OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
UserInventoryTests.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using System.Text;
32 using System.Threading;
33 using System.Timers;
35 using Nini.Config;
36 using NUnit.Framework;
37 using OpenMetaverse;
38 using OpenMetaverse.Assets;
39 using OpenSim.Framework;
40 using OpenSim.Region.Framework.Scenes;
41 using OpenSim.Region.Framework.Interfaces;
42 using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
43 using OpenSim.Region.CoreModules.World.Serialiser;
44 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
45 using OpenSim.Services.Interfaces;
46 using OpenSim.Tests.Common;
47 
48 namespace OpenSim.Region.Framework.Tests
49 {
50  [TestFixture]
52  {
53  [Test]
55  {
56  TestHelpers.InMethod();
57 // TestHelpers.EnableLogging();
58 
59  // For this test both folders will have the same name which is legal in SL user inventories.
60  string foldersName = "f1";
61 
62  Scene scene = new SceneHelpers().SetupScene();
63  UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
64 
65  UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, foldersName, false);
66 
67  List<InventoryFolderBase> oneFolder
68  = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, foldersName);
69 
70  Assert.That(oneFolder.Count, Is.EqualTo(1));
71  InventoryFolderBase firstRetrievedFolder = oneFolder[0];
72  Assert.That(firstRetrievedFolder.Name, Is.EqualTo(foldersName));
73 
74  UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, foldersName, false);
75 
76  List<InventoryFolderBase> twoFolders
77  = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, foldersName);
78 
79  Assert.That(twoFolders.Count, Is.EqualTo(2));
80  Assert.That(twoFolders[0].Name, Is.EqualTo(foldersName));
81  Assert.That(twoFolders[1].Name, Is.EqualTo(foldersName));
82  Assert.That(twoFolders[0].ID, Is.Not.EqualTo(twoFolders[1].ID));
83  }
84 
85  [Test]
86  public void TestGiveInventoryItem()
87  {
88  TestHelpers.InMethod();
89 // log4net.Config.XmlConfigurator.Configure();
90 
91  Scene scene = new SceneHelpers().SetupScene();
92  UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
93  UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002));
94  InventoryItemBase item1 = UserInventoryHelpers.CreateInventoryItem(scene, "item1", user1.PrincipalID);
95 
96  string message;
97 
98  scene.GiveInventoryItem(user2.PrincipalID, user1.PrincipalID, item1.ID, out message);
99 
100  InventoryItemBase retrievedItem1
101  = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, user2.PrincipalID, "Notecards/item1");
102 
103  Assert.That(retrievedItem1, Is.Not.Null);
104 
105  // Try giving back the freshly received item
106  scene.GiveInventoryItem(user1.PrincipalID, user2.PrincipalID, retrievedItem1.ID, out message);
107 
108  List<InventoryItemBase> reretrievedItems
109  = UserInventoryHelpers.GetInventoryItems(scene.InventoryService, user1.PrincipalID, "Notecards/item1");
110 
111  Assert.That(reretrievedItems.Count, Is.EqualTo(2));
112  }
113 
114  [Test]
116  {
117  TestHelpers.InMethod();
118 // TestHelpers.EnableLogging();
119 
120  Scene scene = new SceneHelpers().SetupScene();
121  UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
122  UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002));
123  InventoryFolderBase folder1
124  = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, "folder1", false);
125 
126  scene.GiveInventoryFolder(null, user2.PrincipalID, user1.PrincipalID, folder1.ID, UUID.Zero);
127 
128  InventoryFolderBase retrievedFolder1
129  = UserInventoryHelpers.GetInventoryFolder(scene.InventoryService, user2.PrincipalID, "folder1");
130 
131  Assert.That(retrievedFolder1, Is.Not.Null);
132 
133  // Try giving back the freshly received folder
134  scene.GiveInventoryFolder(null, user1.PrincipalID, user2.PrincipalID, retrievedFolder1.ID, UUID.Zero);
135 
136  List<InventoryFolderBase> reretrievedFolders
137  = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, "folder1");
138 
139  Assert.That(reretrievedFolders.Count, Is.EqualTo(2));
140  }
141  }
142 }
System.Timers.Timer Timer
Inventory Item - contains all the properties associated with an individual inventory piece...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
System.Timers.Timer Timer