30 using NUnit.Framework;
32 using OpenSim.Framework;
33 using OpenSim.Tests.Common;
35 using System.Reflection;
36 using System.Data.Common;
39 using MySql.Data.MySqlClient;
40 using OpenSim.Data.MySQL;
42 using Mono.Data.Sqlite;
43 using OpenSim.Data.SQLite;
45 namespace OpenSim.Data.Tests
47 [TestFixture(Description =
"Inventory store tests (MySQL)")]
52 public class InventoryTests<TConn, TInvStore> : BasicDataServiceTest<TConn, TInvStore>
53 where TConn : DbConnection, new()
58 public UUID zero = UUID.Zero;
60 public UUID folder1 = UUID.Random();
61 public UUID folder2 = UUID.Random();
62 public UUID folder3 = UUID.Random();
63 public UUID owner1 = UUID.Random();
64 public UUID owner2 = UUID.Random();
65 public UUID owner3 = UUID.Random();
67 public UUID item1 = UUID.Random();
68 public UUID item2 = UUID.Random();
69 public UUID item3 = UUID.Random();
70 public UUID asset1 = UUID.Random();
71 public UUID asset2 = UUID.Random();
72 public UUID asset3 = UUID.Random();
75 public string name2 =
"First Level folder";
76 public string name3 =
"First Level folder 2";
77 public string niname1 =
"My Shirt";
78 public string iname1 =
"Shirt";
79 public string iname2 =
"Text Board";
80 public string iname3 =
"No Pants Barrel";
84 name1 =
"Root Folder for " + owner1.ToString();
92 db.Initialise(m_connStr);
95 private void ClearDB()
97 DropTables(
"inventoryitems",
"inventoryfolders");
98 ResetMigrations(
"InventoryStore");
104 TestHelpers.InMethod();
106 Assert.That(db.getInventoryFolder(zero), Is.Null);
107 Assert.That(db.getInventoryFolder(folder1), Is.Null);
108 Assert.That(db.getInventoryFolder(folder2), Is.Null);
109 Assert.That(db.getInventoryFolder(folder3), Is.Null);
111 Assert.That(db.getInventoryItem(zero), Is.Null);
112 Assert.That(db.getInventoryItem(item1), Is.Null);
113 Assert.That(db.getInventoryItem(item2), Is.Null);
114 Assert.That(db.getInventoryItem(item3), Is.Null);
116 Assert.That(db.getUserRootFolder(zero), Is.Null);
117 Assert.That(db.getUserRootFolder(owner1), Is.Null);
124 TestHelpers.InMethod();
128 db.addInventoryFolder(f1);
130 Assert.That(f1a, Is.Null);
136 TestHelpers.InMethod();
147 db.addInventoryFolder(f1);
149 Assert.That(folder1, Is.EqualTo(f1a.ID),
"Assert.That(folder1, Is.EqualTo(f1a.ID))");
150 Assert.That(name1, Is.StringMatching(f1a.Name),
"Assert.That(name1, Text.Matches(f1a.Name))");
161 TestHelpers.InMethod();
164 db.addInventoryFolder(f2);
166 Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1),
"Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1))");
167 Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(2),
"Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(2))");
168 Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0),
"Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0))");
169 Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(0),
"Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(0))");
170 Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0),
"Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0))");
177 TestHelpers.InMethod();
179 int n = db.getFolderHierarchy(zero).Count;
180 Assert.That(n, Is.EqualTo(0),
"Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0))");
181 n = db.getFolderHierarchy(folder1).Count;
182 Assert.That(n, Is.EqualTo(2),
"Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2))");
183 Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0),
"Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0))");
184 Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0),
"Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0))");
185 Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0),
"Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0))");
192 TestHelpers.InMethod();
195 f2.ParentID = folder3;
196 db.moveInventoryFolder(f2);
198 Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1),
"Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1))");
199 Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(1),
"Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(1))");
200 Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0),
"Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0))");
201 Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(1),
"Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(1))");
202 Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0),
"Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0))");
208 TestHelpers.InMethod();
210 Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0),
"Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0))");
211 Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2),
"Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2))");
212 Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0),
"Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0))");
213 Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(1),
"Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(1))");
214 Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0),
"Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0))");
221 TestHelpers.InMethod();
223 Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0),
"Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0))");
224 Assert.That(db.getInventoryInFolder(folder1).Count, Is.EqualTo(0),
"Assert.That(db.getInventoryInFolder(folder1).Count, Is.EqualTo(0))");
225 Assert.That(db.getInventoryInFolder(folder2).Count, Is.EqualTo(0),
"Assert.That(db.getInventoryInFolder(folder2).Count, Is.EqualTo(0))");
226 Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(0),
"Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(0))");
235 TestHelpers.InMethod();
237 db.addInventoryItem(NewItem(item1, folder3, owner1, iname1, asset1));
238 db.addInventoryItem(NewItem(item2, folder3, owner1, iname2, asset2));
239 db.addInventoryItem(NewItem(item3, folder3, owner1, iname3, asset3));
240 Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(3),
"Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(3))");
246 TestHelpers.InMethod();
251 Assert.That(i1.Name, Is.EqualTo(iname1),
"Assert.That(i1.Name, Is.EqualTo(iname1))");
252 Assert.That(i2.Name, Is.EqualTo(iname2),
"Assert.That(i2.Name, Is.EqualTo(iname2))");
253 Assert.That(i3.Name, Is.EqualTo(iname3),
"Assert.That(i3.Name, Is.EqualTo(iname3))");
254 Assert.That(i1.Owner, Is.EqualTo(owner1),
"Assert.That(i1.Owner, Is.EqualTo(owner1))");
255 Assert.That(i2.Owner, Is.EqualTo(owner1),
"Assert.That(i2.Owner, Is.EqualTo(owner1))");
256 Assert.That(i3.Owner, Is.EqualTo(owner1),
"Assert.That(i3.Owner, Is.EqualTo(owner1))");
257 Assert.That(i1.AssetID, Is.EqualTo(asset1),
"Assert.That(i1.AssetID, Is.EqualTo(asset1))");
258 Assert.That(i2.AssetID, Is.EqualTo(asset2),
"Assert.That(i2.AssetID, Is.EqualTo(asset2))");
259 Assert.That(i3.AssetID, Is.EqualTo(asset3),
"Assert.That(i3.AssetID, Is.EqualTo(asset3))");
265 TestHelpers.InMethod();
272 i1.Description = niname1;
274 db.updateInventoryItem(i1);
276 i1 = db.getInventoryItem(item1);
277 Assert.That(i1.Name, Is.EqualTo(niname1),
"Assert.That(i1.Name, Is.EqualTo(niname1))");
278 Assert.That(i1.Description, Is.EqualTo(niname1),
"Assert.That(i1.Description, Is.EqualTo(niname1))");
279 Assert.That(i1.Owner, Is.EqualTo(owner2),
"Assert.That(i1.Owner, Is.EqualTo(owner2))");
285 TestHelpers.InMethod();
287 PropertyScrambler<InventoryFolderBase> folderScrambler =
288 new PropertyScrambler<InventoryFolderBase>()
289 .DontScramble(x => x.Owner)
290 .DontScramble(x => x.ParentID)
291 .DontScramble(x => x.ID);
292 UUID owner = UUID.Random();
293 UUID folder = UUID.Random();
294 UUID rootId = UUID.Random();
295 UUID rootAsset = UUID.Random();
297 folderScrambler.Scramble(f1);
299 db.addInventoryFolder(f1);
301 Assert.That(f1a, Constraints.PropertyCompareConstraint(f1));
303 folderScrambler.Scramble(f1a);
305 db.updateInventoryFolder(f1a);
308 Assert.That(f1b, Constraints.PropertyCompareConstraint(f1a));
311 PropertyScrambler<InventoryItemBase> inventoryScrambler =
312 new PropertyScrambler<InventoryItemBase>()
313 .DontScramble(x => x.ID)
314 .DontScramble(x => x.AssetID)
315 .DontScramble(x => x.Owner)
316 .DontScramble(x => x.Folder);
318 inventoryScrambler.Scramble(root);
319 db.addInventoryItem(root);
322 Assert.That(expected, Constraints.PropertyCompareConstraint(root)
323 .IgnoreProperty(x => x.InvType)
324 .IgnoreProperty(x => x.CreatorIdAsUuid)
325 .IgnoreProperty(x => x.Description)
326 .IgnoreProperty(x => x.CreatorIdentification)
327 .IgnoreProperty(x => x.CreatorData));
329 inventoryScrambler.Scramble(expected);
330 db.updateInventoryItem(expected);
333 Assert.That(actual, Constraints.PropertyCompareConstraint(expected)
334 .IgnoreProperty(x => x.InvType)
335 .IgnoreProperty(x => x.CreatorIdAsUuid)
336 .IgnoreProperty(x => x.Description)
337 .IgnoreProperty(x => x.CreatorIdentification)
338 .IgnoreProperty(x => x.CreatorData));
344 TestHelpers.InMethod();
347 Assert.That(db.getInventoryFolder(zero), Is.Null);
348 Assert.That(db.getInventoryItem(zero), Is.Null);
349 Assert.That(db.getUserRootFolder(zero), Is.Null);
350 Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0),
"Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0))");
353 private InventoryItemBase NewItem(UUID
id, UUID parent, UUID owner,
string name, UUID asset)
359 i.CreatorId = owner.ToString();
361 i.Description = name;
void T010_FolderNonParent()
InventoryTests(string conn)
Inventory Item - contains all the properties associated with an individual inventory piece...
void T013_FolderHierarchy()
void T015_FolderHierarchy()
void T104_RandomUpdateItem()
override void InitService(object service)
To be overridden in derived classes. Do whatever init with the m_service, like setting the conn strin...
An interface for accessing inventory data from a storage server