29 using System.Collections.Generic;
31 using NUnit.Framework;
32 using NUnit.Framework.Constraints;
34 using OpenSim.Framework;
35 using OpenSim.Tests.Common;
36 using System.Data.Common;
40 using MySql.Data.MySqlClient;
41 using OpenSim.Data.MySQL;
43 using Mono.Data.Sqlite;
44 using OpenSim.Data.SQLite;
48 [TestFixture(Description =
"Asset store tests (SQLite)")]
53 [TestFixture(Description =
"Asset store tests (MySQL)")]
58 public class AssetTests<TConn, TAssetData> : BasicDataServiceTest<TConn, TAssetData>
59 where TConn : DbConnection, new()
64 public UUID uuid1 = UUID.Random();
65 public UUID uuid2 = UUID.Random();
66 public UUID uuid3 = UUID.Random();
68 public string critter1 = UUID.Random().ToString();
69 public string critter2 = UUID.Random().ToString();
70 public string critter3 = UUID.Random().ToString();
72 public byte[] data1 =
new byte[100];
74 PropertyScrambler<AssetBase> scrambler =
new PropertyScrambler<AssetBase>()
75 .DontScramble(x => x.ID)
76 .DontScramble(x => x.Type)
77 .DontScramble(x => x.FullID)
78 .DontScramble(x => x.Metadata.ID)
79 .DontScramble(x => x.Metadata.CreatorID)
80 .DontScramble(x => x.Metadata.ContentType)
81 .DontScramble(x => x.Metadata.FullID)
82 .DontScramble(x => x.Data);
87 m_db = (TAssetData)service;
88 m_db.Initialise(m_connStr);
91 private void ClearDB()
94 ResetMigrations(
"AssetStore");
101 TestHelpers.InMethod();
103 bool[] exist = m_db.AssetsExist(
new[] { uuid1, uuid2, uuid3 });
104 Assert.IsFalse(exist[0]);
105 Assert.IsFalse(exist[1]);
106 Assert.IsFalse(exist[2]);
112 TestHelpers.InMethod();
114 AssetBase a1 =
new AssetBase(uuid1,
"asset one", (sbyte)AssetType.Texture, critter1.ToString());
115 AssetBase a2 =
new AssetBase(uuid2,
"asset two", (sbyte)AssetType.Texture, critter2.ToString());
116 AssetBase a3 =
new AssetBase(uuid3,
"asset three", (sbyte)AssetType.Texture, critter3.ToString());
121 scrambler.Scramble(a1);
122 scrambler.Scramble(a2);
123 scrambler.Scramble(a3);
128 a1.UploadAttempts = 0;
129 a2.UploadAttempts = 0;
130 a3.UploadAttempts = 0;
133 a1a.UploadAttempts = 0;
134 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
137 a2a.UploadAttempts = 0;
138 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
141 a3a.UploadAttempts = 0;
142 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
144 scrambler.Scramble(a1a);
145 scrambler.Scramble(a2a);
146 scrambler.Scramble(a3a);
148 m_db.StoreAsset(a1a);
149 m_db.StoreAsset(a2a);
150 m_db.StoreAsset(a3a);
151 a1a.UploadAttempts = 0;
152 a2a.UploadAttempts = 0;
153 a3a.UploadAttempts = 0;
156 a1b.UploadAttempts = 0;
157 Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a));
160 a2b.UploadAttempts = 0;
161 Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a));
164 a3b.UploadAttempts = 0;
165 Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a));
167 bool[] exist = m_db.AssetsExist(
new[] { uuid1, uuid2, uuid3 });
168 Assert.IsTrue(exist[0]);
169 Assert.IsTrue(exist[1]);
170 Assert.IsTrue(exist[2]);
172 List<AssetMetadata> metadatas = m_db.FetchAssetMetadataSet(0, 1000);
174 Assert.That(metadatas.Count >= 3,
"FetchAssetMetadataSet() should have returned at least 3 assets!");
178 if (metadatas.Count < 1000)
180 AssetMetadata metadata = metadatas.Find(x => x.FullID == uuid1);
181 Assert.That(metadata.Name, Is.EqualTo(a1b.Name));
182 Assert.That(metadata.Description, Is.EqualTo(a1b.Description));
183 Assert.That(metadata.Type, Is.EqualTo(a1b.Type));
184 Assert.That(metadata.Temporary, Is.EqualTo(a1b.Temporary));
185 Assert.That(metadata.FullID, Is.EqualTo(a1b.FullID));
192 TestHelpers.InMethod();
198 AssetBase a2 =
new AssetBase(uuid2,
"asset two", (sbyte)AssetType.Texture,
"This is not a GUID!");
205 a1.UploadAttempts = 0;
207 a2.UploadAttempts = 0;
209 a3.UploadAttempts = 0;
212 a1a.UploadAttempts = 0;
213 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
216 a2a.UploadAttempts = 0;
217 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
220 a3a.UploadAttempts = 0;
221 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
void T020_CheckForWeirdCreatorID()
void T010_StoreReadVerifyAssets()
Asset class. All Assets are reference by this class or a class derived from this class ...
Interactive OpenSim region server
override void InitService(object service)
To be overridden in derived classes. Do whatever init with the m_service, like setting the conn strin...