public void Save_CreatesValidFile() { string content = Properties.Resources.default_settings; using (StreamWriter w = new StreamWriter(filename)) { w.Write(content); } XmlParameterContainerParser loader = new XmlParameterContainerParser(); var collection = loader.Load(filename); loader.Save(collection, filename); collection = loader.Load(filename); bool b = collection.Get <bool>("TEST_BOOL"); int i = collection.Get <int>("TEST_INT"); Assert.IsTrue(b); Assert.AreEqual(3, i); }
public void Save_EachTypeOfParameter_CreatesValidFile() { int expectedInt = 46546440; float expectedFloat = 4487.2f; bool expectedBool = true; string expectedString = "Hello, world!"; float expectedFloatRange = 3.1f; int expectedIntRange = 35; List <Parameter> list = new List <Parameter>(5); list.Add(new BooleanParameter("bool", "bool", expectedBool)); list.Add(new StringParameter("string", "string", expectedString)); list.Add(new IntegerParameter("integer", "integer", expectedInt)); list.Add(new IntRangeParameter("intrange", "intrange", -7, 247, expectedIntRange)); list.Add(new FloatParameter("float", "float", expectedFloat)); list.Add(new FloatRangeParameter("floatrange", "floatrange", 2.3f, 4.8f, expectedFloatRange)); ParameterContainer fullCollection = new ParameterContainer(list); XmlParameterContainerParser loader = new XmlParameterContainerParser(); loader.Save(fullCollection, filename); var loadedCollection = loader.Load(filename); bool actualBool = loadedCollection.Get <bool>("bool"); string actualString = loadedCollection.Get <string>("string"); int actualInt = loadedCollection.Get <int>("integer"); float actualFloat = loadedCollection.Get <float>("float"); float actualFloatRange = loadedCollection.Get <float>("floatrange"); int actualIntRange = loadedCollection.Get <int>("intrange"); Assert.AreEqual(expectedBool, actualBool); Assert.AreEqual(expectedFloat, actualFloat); Assert.AreEqual(expectedFloatRange, actualFloatRange); Assert.AreEqual(expectedString, actualString); Assert.AreEqual(expectedInt, actualInt); Assert.AreEqual(expectedIntRange, actualIntRange); }