public void SaveLoadValues() { XmlFileManager fileManager = new XmlFileManager(new CimTools.Legacy.CimToolSettings("TestSaveLoad")); fileManager.Data.SetValue("testUshort", (ushort)2); fileManager.Data.SetValue("testFloat", 10.4f); fileManager.Data.SetValue("testString", "hello"); fileManager.Data.SetValue("testDouble", 19.2); fileManager.Data.SetValue("testInt", 19); fileManager.Data.SetValue("testInt", 2082, "awesome group"); fileManager.Data.SetValue("testDouble", 106.8, "awesome group"); fileManager.Data.SetValue("testString", "hello again", "awesome group"); fileManager.Data.SetValue("testDifferentString", "hello again again", "awesome group"); fileManager.Data.SetValue("testDifferentGroup", "hi", "not as awesome group"); bool succeeded = fileManager.Save() == ExportOptionBase.OptionError.NoError; Assert.IsTrue(succeeded, "Options failed to save to disk"); if (succeeded) { float floatValue = 0; int intValue = 0; string stringValue = ""; fileManager = new XmlFileManager(new CimTools.Legacy.CimToolSettings("TestSaveLoad")); bool valid = fileManager.Data.GetValue("testFloat", ref floatValue) == ExportOptionBase.OptionError.NoError; Assert.IsFalse(valid); fileManager.Load(); valid = fileManager.Data.GetValue("testFloat", ref floatValue) == ExportOptionBase.OptionError.NoError; Assert.IsTrue(valid, "Obtaining \"testFloat\" from the options"); if (valid) { Assert.AreEqual(10.4f, floatValue, "Checking whether the value is a float"); } valid = fileManager.Data.GetValue("testInt", ref intValue, "awesome group") == ExportOptionBase.OptionError.NoError; Assert.IsTrue(valid, "Obtaining \"testInt\" from the options under \"awesome group\""); if (valid) { Assert.AreEqual(2082, intValue, "Checking whether the value is an int"); } valid = fileManager.Data.GetValue("testString", ref stringValue, "awesome group") == ExportOptionBase.OptionError.NoError; Assert.IsTrue(valid, "Obtaining \"testString\" from the options under \"awesome group\""); if (valid) { Assert.AreEqual("hello again", stringValue, "Checking whether the value is a string"); } } }
public void SaveLoadUsingAttributes() { XmlFileManager testManager = new XmlFileManager(new CimToolBase(new CimToolSettings("", "SaveLoadUsingAttributesTest", modAssembly: Assembly.GetExecutingAssembly()))); TestNonStaticOverriddenClass testClassOverridden = new TestNonStaticOverriddenClass(); TestNonStaticNonOverriddenClass testClassNonOverridden = new TestNonStaticNonOverriddenClass(); testManager.AddObjectToSave(testClassOverridden); testManager.AddObjectToSave(testClassNonOverridden); testManager.Save(); TestOverriddenNameClass.testInt = -100; TestOverriddenNameClass.testString = "differentValue"; TestOverriddenNameClass.testDictionaryDouble = new Dictionary <string, double>() { { "new double", -23.4567 }, { "another double", 98877.52322 } }; TestOverriddenNameClass.testListInt = new List <int>() { 9, 8, 7, 6 }; testClassOverridden.testInt = -100; testClassOverridden.testString = "differentValue"; testClassOverridden.testDictionaryDouble = new Dictionary <string, double>() { { "new double", -23.4567 }, { "another double", 98877.52322 } }; testClassOverridden.testListInt = new List <int>() { 9, 8, 7, 6 }; Assert.AreEqual(-100, TestOverriddenNameClass.testInt); Assert.AreEqual("differentValue", TestOverriddenNameClass.testString); Assert.AreEqual(-23.4567, TestOverriddenNameClass.testDictionaryDouble["new double"]); Assert.AreEqual(98877.52322, TestOverriddenNameClass.testDictionaryDouble["another double"]); Assert.AreEqual(4, TestOverriddenNameClass.testListInt.Count); Assert.AreEqual(-100, testClassOverridden.testInt); Assert.AreEqual("differentValue", testClassOverridden.testString); Assert.AreEqual(-23.4567, testClassOverridden.testDictionaryDouble["new double"]); Assert.AreEqual(98877.52322, testClassOverridden.testDictionaryDouble["another double"]); Assert.AreEqual(4, testClassOverridden.testListInt.Count); testManager.Load(); Assert.AreEqual(15, TestOverriddenNameClass.testInt); Assert.AreEqual("test string", TestOverriddenNameClass.testString); Assert.AreEqual(0.00005, TestOverriddenNameClass.testDictionaryDouble["doublekey1"]); Assert.AreEqual(2, TestOverriddenNameClass.testDictionaryDouble.Count); Assert.AreEqual(6, TestOverriddenNameClass.testListInt.Count); Assert.AreEqual(1, TestOverriddenNameClass.testListInt[0]); Assert.AreEqual(2, TestOverriddenNameClass.testListInt[1]); Assert.AreEqual(3, TestOverriddenNameClass.testListInt[2]); Assert.AreEqual(4, TestOverriddenNameClass.testListInt[3]); Assert.AreEqual(5, TestOverriddenNameClass.testListInt[4]); Assert.AreEqual(6, TestOverriddenNameClass.testListInt[5]); Assert.AreEqual(150, testClassOverridden.testInt); Assert.AreEqual("test non static string", testClassOverridden.testString); Assert.AreEqual(0.00005, testClassOverridden.testDictionaryDouble["doublekey2"]); Assert.AreEqual(1, testClassOverridden.testDictionaryDouble.Count); Assert.AreEqual(6, testClassOverridden.testListInt.Count); Assert.AreEqual(10, testClassOverridden.testListInt[0]); Assert.AreEqual(20, testClassOverridden.testListInt[1]); Assert.AreEqual(30, testClassOverridden.testListInt[2]); Assert.AreEqual(40, testClassOverridden.testListInt[3]); Assert.AreEqual(50, testClassOverridden.testListInt[4]); Assert.AreEqual(60, testClassOverridden.testListInt[5]); }