UserInventoryTests.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using System.Text;
  31. using System.Threading;
  32. using System.Timers;
  33. using Timer=System.Timers.Timer;
  34. using Nini.Config;
  35. using NUnit.Framework;
  36. using OpenMetaverse;
  37. using OpenMetaverse.Assets;
  38. using OpenSim.Framework;
  39. using OpenSim.Region.Framework.Scenes;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
  42. using OpenSim.Region.CoreModules.World.Serialiser;
  43. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  44. using OpenSim.Services.Interfaces;
  45. using OpenSim.Tests.Common;
  46. namespace OpenSim.Region.Framework.Tests
  47. {
  48. [TestFixture]
  49. public class UserInventoryTests : OpenSimTestCase
  50. {
  51. [Test]
  52. public void TestCreateInventoryFolders()
  53. {
  54. TestHelpers.InMethod();
  55. // TestHelpers.EnableLogging();
  56. // For this test both folders will have the same name which is legal in SL user inventories.
  57. string foldersName = "f1";
  58. Scene scene = new SceneHelpers().SetupScene();
  59. UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
  60. UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, foldersName, false);
  61. List<InventoryFolderBase> oneFolder
  62. = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, foldersName);
  63. Assert.That(oneFolder.Count, Is.EqualTo(1));
  64. InventoryFolderBase firstRetrievedFolder = oneFolder[0];
  65. Assert.That(firstRetrievedFolder.Name, Is.EqualTo(foldersName));
  66. UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, foldersName, false);
  67. List<InventoryFolderBase> twoFolders
  68. = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, foldersName);
  69. Assert.That(twoFolders.Count, Is.EqualTo(2));
  70. Assert.That(twoFolders[0].Name, Is.EqualTo(foldersName));
  71. Assert.That(twoFolders[1].Name, Is.EqualTo(foldersName));
  72. Assert.That(twoFolders[0].ID, Is.Not.EqualTo(twoFolders[1].ID));
  73. }
  74. [Test]
  75. public void TestGiveInventoryItem()
  76. {
  77. TestHelpers.InMethod();
  78. // log4net.Config.XmlConfigurator.Configure();
  79. Scene scene = new SceneHelpers().SetupScene();
  80. UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
  81. UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002));
  82. InventoryItemBase item1 = UserInventoryHelpers.CreateInventoryItem(scene, "item1", user1.PrincipalID);
  83. string message;
  84. scene.GiveInventoryItem(user2.PrincipalID, user1.PrincipalID, item1.ID, out message);
  85. InventoryItemBase retrievedItem1
  86. = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, user2.PrincipalID, "Notecards/item1");
  87. Assert.That(retrievedItem1, Is.Not.Null);
  88. // Try giving back the freshly received item
  89. scene.GiveInventoryItem(user1.PrincipalID, user2.PrincipalID, retrievedItem1.ID, out message);
  90. List<InventoryItemBase> reretrievedItems
  91. = UserInventoryHelpers.GetInventoryItems(scene.InventoryService, user1.PrincipalID, "Notecards/item1");
  92. Assert.That(reretrievedItems.Count, Is.EqualTo(2));
  93. }
  94. [Test]
  95. public void TestGiveInventoryFolder()
  96. {
  97. TestHelpers.InMethod();
  98. // TestHelpers.EnableLogging();
  99. Scene scene = new SceneHelpers().SetupScene();
  100. UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
  101. UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002));
  102. InventoryFolderBase folder1
  103. = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, "folder1", false);
  104. scene.GiveInventoryFolder(null, user2.PrincipalID, user1.PrincipalID, folder1.ID, UUID.Zero);
  105. InventoryFolderBase retrievedFolder1
  106. = UserInventoryHelpers.GetInventoryFolder(scene.InventoryService, user2.PrincipalID, "folder1");
  107. Assert.That(retrievedFolder1, Is.Not.Null);
  108. // Try giving back the freshly received folder
  109. scene.GiveInventoryFolder(null, user1.PrincipalID, user2.PrincipalID, retrievedFolder1.ID, UUID.Zero);
  110. List<InventoryFolderBase> reretrievedFolders
  111. = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, "folder1");
  112. Assert.That(reretrievedFolders.Count, Is.EqualTo(2));
  113. }
  114. }
  115. }