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 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);
        }
        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);
        }
Example #7
0
        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());
        }