public async Task DBFiles_Provider_01_ByReference() { ByReference Obj = new ByReference() { Default = DBFilesBTreeTests.CreateDefault(100), Simple = DBFilesBTreeTests.CreateSimple(100) }; await this.provider.Insert(Obj); ObjectBTreeFile File = await this.provider.GetFile("Default"); await DBFilesBTreeTests.AssertConsistent(File, this.provider, 3, Obj, true); Console.Out.WriteLine(await DBFilesBTreeTests.ExportXML(File, "Data\\BTree.xml")); Assert.AreNotEqual(Guid.Empty, Obj.ObjectId); Assert.AreNotEqual(Guid.Empty, Obj.Default.ObjectId); Assert.AreNotEqual(Guid.Empty, Obj.Simple.ObjectId); ByReference Obj2 = await this.provider.LoadObject <ByReference>(Obj.ObjectId); DBFilesObjectSerializationTests.AssertEqual(Obj2.Default, Obj.Default); DBFilesObjectSerializationTests.AssertEqual(Obj2.Simple, Obj.Simple); }
private async Task Test_Add(int MaxLen) { byte[] ByteArray = this.GetBytes(MaxLen, 0); Simple Obj = DBFilesBTreeTests.CreateSimple(MaxLen); await this.file.AddAsync("Key1", "Value1"); await this.file.AddAsync("Key2", "Value2"); await this.file.AddAsync("Key3", "Value3"); await this.file.AddAsync("Key4", null); await this.file.AddAsync("Key5", Obj); await this.file.AddAsync("Key6", ByteArray); Assert.IsTrue(await this.file.ContainsKeyAsync("Key1")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key2")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key3")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key4")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key5")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key6")); AssertEx.Same(this.file["Key1"], "Value1"); AssertEx.Same(this.file["Key2"], "Value2"); AssertEx.Same(this.file["Key3"], "Value3"); Assert.IsNull(this.file["Key4"]); DBFilesObjectSerializationTests.AssertEqual(this.file["Key5"] as Simple, Obj); AssertEx.Same(this.file["Key6"], ByteArray); }
public async Task TestInitialize() { DBFilesBTreeTests.DeleteFiles(); this.provider = new FilesProvider("Data", DBFilesBTreeTests.CollectionName, 8192, BlocksInCache, 8192, Encoding.UTF8, 10000, true); this.file = await this.provider.GetFile("Default"); }
public async Task DBFiles_StringDictionary_02_Add() { byte[] ByteArray = new byte[] { 1, 2, 3, 4, 5 }; Simple Obj = DBFilesBTreeTests.CreateSimple(100); await this.file.AddAsync("Key1", "Value1"); await this.file.AddAsync("Key2", "Value2"); await this.file.AddAsync("Key3", "Value3"); await this.file.AddAsync("Key4", null); await this.file.AddAsync("Key5", Obj); await this.file.AddAsync("Key6", ByteArray); Assert.IsTrue(await this.file.ContainsKeyAsync("Key1")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key2")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key3")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key4")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key5")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key6")); AssertEx.Same(this.file["Key1"], "Value1"); AssertEx.Same(this.file["Key2"], "Value2"); AssertEx.Same(this.file["Key3"], "Value3"); Assert.IsNull(this.file["Key4"]); DBFilesObjectSerializationTests.AssertEqual(this.file["Key5"] as Simple, Obj); AssertEx.Same(this.file["Key6"], ByteArray); }
public async Task DBFiles_RetryLastTest_01_Retry_SaveNew() { FileStatistics StatBefore = (await this.file.ComputeStatistics()).Key; Simple Obj = this.LoadSimple(); Guid ObjectId = await this.file.SaveNewObject(Obj); Assert.AreNotEqual(Guid.Empty, ObjectId); await DBFilesBTreeTests.AssertConsistent(this.file, this.provider, (int)(StatBefore.NrObjects + 1), null, true); }
public async Task TestInitialize() { DBFilesBTreeTests.DeleteFiles(); #if LW this.provider = await FilesProvider.CreateAsync("Data", DBFilesBTreeTests.CollectionName, 8192, BlocksInCache, 8192, Encoding.UTF8, 10000); #else this.provider = await FilesProvider.CreateAsync("Data", DBFilesBTreeTests.CollectionName, 8192, BlocksInCache, 8192, Encoding.UTF8, 10000, true); #endif this.file = await this.provider.GetFile("Default"); }
public static async Task ClassInitialize(TestContext Context) { DBFilesBTreeTests.DeleteFiles(); #if LW provider = await FilesProvider.CreateAsync("Data", "Default", BlockSize, BlocksInCache, Math.Max(BlockSize / 2, 1024), Encoding.UTF8, 10000); #else provider = await FilesProvider.CreateAsync("Data", "Default", BlockSize, BlocksInCache, Math.Max(BlockSize / 2, 1024), Encoding.UTF8, 10000, true); #endif file = await provider.GetFile("Default"); }
public async Task TestInitialize() { if (!File.Exists(DBFilesBTreeTests.MasterFileName + ".bak") || !File.Exists(DBFilesBTreeTests.DefaultFileName + ".bak") || !File.Exists(DBFilesBTreeTests.DefaultBlobFileName + ".bak") || !File.Exists(DBFilesBTreeTests.DefaultLabelsFileName + ".bak")) { Assert.Inconclusive("No backup files to test against."); } if (File.Exists(DBFilesBTreeTests.MasterFileName)) { File.Delete(DBFilesBTreeTests.MasterFileName); } if (File.Exists(DBFilesBTreeTests.DefaultFileName)) { File.Delete(DBFilesBTreeTests.DefaultFileName); } if (File.Exists(DBFilesBTreeTests.DefaultBlobFileName)) { File.Delete(DBFilesBTreeTests.DefaultBlobFileName); } if (File.Exists(DBFilesBTreeTests.DefaultLabelsFileName)) { File.Delete(DBFilesBTreeTests.DefaultLabelsFileName); } File.Copy(DBFilesBTreeTests.MasterFileName + ".bak", DBFilesBTreeTests.MasterFileName); File.Copy(DBFilesBTreeTests.DefaultFileName + ".bak", DBFilesBTreeTests.DefaultFileName); File.Copy(DBFilesBTreeTests.DefaultBlobFileName + ".bak", DBFilesBTreeTests.DefaultBlobFileName); File.Copy(DBFilesBTreeTests.DefaultLabelsFileName + ".bak", DBFilesBTreeTests.DefaultLabelsFileName); int BlockSize = this.LoadBlockSize(); #if LW this.provider = await FilesProvider.CreateAsync(DBFilesBTreeTests.Folder, DBFilesBTreeTests.CollectionName, BlockSize, 10000, Math.Max(BlockSize / 2, 1024), Encoding.UTF8, 10000); #else this.provider = await FilesProvider.CreateAsync(DBFilesBTreeTests.Folder, DBFilesBTreeTests.CollectionName, BlockSize, 10000, Math.Max(BlockSize / 2, 1024), Encoding.UTF8, 10000, true); #endif this.file = await this.provider.GetFile(DBFilesBTreeTests.CollectionName); this.start = DateTime.Now; await DBFilesBTreeTests.ExportXML(this.file, "Data\\BTreeBefore.xml"); }
private async Task Test_CopyTo(int MaxLen) { byte[] ByteArray = this.GetBytes(MaxLen, 0); Simple Obj = DBFilesBTreeTests.CreateSimple(MaxLen); this.file["Key1"] = "Value1"; this.file["Key2"] = "Value2"; this.file["Key3"] = "Value3"; this.file["Key4"] = null; this.file["Key5"] = Obj; this.file["Key6"] = ByteArray; Assert.IsTrue(await this.file.ContainsKeyAsync("Key1")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key2")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key3")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key4")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key5")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key6")); AssertEx.Same(this.file["Key1"], "Value1"); AssertEx.Same(this.file["Key2"], "Value2"); AssertEx.Same(this.file["Key3"], "Value3"); Assert.IsNull(this.file["Key4"]); DBFilesObjectSerializationTests.AssertEqual(this.file["Key5"] as Simple, Obj); AssertEx.Same(this.file["Key6"], ByteArray); int c = this.file.Count; AssertEx.Same(6, c); KeyValuePair <string, object>[] A = new KeyValuePair <string, object> [c]; this.file.CopyTo(A, 0); AssertEx.Same(A[0].Key, "Key1"); AssertEx.Same(A[1].Key, "Key2"); AssertEx.Same(A[2].Key, "Key3"); AssertEx.Same(A[3].Key, "Key4"); AssertEx.Same(A[4].Key, "Key5"); AssertEx.Same(A[5].Key, "Key6"); AssertEx.Same(A[0].Value, "Value1"); AssertEx.Same(A[1].Value, "Value2"); AssertEx.Same(A[2].Value, "Value3"); Assert.IsNull(A[3].Value); DBFilesObjectSerializationTests.AssertEqual(A[4].Value as Simple, Obj); AssertEx.Same(A[5].Value, ByteArray); }
private async Task Test_Reset(int MaxLen) { byte[] ByteArray1 = this.GetBytes(MaxLen, 0); byte[] ByteArray2 = this.GetBytes(MaxLen, MaxLen); Simple Obj1 = DBFilesBTreeTests.CreateSimple(MaxLen); Simple Obj2 = DBFilesBTreeTests.CreateSimple(MaxLen); this.file["Key1"] = "Value1_1"; this.file["Key2"] = "Value2_1"; this.file["Key3"] = "Value3_1"; this.file["Key4"] = null; this.file["Key5"] = Obj1; this.file["Key6"] = ByteArray1; Assert.IsTrue(await this.file.ContainsKeyAsync("Key1")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key2")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key3")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key4")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key5")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key6")); AssertEx.Same(this.file["Key1"], "Value1_1"); AssertEx.Same(this.file["Key2"], "Value2_1"); AssertEx.Same(this.file["Key3"], "Value3_1"); Assert.IsNull(this.file["Key4"]); DBFilesObjectSerializationTests.AssertEqual(this.file["Key5"] as Simple, Obj1); AssertEx.Same(this.file["Key6"], ByteArray1); this.file["Key1"] = "Value1_2"; this.file["Key2"] = "Value2_2"; this.file["Key3"] = "Value3_2"; this.file["Key4"] = null; this.file["Key5"] = Obj2; this.file["Key6"] = ByteArray2; Assert.IsTrue(await this.file.ContainsKeyAsync("Key1")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key2")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key3")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key4")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key5")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key6")); AssertEx.Same(this.file["Key1"], "Value1_2"); AssertEx.Same(this.file["Key2"], "Value2_2"); AssertEx.Same(this.file["Key3"], "Value3_2"); Assert.IsNull(this.file["Key4"]); DBFilesObjectSerializationTests.AssertEqual(this.file["Key5"] as Simple, Obj2); AssertEx.Same(this.file["Key6"], ByteArray2); }
public async Task DBFiles_StringDictionary_03_Reset() { byte[] ByteArray1 = new byte[] { 1, 2, 3, 4, 5 }; byte[] ByteArray2 = new byte[] { 6, 7, 8, 9, 0 }; Simple Obj1 = DBFilesBTreeTests.CreateSimple(100); Simple Obj2 = DBFilesBTreeTests.CreateSimple(100); this.file["Key1"] = "Value1_1"; this.file["Key2"] = "Value2_1"; this.file["Key3"] = "Value3_1"; this.file["Key4"] = null; this.file["Key5"] = Obj1; this.file["Key6"] = ByteArray1; Assert.IsTrue(await this.file.ContainsKeyAsync("Key1")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key2")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key3")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key4")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key5")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key6")); AssertEx.Same(this.file["Key1"], "Value1_1"); AssertEx.Same(this.file["Key2"], "Value2_1"); AssertEx.Same(this.file["Key3"], "Value3_1"); Assert.IsNull(this.file["Key4"]); DBFilesObjectSerializationTests.AssertEqual(this.file["Key5"] as Simple, Obj1); AssertEx.Same(this.file["Key6"], ByteArray1); this.file["Key1"] = "Value1_2"; this.file["Key2"] = "Value2_2"; this.file["Key3"] = "Value3_2"; this.file["Key4"] = null; this.file["Key5"] = Obj2; this.file["Key6"] = ByteArray2; Assert.IsTrue(await this.file.ContainsKeyAsync("Key1")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key2")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key3")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key4")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key5")); Assert.IsTrue(await this.file.ContainsKeyAsync("Key6")); AssertEx.Same(this.file["Key1"], "Value1_2"); AssertEx.Same(this.file["Key2"], "Value2_2"); AssertEx.Same(this.file["Key3"], "Value3_2"); Assert.IsNull(this.file["Key4"]); DBFilesObjectSerializationTests.AssertEqual(this.file["Key5"] as Simple, Obj2); AssertEx.Same(this.file["Key6"], ByteArray2); }
public async Task DBFiles_RetryLastTest_02_Retry_Delete() { FileStatistics StatBefore = (await this.file.ComputeStatistics()).Key; Guid ObjectId = this.LoadObjectId(); try { await this.file.DeleteObject(ObjectId); } catch (Exception ex) { Console.Out.WriteLine(await DBFilesBTreeTests.ExportXML(this.file, "Data\\BTreeError.xml")); ExceptionDispatchInfo.Capture(ex).Throw(); } Console.Out.WriteLine(await DBFilesBTreeTests.ExportXML(this.file, "Data\\BTreeAfter.xml")); await DBFilesBTreeTests.AssertConsistent(this.file, this.provider, (int)(StatBefore.NrObjects - 1), null, true); }
public void DBFiles_StringDictionary_07_DataTypes() { Simple Obj = DBFilesBTreeTests.CreateSimple(100); this.file["Key1"] = true; this.file["Key2"] = (byte)1; this.file["Key3"] = (short)2; this.file["Key4"] = (int)3; this.file["Key5"] = (long)4; this.file["Key6"] = (sbyte)5; this.file["Key7"] = (ushort)6; this.file["Key8"] = (uint)7; this.file["Key9"] = (ulong)8; this.file["Key10"] = (decimal)9; this.file["Key11"] = (double)10; this.file["Key12"] = (float)11; this.file["Key13"] = (DateTime)DateTime.Today; this.file["Key14"] = TimeSpan.Zero; this.file["Key15"] = 'a'; this.file["Key16"] = "Hello"; this.file["Key17"] = NormalEnum.Option2; this.file["Key18"] = Guid.Empty.ToByteArray(); AssertEx.Same(this.file["Key1"], true); AssertEx.Same(this.file["Key2"], (byte)1); AssertEx.Same(this.file["Key3"], (short)2); AssertEx.Same(this.file["Key4"], (int)3); AssertEx.Same(this.file["Key5"], (long)4); AssertEx.Same(this.file["Key6"], (sbyte)5); AssertEx.Same(this.file["Key7"], (ushort)6); AssertEx.Same(this.file["Key8"], (uint)7); AssertEx.Same(this.file["Key9"], (ulong)8); AssertEx.Same(this.file["Key10"], (decimal)9); AssertEx.Same(this.file["Key11"], (double)10); AssertEx.Same(this.file["Key12"], (float)11); AssertEx.Same(this.file["Key13"], (DateTime)DateTime.Today); AssertEx.Same(this.file["Key14"], TimeSpan.Zero); AssertEx.Same(this.file["Key15"], 'a'); AssertEx.Same(this.file["Key16"], "Hello"); AssertEx.Same(this.file["Key17"], "Option2"); AssertEx.Same(this.file["Key18"], Guid.Empty.ToByteArray()); }