public void TestConfTree_AddMixToTree2() { ConfTree tree1 = new ConfTree("Tree1"); tree1.Add(new ConfItem("Item1-1", "Value1-1")); ConfTree tree2 = new ConfTree("Tree2"); tree2.Add(new ConfItem("Item2-1", "Value2-1")); tree2.Add(new ConfItem("Item2-2", "Value2-2")); ConfTree tree3 = new ConfTree("Tree3"); tree3.Add(new ConfItem("Item3-1", "Value3-1")); tree3.Add(new ConfItem("Item3-2", "Value3-2")); tree1.Add(tree2); tree2.Add(tree3); Assert.IsTrue(tree1.Find("Item1-1").Path == "/Tree1"); Assert.IsTrue(tree1.Find("Tree2").Path == "/Tree1"); Assert.IsTrue(tree1.Find("Item2-1").Path == "/Tree1/Tree2"); Assert.IsTrue(tree1.Find("Tree3").Path == "/Tree1/Tree2"); Assert.IsTrue(tree1.Find("Item3-1").Path == "/Tree1/Tree2/Tree3"); Assert.IsTrue(tree1.Find("Item3-2").Path == "/Tree1/Tree2/Tree3"); GlobalVar.Log.Debug(tree1.ShowAll()); }
public void TestConfTree_Clone_Modify_Save() { ConfTree conf1 = Builder.Generate(new Dictionary <string, string> { { "Item1", "Value1" }, { "Item2", "Value2" }, }, "DictionaryConf"); Builder.Xml.Save(conf1, $"{GlobalVar.ResultPath}/Conf.xml"); GlobalVar.Log.Debug(conf1.ShowAll()); ConfTree conf2 = conf1.Clone("new") as ConfTree; Builder.Xml.Save(conf2 as ConfTree); conf1["Item1"] = "Value3"; Builder.Xml.Save(conf1 as ConfTree); Debug.WriteLine(conf2.ToString()); conf2["Item2"] = "Value4"; Builder.Xml.Save(conf2 as ConfTree); ConfTree readback = Builder.Xml.Generate($"{GlobalVar.ResultPath}/Conf.xml"); Debug.WriteLine(readback.ToString()); JbAssert.Equal(readback["Default:Item1"], "Value3"); JbAssert.Equal(readback["Default:Item2"], "Value2"); JbAssert.Equal(readback["new:Item1"], "Value1"); JbAssert.Equal(readback["new:Item2"], "Value4"); }
public void TestConfTreeFind_Conflict() { ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/MultiLevel.xml"); GlobalVar.Log.Debug(conf.ShowAll()); JbAssert.Equal(conf[@"Level1/Item"], "1.0"); JbAssert.Equal(conf[@"Level1/Item1"], "1.1"); JbAssert.Equal(conf[@"Level2/Item"], "2.0"); JbAssert.Equal(conf[@"Level2/Item2"], "2.1"); JbAssert.Equal(conf[@"Level2/Item22"], "2.2"); JbAssert.Equal(conf[@"Level1/Level2/Item"], "2.0"); JbAssert.Equal(conf[@"Level1/Level2/Item2"], "2.1"); JbAssert.Equal(conf[@"Level1/Level2/Item22"], "2.2"); JbAssert.Equal(conf[@"Level3/Item"], "3.0"); JbAssert.Equal(conf[@"Level3/Item3"], "3.1"); JbAssert.Equal(conf[@"Level2/Level3/Item"], "3.0"); JbAssert.Equal(conf[@"Level2/Level3/Item3"], "3.1"); JbAssert.Equal(conf[@"Level1/Level2/Level3/Item"], "3.0"); JbAssert.Equal(conf[@"Level1/Level2/Level3/Item3"], "3.1"); JbAssert.Equal(conf[@"Level4/Item"], "4.0"); JbAssert.Equal(conf.FindStrict("Item", null, false).Value, "1.0"); JbAssert.Equal(conf.FindStrict(@"Level1/Item").Value, "1.0"); Assert.ThrowsException <Exception>(() => { conf.FindStrict("Item"); }); }
public void TestConfTree_AddItemToTree() { ConfTree conf = new ConfTree("TestBuildTree"); Assert.IsTrue(conf.Name == "TestBuildTree"); conf.Add(new ConfItem("Item1", "Value1")); Assert.IsTrue(conf["Item1"] == "Value1"); Assert.IsTrue(conf.Find("Item1").Path == "/TestBuildTree"); GlobalVar.Log.Debug(conf.ShowAll()); }
public void TestConfTree_AddTreeToTree() { ConfTree tree1 = new ConfTree("Tree1"); tree1.Add(new ConfItem("Item1", "Value1")); ConfTree tree2 = new ConfTree("Tree2"); tree2.Add(new ConfItem("Item2", "Value2")); tree1.Add(tree2); Assert.IsTrue(tree1.Find("Item1").Path == "/Tree1"); Assert.IsTrue(tree1.Find("Tree2").Path == "/Tree1"); Assert.IsTrue(tree1.Find("Item2").Path == "/Tree1/Tree2"); Assert.IsTrue(tree1.Find("Item1").Parent.Name == "Tree1"); Assert.IsTrue(tree1.Find("Tree2").Parent.Name == "Tree1"); Assert.IsTrue(tree1.Find("Item2").Parent.Name == "Tree2"); GlobalVar.Log.Debug(tree1.ShowAll()); }