* Simplify test code by always setting up mock 'in memory' user and inventory data plugins for every TestCommunicationsManager

* imo the gain in simplcity of test code outweighs the very small cost of setting up some stuff that some tests will never use
0.6.2-post-fixes
Justin Clarke Casey 2009-01-05 18:00:53 +00:00
parent 04ffcce7ea
commit 0b07c9762b
5 changed files with 42 additions and 57 deletions

View File

@ -52,7 +52,7 @@ namespace OpenSim.Framework.Communications.Tests
UUID nonExistingUserId = UUID.Parse("00000000-0000-0000-0000-000000000001"); UUID nonExistingUserId = UUID.Parse("00000000-0000-0000-0000-000000000001");
UUID existingUserId = UUID.Parse("00000000-0000-0000-0000-000000000002"); UUID existingUserId = UUID.Parse("00000000-0000-0000-0000-000000000002");
CommunicationsManager commsManager = UserProfileTestUtils.SetupServices(); TestCommunicationsManager commsManager = new TestCommunicationsManager();
CachedUserInfo existingUserInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager, existingUserId); CachedUserInfo existingUserInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager, existingUserId);
Assert.That(existingUserInfo, Is.Not.Null, "Existing user info unexpectedly not found"); Assert.That(existingUserInfo, Is.Not.Null, "Existing user info unexpectedly not found");
@ -68,7 +68,7 @@ namespace OpenSim.Framework.Communications.Tests
[Test] [Test]
public void TestRequestInventoryForUser() public void TestRequestInventoryForUser()
{ {
CommunicationsManager commsManager = UserProfileTestUtils.SetupServices(); TestCommunicationsManager commsManager = new TestCommunicationsManager();
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager); CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);
Assert.That(userInfo.HasReceivedInventory, Is.True); Assert.That(userInfo.HasReceivedInventory, Is.True);
@ -80,7 +80,7 @@ namespace OpenSim.Framework.Communications.Tests
[Test] [Test]
public void TestGetChildFolder() public void TestGetChildFolder()
{ {
CommunicationsManager commsManager = UserProfileTestUtils.SetupServices(); TestCommunicationsManager commsManager = new TestCommunicationsManager();
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager); CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);
UUID folderId = UUID.Parse("00000000-0000-0000-0000-000000000011"); UUID folderId = UUID.Parse("00000000-0000-0000-0000-000000000011");
@ -96,12 +96,12 @@ namespace OpenSim.Framework.Communications.Tests
/// </summary> /// </summary>
[Test] [Test]
public void TestCreateFolder() public void TestCreateFolder()
{ {
IUserDataPlugin userDataPlugin = new TestUserDataPlugin(); TestCommunicationsManager commsManager = new TestCommunicationsManager();
IInventoryDataPlugin inventoryDataPlugin = new TestInventoryDataPlugin();
IUserDataPlugin userDataPlugin = commsManager.UserDataPlugin;
IInventoryDataPlugin inventoryDataPlugin = commsManager.InventoryDataPlugin;
CommunicationsManager commsManager
= UserProfileTestUtils.SetupServices(userDataPlugin, inventoryDataPlugin);
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager); CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);
UUID folderId = UUID.Parse("00000000-0000-0000-0000-000000000010"); UUID folderId = UUID.Parse("00000000-0000-0000-0000-000000000010");
@ -129,11 +129,11 @@ namespace OpenSim.Framework.Communications.Tests
[Test] [Test]
public void TestUpdateFolder() public void TestUpdateFolder()
{ {
IUserDataPlugin userDataPlugin = new TestUserDataPlugin(); TestCommunicationsManager commsManager = new TestCommunicationsManager();
IInventoryDataPlugin inventoryDataPlugin = new TestInventoryDataPlugin();
IUserDataPlugin userDataPlugin = commsManager.UserDataPlugin;
IInventoryDataPlugin inventoryDataPlugin = commsManager.InventoryDataPlugin;
CommunicationsManager commsManager
= UserProfileTestUtils.SetupServices(userDataPlugin, inventoryDataPlugin);
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager); CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);
UUID folder1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); UUID folder1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
@ -188,11 +188,11 @@ namespace OpenSim.Framework.Communications.Tests
[Test] [Test]
public void TestMoveFolder() public void TestMoveFolder()
{ {
IUserDataPlugin userDataPlugin = new TestUserDataPlugin(); TestCommunicationsManager commsManager = new TestCommunicationsManager();
IInventoryDataPlugin inventoryDataPlugin = new TestInventoryDataPlugin();
IUserDataPlugin userDataPlugin = commsManager.UserDataPlugin;
IInventoryDataPlugin inventoryDataPlugin = commsManager.InventoryDataPlugin;
CommunicationsManager commsManager
= UserProfileTestUtils.SetupServices(userDataPlugin, inventoryDataPlugin);
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager); CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);
UUID folder1Id = UUID.Parse("00000000-0000-0000-0000-000000000020"); UUID folder1Id = UUID.Parse("00000000-0000-0000-0000-000000000020");
@ -226,11 +226,11 @@ namespace OpenSim.Framework.Communications.Tests
{ {
//log4net.Config.XmlConfigurator.Configure(); //log4net.Config.XmlConfigurator.Configure();
IUserDataPlugin userDataPlugin = new TestUserDataPlugin(); TestCommunicationsManager commsManager = new TestCommunicationsManager();
IInventoryDataPlugin inventoryDataPlugin = new TestInventoryDataPlugin();
IUserDataPlugin userDataPlugin = commsManager.UserDataPlugin;
IInventoryDataPlugin inventoryDataPlugin = commsManager.InventoryDataPlugin;
CommunicationsManager commsManager
= UserProfileTestUtils.SetupServices(userDataPlugin, inventoryDataPlugin);
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager); CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);
UUID folder1Id = UUID.Parse("00000000-0000-0000-0000-000000000070"); UUID folder1Id = UUID.Parse("00000000-0000-0000-0000-000000000070");

