Example #1
0
 private static void createParents(
     int activitiesCount,
     out ChildrenList_Parent[] parentP,
     out ChildrenList_ParentReadonly[] parentPr,
     out ChildrenList_CreateOnlyParent[] parentPC,
     out ChildrenList_CreateOnlyParentReadonly[] parentPCr)
 {
     parentP   = new ChildrenList_Parent[activitiesCount];
     parentPr  = new ChildrenList_ParentReadonly[activitiesCount];
     parentPC  = new ChildrenList_CreateOnlyParent[activitiesCount];
     parentPCr = new ChildrenList_CreateOnlyParentReadonly[activitiesCount];
     for (int i = 0; i < activitiesCount; i++)
     {
         parentP[i]   = new ChildrenList_Parent($"{i}");
         parentPr[i]  = new ChildrenList_ParentReadonly($"{i}");
         parentPC[i]  = new ChildrenList_CreateOnlyParent($"{i}");
         parentPCr[i] = new ChildrenList_CreateOnlyParentReadonly($"{i}");
     }
 }
Example #2
0
        public void TestChildrenList()
        {
            try {
                parents                    = new DataStoreStats();
                parentReadonlies           = new DataStoreStats();
                parentNullables            = new DataStoreStats();
                parentNullableReadonlies   = new DataStoreStats();
                coParents                  = new DataStoreStats();
                coParentReadonlies         = new DataStoreStats();
                coParentNullables          = new DataStoreStats();
                coParentNullableReadonlies = new DataStoreStats();
                children                   = new DataStoreStats();
                coChildren                 = new DataStoreStats();
                childrenTestString         = new Dictionary <int, string>();


                var directoryInfo = new DirectoryInfo("TestCsv");
                if (directoryInfo.Exists)
                {
                    directoryInfo.Delete(recursive: true);
                    directoryInfo.Refresh();
                }

                directoryInfo.Create();

                csvConfig = new CsvConfig(directoryInfo.FullName, reportException: reportException);
                DC.Trace  = dcTrace;
                initDC();
                assertData();

                traceHeader("--- construct and store parent P0, PN0, CP0, CPN0 ---");
                DC.Data.StartTransaction();
                var p0    = new ChildrenList_Parent("P0");
                var p0r   = new ChildrenList_ParentReadonly("P0r");
                var pn0   = new ChildrenList_ParentNullable("PN0", isStoring: false);
                var pn0r  = new ChildrenList_ParentNullableReadonly("PN0r", isStoring: false);
                var cp0   = new ChildrenList_CreateOnlyParent("CP0");
                var cp0r  = new ChildrenList_CreateOnlyParentReadonly("CP0r");
                var cpn0  = new ChildrenList_CreateOnlyParentNullable("CPN0", isStoring: false);
                var cpn0r = new ChildrenList_CreateOnlyParentNullableReadonly("CPN0r", isStoring: false);
                DC.Data.RollbackTransaction();
                assertData();
                DC.Data.StartTransaction();
                p0.Store();
                var p0Key = p0.Key;
                p0r.Store();
                var p0rKey = p0r.Key;
                pn0.Store();
                var pn0Key = pn0.Key;
                pn0r.Store();
                var pn0rKey = pn0r.Key;
                cp0.Store();
                var cp0Key = cp0.Key;
                cp0r.Store();
                var cp0rKey = cp0r.Key;
                cpn0.Store();
                var cpn0Key = cpn0.Key;
                cpn0r.Store();
                var cpn0rKey = cpn0r.Key;
                DC.Data.CommitTransaction();
                parents.Items[p0Key] = p0.ToString();
                parents.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 0);
                parentReadonlies.Items[p0rKey] = p0r.ToString();
                parentReadonlies.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 0);
                coParents.Items[cp0Key] = cp0.ToString();
                coParents.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 0);
                coParentReadonlies.Items[cp0rKey] = cp0r.ToString();
                coParentReadonlies.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 0);
                parentNullables.Items[pn0Key] = pn0.ToString();
                parentNullables.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 0);
                parentNullableReadonlies.Items[pn0rKey] = pn0r.ToString();
                parentNullableReadonlies.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 0);
                coParentNullables.Items[cpn0Key] = cpn0.ToString();
                coParentNullables.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 0);
                coParentNullableReadonlies.Items[cpn0rKey] = cpn0r.ToString();
                coParentNullableReadonlies.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 0);
                assertData();

                traceHeader("--- construct and store children C0 and CC0 ---");
                p0    = DC.Data.ChildrenList_Parents[p0Key];
                p0r   = DC.Data.ChildrenList_ParentReadonlys[p0rKey];
                pn0   = DC.Data.ChildrenList_ParentNullables[pn0Key];
                pn0r  = DC.Data.ChildrenList_ParentNullableReadonlys[pn0rKey];
                cp0   = DC.Data.ChildrenList_CreateOnlyParents[cp0Key];
                cp0r  = DC.Data.ChildrenList_CreateOnlyParentReadonlys[cp0rKey];
                cpn0  = DC.Data.ChildrenList_CreateOnlyParentNullables[cpn0Key];
                cpn0r = DC.Data.ChildrenList_CreateOnlyParentNullableReadonlys[cpn0rKey];
                DC.Data.StartTransaction();
                var c0  = new  ChildrenList_Child("C0", p0, p0r, pn0, pn0r, cp0, cp0r, cpn0, cpn0r);
                var cc0 = new  ChildrenList_CreateOnlyChild("CC0", cp0, cp0r, cpn0, cpn0r);
                DC.Data.RollbackTransaction();
                assertData();
                p0    = DC.Data.ChildrenList_Parents[p0Key];
                p0r   = DC.Data.ChildrenList_ParentReadonlys[p0rKey];
                pn0   = DC.Data.ChildrenList_ParentNullables[pn0Key];
                pn0r  = DC.Data.ChildrenList_ParentNullableReadonlys[pn0rKey];
                cp0   = DC.Data.ChildrenList_CreateOnlyParents[cp0Key];
                cp0r  = DC.Data.ChildrenList_CreateOnlyParentReadonlys[cp0rKey];
                cpn0  = DC.Data.ChildrenList_CreateOnlyParentNullables[cpn0Key];
                cpn0r = DC.Data.ChildrenList_CreateOnlyParentNullableReadonlys[cpn0rKey];
                DC.Data.StartTransaction();
                c0 = new  ChildrenList_Child("C0", p0, p0r, pn0, pn0r, cp0, cp0r, cpn0, cpn0r);
                var c0Key = c0.Key;
                cc0 = new  ChildrenList_CreateOnlyChild("CC0", cp0, cp0r, cpn0, cpn0r);
                var cc0Key = cc0.Key;
                DC.Data.CommitTransaction();
                parents.Items[p0Key]                       = p0.ToString();
                parentReadonlies.Items[p0rKey]             = p0r.ToString();
                coParents.Items[cp0Key]                    = cp0.ToString();
                coParentReadonlies.Items[cp0rKey]          = cp0r.ToString();
                parentNullables.Items[pn0Key]              = pn0.ToString();
                parentNullableReadonlies.Items[pn0rKey]    = pn0r.ToString();
                coParentNullables.Items[cpn0Key]           = cpn0.ToString();
                coParentNullableReadonlies.Items[cpn0rKey] = cpn0r.ToString();
                children.Items[c0Key]                      = c0.ToString();
                childrenTestString[c0Key]                  = c0.ToTestString();
                coChildren.Items[cc0Key]                   = cc0.ToString();
                children.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 0);
                coChildren.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 0);
                assertData();

                traceHeader("--- update child C0 with null parents ---");
                c0 = DC.Data.ChildrenList_Children[c0Key];
                DC.Data.StartTransaction();
                c0.Update("C0", c0.Parent, null, c0.CreateOnlyParent, null);
                DC.Data.RollbackTransaction();
                assertData();
                c0 = DC.Data.ChildrenList_Children[c0Key];
                DC.Data.StartTransaction();
                c0.Update("C0", c0.Parent, null, c0.CreateOnlyParent, null);
                DC.Data.CommitTransaction();
                pn0 = DC.Data.ChildrenList_ParentNullables[pn0Key];
                parentNullables.Items[pn0Key] = pn0.ToString();
                cpn0 = DC.Data.ChildrenList_CreateOnlyParentNullables[cpn0Key];
                coParentNullables.Items[cpn0Key] = cpn0.ToString();
                children.Items[c0Key]            = c0.ToString();
                childrenTestString[c0Key]        = c0.ToTestString();
                children.Set(isContinuous: true, isUpdated: true, isDeleted: false, firstIndex: 0, lastIndex: 0);
                assertData();
                children.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 0);

                traceHeader("--- update child C0 with parents 1 ---");
                c0 = DC.Data.ChildrenList_Children[c0Key];
                DC.Data.StartTransaction();
                var p1   = new ChildrenList_Parent("P1");
                var pn1  = new ChildrenList_ParentNullable("PN1");
                var cp1  = new ChildrenList_CreateOnlyParent("CP1");
                var cpn1 = new ChildrenList_CreateOnlyParentNullable("CPN1");
                c0.Update("C0U", p1, pn1, cp1, cpn1);
                DC.Data.RollbackTransaction();
                assertData();
                c0 = DC.Data.ChildrenList_Children[c0Key];
                DC.Data.StartTransaction();
                p1 = new ChildrenList_Parent("P1");
                var p1Key = p1.Key;
                pn1 = new ChildrenList_ParentNullable("PN1");
                var pn1Key = pn1.Key;
                cp1 = new ChildrenList_CreateOnlyParent("CP1");
                var cp1Key = cp1.Key;
                cpn1 = new ChildrenList_CreateOnlyParentNullable("CPN1");
                var cpn1Key = cpn1.Key;
                c0.Update("C0U", p1, pn1, cp1, cpn1);
                DC.Data.CommitTransaction();
                p0 = DC.Data.ChildrenList_Parents[p0Key];
                parents.Items[p0Key] = p0.ToString();
                parents.Items[p1Key] = p1.ToString();
                parents.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 1);
                pn0 = DC.Data.ChildrenList_ParentNullables[pn0Key];
                parentNullables.Items[pn0Key] = pn0.ToString();
                parentNullables.Items[pn1Key] = pn1.ToString();
                parentNullables.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 1);
                cp0 = DC.Data.ChildrenList_CreateOnlyParents[cp0Key];
                coParents.Items[cp0Key] = cp0.ToString();
                coParents.Items[cp1Key] = cp1.ToString();
                coParents.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 1);
                cpn0 = DC.Data.ChildrenList_CreateOnlyParentNullables[cpn0Key];
                coParentNullables.Items[cpn0Key] = cpn0.ToString();
                coParentNullables.Items[cpn1Key] = cpn1.ToString();
                coParentNullables.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 1);
                children.Items[c0Key]     = c0.ToString();
                childrenTestString[c0Key] = c0.ToTestString();
                children.Set(isContinuous: true, isUpdated: true, isDeleted: false, firstIndex: 0, lastIndex: 0);
                assertData();
                children.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 0);

                traceHeader("--- add children C1, CC1 with parents 0 ---");
                p0   = DC.Data.ChildrenList_Parents[p0Key];
                p0r  = DC.Data.ChildrenList_ParentReadonlys[p0rKey];
                cp0  = DC.Data.ChildrenList_CreateOnlyParents[cp0Key];
                cp0r = DC.Data.ChildrenList_CreateOnlyParentReadonlys[cp0rKey];
                DC.Data.StartTransaction();
                var c1     = new ChildrenList_Child("C1", p0, p0r, null, null, cp0, cp0r, null, null);
                var c1Key  = c1.Key;
                var cc1    = new ChildrenList_CreateOnlyChild("CC1", cp0, cp0r, null, null);
                var cc1Key = cc1.Key;
                DC.Data.RollbackTransaction();
                assertData();
                p0   = DC.Data.ChildrenList_Parents[p0Key];
                p0r  = DC.Data.ChildrenList_ParentReadonlys[p0rKey];
                cp0  = DC.Data.ChildrenList_CreateOnlyParents[cp0Key];
                cp0r = DC.Data.ChildrenList_CreateOnlyParentReadonlys[cp0rKey];
                DC.Data.StartTransaction();
                c1  = new ChildrenList_Child("C1", p0, p0r, null, null, cp0, cp0r, null, null);
                cc1 = new ChildrenList_CreateOnlyChild("CC1", cp0, cp0r, null, null);
                DC.Data.CommitTransaction();
                children.Items[c1Key]     = c1.ToString();
                childrenTestString[c1Key] = c1.ToTestString();
                coChildren.Items[cc1Key]  = cc1.ToString();
                parents.Items[p0Key]      = p0.ToString();
                coParents.Items[cp0Key]   = cp0.ToString();
                children.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 1);
                coChildren.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 1);
                assertData();

                traceHeader("--- test reader and writer ---");
                DC.DisposeData();
                var fromFilePath = csvConfig.DirectoryPath + "\\ChildrenList_Child.csv";
                var toFilePath   = csvConfig.DirectoryPath + "\\ChildrenList_Child.new";
                var c2Key        = 2;
                using (var reader = new ChildrenList_ChildReader(fromFilePath, csvConfig)) {
                    using var writer = new ChildrenList_ChildWriter(toFilePath, csvConfig);
                    var childIndex = 0;
                    while (reader.ReadLine(out var childRaw))
                    {
                        Assert.AreEqual(childrenTestString[childIndex++], childRaw.ToTestString());
                        writer.Write(childRaw);
                    }
                    var newChildRaw = new ChildrenList_ChildRaw {
                        Key                         = c2Key,
                        Text                        = "C2",
                        ParentKey                   = 0,
                        ParentNullableKey           = 0,
                        CreateOnlyParentKey         = 0,
                        CreateOnlyParentNullableKey = 0
                    };
                    writer.Write(newChildRaw);
                    childrenTestString[newChildRaw.Key] = newChildRaw.ToTestString();
                }
                File.Delete(fromFilePath);
                File.Move(toFilePath, fromFilePath);
                initDC();
                children.Items[2] = DC.Data.ChildrenList_Children[2].ToString();
                p0   = DC.Data.ChildrenList_Parents[p0Key];
                pn0  = DC.Data.ChildrenList_ParentNullables[pn0Key];
                cp0  = DC.Data.ChildrenList_CreateOnlyParents[cp0Key];
                cpn0 = DC.Data.ChildrenList_CreateOnlyParentNullables[cpn0Key];
                parents.Items[p0Key]             = p0.ToString();
                parentNullables.Items[pn0Key]    = pn0.ToString();
                coParents.Items[cp0Key]          = cp0.ToString();
                coParentNullables.Items[cpn0Key] = cpn0.ToString();
                children.Set(isContinuous: true, isUpdated: false, isDeleted: false, firstIndex: 0, lastIndex: 2);
                assertData();

                //some tests without disposing DC between tests
                //---------------------------------------------

                traceHeader("--- release child C1 ---");
                c1 = DC.Data.ChildrenList_Children[c1Key];
                DC.Data.StartTransaction();
                c1.Release();
                DC.Data.RollbackTransaction();
                assertData();
                c1 = DC.Data.ChildrenList_Children[c1Key];
                DC.Data.StartTransaction();
                c1.Release();
                DC.Data.CommitTransaction();
                children.Items.Remove(c1Key);
                childrenTestString.Remove(c1Key);
                children.Set(isContinuous: false, isUpdated: false, isDeleted: true, firstIndex: 0, lastIndex: 2);
                var v = parents.Items[p0Key] == DC.Data.ChildrenList_Parents[p0Key].ToString();
                parents.Items[p0Key]    = DC.Data.ChildrenList_Parents[p0Key].ToString();
                coParents.Items[cp0Key] = DC.Data.ChildrenList_CreateOnlyParents[cp0Key].ToString();
                //assertData(); doesn't work, because before closing the DC, the parent has still the released child in Children, but nor in new DC
                assertDC(isAfterDispose: false);

                traceHeader("--- release child C0 ---");
                c0 = DC.Data.ChildrenList_Children[c0Key];
                DC.Data.StartTransaction();
                c0.Release();
                DC.Data.RollbackTransaction();
                assertDC(isAfterDispose: false);
                c0 = DC.Data.ChildrenList_Children[c0Key];
                DC.Data.StartTransaction();
                c0.Release();
                DC.Data.CommitTransaction();
                children.Items.Remove(c0Key);
                childrenTestString.Remove(c0Key);
                children.Set(isContinuous: true, isUpdated: false, isDeleted: true, firstIndex: 2, lastIndex: 2);
                parents.Items[p1Key]             = DC.Data.ChildrenList_Parents[p1Key].ToString();
                parentNullables.Items[pn1Key]    = DC.Data.ChildrenList_ParentNullables[pn1Key].ToString();
                coParents.Items[cp1Key]          = DC.Data.ChildrenList_CreateOnlyParents[cp1Key].ToString();
                coParentNullables.Items[cpn1Key] = DC.Data.ChildrenList_CreateOnlyParentNullables[cpn1Key].ToString();
                assertDC(isAfterDispose: false);

                traceHeader("--- release child C2 ---");
                var c2 = DC.Data.ChildrenList_Children[2];
                DC.Data.StartTransaction();
                c2.Release();
                DC.Data.RollbackTransaction();
                assertDC(isAfterDispose: false);
                c2 = DC.Data.ChildrenList_Children[c2.Key];
                DC.Data.StartTransaction();
                c2.Release();
                DC.Data.CommitTransaction();
                children.Items.Remove(c2Key);
                childrenTestString.Remove(c2Key);
                children.Set(isContinuous: true, isUpdated: false, isDeleted: true, firstIndex: -1, lastIndex: -1);
                parents.Items[p0Key]             = DC.Data.ChildrenList_Parents[p0Key].ToString();
                parentNullables.Items[pn0Key]    = DC.Data.ChildrenList_ParentNullables[pn0Key].ToString();
                coParents.Items[cp0Key]          = DC.Data.ChildrenList_CreateOnlyParents[cp0Key].ToString();
                coParentNullables.Items[cpn0Key] = DC.Data.ChildrenList_CreateOnlyParentNullables[cpn0Key].ToString();
                assertDC(isAfterDispose: false);
            } finally {
                DC.DisposeData();
            }
        }