예제 #1
0
        public void TestStorageList()
        {
            _ = new DC(null);

            var parent      = new TestParent("Parent", isStoring: false);
            var storageList = new StorageList <TestChild>();

            assert(storageList, "", "");

            var child0 = new TestChild("Child0", parent, isStoring: false);

            storageList.Add(child0);
            assert(storageList,
                   @"",
                   @"Key: noKey, Text: Child0, Parent: noKey, Parent;");

            var child1 = new TestChild("Child1", parent, isStoring: false);

            storageList.Add(child1);
            assert(storageList,
                   @"",
                   @"Key: noKey, Text: Child0, Parent: noKey, Parent;
          Key: noKey, Text: Child1, Parent: noKey, Parent;");

            parent.Store();
            assert(storageList,
                   @"",
                   @"Key: noKey, Text: Child0, Parent: 0, Parent;
          Key: noKey, Text: Child1, Parent: 0, Parent;");

            child0.Store();
            assert(storageList,
                   @"Key: 0, Text: Child0, Parent: 0, Parent;",
                   @"Key: 0, Text: Child0, Parent: 0, Parent;
          Key: noKey, Text: Child1, Parent: 0, Parent;");

            child1.Store();
            assert(storageList,
                   @"Key: 0, Text: Child0, Parent: 0, Parent;
          Key: 1, Text: Child1, Parent: 0, Parent;",
                   @"Key: 0, Text: Child0, Parent: 0, Parent;
          Key: 1, Text: Child1, Parent: 0, Parent;");

            child0.Release();
            assert(storageList,
                   @"Key: 1, Text: Child1, Parent: 0, Parent;",
                   @"Key: noKey, Text: Child0, Parent: 0, Parent;
          Key: 1, Text: Child1, Parent: 0, Parent;");
        }
예제 #2
0
        public void TestDCRestore()
        {
            var directoryInfo = new DirectoryInfo("TestCsv");
            var csvConfig     = new CsvConfig(directoryInfo.FullName, reportException: reportException);

            directoryInfo.Refresh();
            if (directoryInfo.Exists)
            {
                directoryInfo.Delete(recursive: true);
                directoryInfo.Refresh();
            }

            directoryInfo.Create();
            directoryInfo.Refresh();

            try {
                var dc          = new DC(csvConfig);
                var testParent0 = new TestParent("TestParent0");
                var testParent1 = new TestParent("TestParent1");
                var testParent2 = new TestParent("TestParent2");
                var testChild0  = new TestChild("TestChild0", testParent0);
                var testChild1  = new TestChild("TestChild1", testParent2);
                var testChild2  = new TestChild("TestChild2", testParent0);
                testChild1.Release();
                testParent2.Release();
                testChild2.Update("TestChild2 updated", testParent1);
                var expectedTestParent0 = testParent0.ToString();
                var expectedTestParent1 = testParent1.ToString();
                var expectedTestChild0  = testChild0.ToString();
                var expectedTestChild2  = testChild2.ToString();
                dc.Dispose();
                File.Delete(directoryInfo.FullName + @"\TestParent.csv");
                File.Move(directoryInfo.FullName + @"\TestParent.bak", directoryInfo.FullName + @"\TestParent.csv");
                File.Delete(directoryInfo.FullName + @"\TestChild.csv");
                File.Move(directoryInfo.FullName + @"\TestChild.bak", directoryInfo.FullName + @"\TestChild.csv");

                dc = new DC(csvConfig);
                Assert.AreEqual(expectedTestParent0, dc.TestParents[0].ToString());
                Assert.AreEqual(expectedTestParent1, dc.TestParents[1].ToString());
                Assert.AreEqual(expectedTestChild0, dc.TestChildren[0].ToString());
                Assert.AreEqual(expectedTestChild2, dc.TestChildren[2].ToString());
            } finally {
                DC.Data?.Dispose();
            }
        }