View File

@ -37,33 +37,7 @@ namespace OpenSim.Framework.Communications.Tests
/// Utility functions for carrying out user profile relate tests. /// Utility functions for carrying out user profile relate tests.
/// </summary> /// </summary>
public class UserProfileTestUtils public class UserProfileTestUtils
{ {
/// <summary>
/// Set up standard services required for user tests.
/// </summary>
/// <returns>CommunicationsManager used to access these services</returns>
public static CommunicationsManager SetupServices()
{
return SetupServices(new TestUserDataPlugin(), new TestInventoryDataPlugin());
}
/// <summary>
/// Set up standard services required for user tests.
/// </summary>
/// <param name="userDataPlugin"></param>
/// <param name="inventoryDataPlugin"></param>
/// <returns>CommunicationsManager used to access these services</returns>
public static CommunicationsManager SetupServices(
IUserDataPlugin userDataPlugin, IInventoryDataPlugin inventoryDataPlugin)
{
CommunicationsManager commsManager = new TestCommunicationsManager();
((LocalUserServices)commsManager.UserService).AddPlugin(userDataPlugin);
((LocalInventoryService)commsManager.InventoryService).AddPlugin(inventoryDataPlugin);
return commsManager;
}
/// <summary> /// <summary>
/// Create a test user with a standard inventory /// Create a test user with a standard inventory
/// </summary> /// </summary>

View File

@ -50,7 +50,7 @@ namespace OpenSim.Framework.Communications.Tests
[Test] [Test]
public void TestNormalLoginResponse() public void TestNormalLoginResponse()
{ {
log4net.Config.XmlConfigurator.Configure(); //log4net.Config.XmlConfigurator.Configure();
string firstName = "Timmy"; string firstName = "Timmy";
string lastName = "Mallet"; string lastName = "Mallet";
@ -58,9 +58,6 @@ namespace OpenSim.Framework.Communications.Tests
CommunicationsManager commsManager CommunicationsManager commsManager
= new TestCommunicationsManager(new OpenSim.Framework.NetworkServersInfo(42, 43)); = new TestCommunicationsManager(new OpenSim.Framework.NetworkServersInfo(42, 43));
((LocalUserServices)commsManager.UserService).AddPlugin(new TestUserDataPlugin());
((LocalInventoryService)commsManager.InventoryService).AddPlugin(new TestInventoryDataPlugin());
commsManager.GridService.RegisterRegion( commsManager.GridService.RegisterRegion(
new RegionInfo(42, 43, new IPEndPoint(IPAddress.Loopback, 9000), "localhost")); new RegionInfo(42, 43, new IPEndPoint(IPAddress.Loopback, 9000), "localhost"));
commsManager.GridService.RegionLoginsEnabled = true; commsManager.GridService.RegionLoginsEnabled = true;

View File

@ -313,9 +313,6 @@ namespace OpenSim.Region.Environment.Scenes.Tests
TestScene scene = SceneTestUtils.SetupScene(); TestScene scene = SceneTestUtils.SetupScene();
SceneObjectPart part = SceneTestUtils.AddSceneObject(scene, myObjectName); SceneObjectPart part = SceneTestUtils.AddSceneObject(scene, myObjectName);
((LocalUserServices)scene.CommsManager.UserService).AddPlugin(new TestUserDataPlugin());
((LocalInventoryService)scene.CommsManager.InventoryService).AddPlugin(new TestInventoryDataPlugin());
Assert.That( Assert.That(
scene.CommsManager.UserAdminService.AddUser( scene.CommsManager.UserAdminService.AddUser(
"Bob", "Hoskins", "test", "test@test.com", 1000, 1000, agentId), "Bob", "Hoskins", "test", "test@test.com", 1000, 1000, agentId),

View File

@ -35,6 +35,18 @@ namespace OpenSim.Tests.Common.Mock
{ {
public class TestCommunicationsManager : CommunicationsManager public class TestCommunicationsManager : CommunicationsManager
{ {
public IUserDataPlugin UserDataPlugin
{
get { return m_userDataPlugin; }
}
private IUserDataPlugin m_userDataPlugin;
public IInventoryDataPlugin InventoryDataPlugin
{
get { return m_inventoryDataPlugin; }
}
private IInventoryDataPlugin m_inventoryDataPlugin;
public TestCommunicationsManager() public TestCommunicationsManager()
: this(null) : this(null)
{ {
@ -43,16 +55,21 @@ namespace OpenSim.Tests.Common.Mock
public TestCommunicationsManager(NetworkServersInfo serversInfo) public TestCommunicationsManager(NetworkServersInfo serversInfo)
: base(serversInfo, null, null, false, null) : base(serversInfo, null, null, false, null)
{ {
m_userDataPlugin = new TestUserDataPlugin();
m_inventoryDataPlugin = new TestInventoryDataPlugin();
LocalInventoryService lis = new LocalInventoryService(); LocalInventoryService lis = new LocalInventoryService();
lis.AddPlugin(m_inventoryDataPlugin);
m_interServiceInventoryService = lis; m_interServiceInventoryService = lis;
AddInventoryService(lis); AddInventoryService(lis);
LocalUserServices lus = new LocalUserServices(991, 992, lis); LocalUserServices lus = new LocalUserServices(991, 992, lis);
lus.AddPlugin(m_userDataPlugin);
m_userService = lus; m_userService = lus;
m_userAdminService = lus; m_userAdminService = lus;
LocalBackEndServices gs = new LocalBackEndServices(); LocalBackEndServices gs = new LocalBackEndServices();
m_gridService = gs; m_gridService = gs;
} }
} }
} }