public void Test_LoadFromXml() { string testResourcesPath = UTHelperPrivate.GetTestResourcesPath(); Profile p = XmlSerializerExt.Deserialize <Profile>(Path.Combine(testResourcesPath, "Profile_Test-profile1.xml")); Assert.AreEqual("pvalue1", p.Properties.Get("pvar1")); Assert.AreEqual("pvalue2", p.Properties.Get("pvar2")); Assert.IsTrue(p.Properties.XmlMergeWithGlobal); }
public void Test_StandardParameters() { // Test definition of properties. NoParametersStd parsed = new NoParametersStd(); string[] args = new string[] { "-d:var1=value1", "-d:var2=value2" }; Props.Global.Set("var1", null); Props.Global.Set("var2", null); Assert.IsTrue(Parser.ParseArguments(args, parsed)); Assert.AreEqual("profile.xml", parsed.ProfileFile); Assert.IsNull(parsed.Profile); Assert.AreEqual("value1", Props.Global.Get("var1")); Assert.AreEqual("value2", Props.Global.Get("var2")); // Overwrite a standard variable string tmp = Props.Global.Get("bds.VarDir"); parsed = new NoParametersStd(); args = new string[] { "-d:bds.VarDir=c:\temp" }; Assert.IsTrue(Parser.ParseArguments(args, parsed)); Assert.AreEqual("c:\temp", Props.Global.Get("bds.VarDir")); Props.Global.Set("bds.VarDir", tmp); // Test a profile. Props.Global.Set("var1", null); Props.Global.Set("var2", null); Props.Global.Set("pvar1", null); Props.Global.Set("pvar2", null); string testResourcesPath = UTHelperPrivate.GetTestResourcesPath(); string profileFile = Path.Combine(testResourcesPath, "Profile_Test-profile1.xml"); args = new string[] { "-d:var1=value1", "-d:var2=value2", "-d:pvar2=overwritten", "--profile:" + profileFile }; Assert.IsTrue(Parser.ParseArguments(args, parsed)); Assert.AreEqual(profileFile, parsed.ProfileFile); Assert.IsNotNull(parsed.Profile); Assert.AreEqual("value1", Props.Global.Get("var1")); Assert.AreEqual("value2", Props.Global.Get("var2")); Assert.AreEqual("pvalue1", Props.Global.Get("pvar1")); Assert.AreEqual("overwritten", Props.Global.Get("pvar2")); // Test wrong format of properties args = new string[] { "-d:var1*value1", "-d:=value2" }; Assert.IsFalse(Parser.ParseArguments(args, parsed)); }
public void Test_XmlDeserialize() { string testResourcesPath = UTHelperPrivate.GetTestResourcesPath(); string fileName = Path.Combine(testResourcesPath, "Props_Test-prop1.xml"); // Merged with global variables Props p = XmlSerializerExt.Deserialize <Props>(fileName); Assert.AreEqual("pvalue1", p.Get("pvar1")); Assert.AreEqual("pvalue2", p.Get("pvar2")); Assert.IsTrue(AreDirPathsEqual(testResourcesPath, p.Get("MyDirName"))); Assert.AreEqual(fileName, p.Get("MyFileName")); Assert.IsTrue(p.XmlMergeWithGlobal); Assert.IsNotNull(p.Get("ai.Root")); // Not merged with global variables p = XmlSerializerExt.Deserialize <Props>(Path.Combine(testResourcesPath, "Props_Test-prop2.xml")); Assert.AreEqual("pvalue1", p.Get("pvar1")); Assert.AreEqual("pvalue2", p.Get("pvar2")); Assert.IsFalse(p.XmlMergeWithGlobal); Assert.IsNull(p.Get("ai.Root")); }