public void MakeDifferentialTree() { var struc = new Profile.ProfileStructureComponent(); struc.Element = new List<Profile.ElementComponent>(); struc.Element.Add(new Profile.ElementComponent() { Path = "A.B.C1" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.B.C1" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.B.C2" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.B" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.B.C1.D" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.D.F" }); var tree = new DifferentialTreeConstructor(struc).MakeTree(); Assert.IsNotNull(tree); var nav = new ElementNavigator(tree); Assert.AreEqual(10, nav.Count); Assert.IsTrue(nav.MoveToChild("A")); Assert.IsTrue(nav.MoveToChild("B")); Assert.IsTrue(nav.MoveToChild("C1")); Assert.IsTrue(nav.MoveToNext("C1")); Assert.IsTrue(nav.MoveToNext("C2")); Assert.IsTrue(nav.MoveToParent()); // 1st A.B Assert.IsTrue(nav.MoveToNext() && nav.Path == "A.B"); // (now) 2nd A.B Assert.IsTrue(nav.MoveToChild("C1")); Assert.IsTrue(nav.MoveToChild("D")); Assert.IsTrue(nav.MoveToParent()); // A.B.C1 Assert.IsTrue(nav.MoveToParent()); // A.B (2nd) Assert.IsTrue(nav.MoveToNext() && nav.Path == "A.D"); Assert.IsTrue(nav.MoveToChild("F")); }
public void CopyChildTree() { var dest = createTestNav(); var struc = new Profile.ProfileStructureComponent(); struc.Element = new List<Profile.ElementComponent>(); struc.Element.Add(new Profile.ElementComponent() { Path = "X" }); struc.Element.Add(new Profile.ElementComponent() { Path = "X.Y1" }); struc.Element.Add(new Profile.ElementComponent() { Path = "X.Y2" }); struc.Element.Add(new Profile.ElementComponent() { Path = "X.Y2.Z1" }); struc.Element.Add(new Profile.ElementComponent() { Path = "X.Y2.Z2" }); var source = new ElementNavigator(struc); Assert.IsTrue(dest.JumpToFirst("A.D")); var dstPos = dest.OrdinalPosition; source.MoveToFirstChild(); var srcPos = source.OrdinalPosition; Assert.IsTrue(dest.CopyChildren(source)); Assert.AreEqual(srcPos, source.OrdinalPosition, "source did not remain on original position"); Assert.AreEqual(dstPos, dest.OrdinalPosition, "dest did not remain on original position"); Assert.IsTrue(dest.MoveToFirstChild()); Assert.AreEqual("Y1", dest.PathName); Assert.IsTrue(dest.MoveToNext()); Assert.AreEqual("Y2", dest.PathName); Assert.IsFalse(dest.MoveToNext()); Assert.IsTrue(dest.MoveToFirstChild()); Assert.AreEqual("Z1", dest.PathName); Assert.IsTrue(dest.MoveToNext()); Assert.AreEqual("Z2", dest.PathName); Assert.IsFalse(dest.MoveToNext()); }
private static Profile.ProfileStructureComponent createTestStructure() { var struc = new Profile.ProfileStructureComponent(); struc.Element = new List<Profile.ElementComponent>(); struc.Element.Add(new Profile.ElementComponent() { Path = "A" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.B" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.B.C1" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.B.C2" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.B" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.B" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.B.C1" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.B.C1.D" }); struc.Element.Add(new Profile.ElementComponent() { Path = "A.D" }); return struc; }
public DifferentialTreeConstructor(Profile.ProfileStructureComponent source) { _source = source; }