public void Test_Serialize_SingleFieldType() { ExampleSingleFieldConfig configInstance = new ExampleSingleFieldConfig { firstField = new ExampleSingleFieldConfig.SingleFieldType1 { secondField = new ExampleSingleFieldConfig.SingleFieldType2 { a = 1, b = 2 } } }; const string expectedResult = @" - a = 1 - b = 2 "; IEnumerable <string> lines = new ConfigSerializer( new ConfigOptions { keyFormatOption = EFormatOption.QuoteValue, valueFormatOption = EFormatOption.QuoteValue }).Serialize(configInstance); Assert.AreEqual(expectedResult.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries), lines.ToArray()); }
public void Test_SerializeNullValues() { ExampleNullableConfig exampleNullableConfig = new ExampleNullableConfig { stringValue = null, stringValue2 = "~", stringList = new List <string> { null, "~" }, subClassList = new List <ExampleNullableConfig.ExampleNullableSubClass> { new ExampleNullableConfig.ExampleNullableSubClass { a = null }, new ExampleNullableConfig.ExampleNullableSubClass { a = "~" } }, stringDict = new Dictionary <string, string> { { "str1", null }, { "~", "~" } }, subClassDict = new Dictionary <string, ExampleNullableConfig.ExampleNullableSubClass> { { "str1", new ExampleNullableConfig.ExampleNullableSubClass { a = null } }, { "~", new ExampleNullableConfig.ExampleNullableSubClass { a = "~" } } } }; const string expectedResult = @" - intValue = 1 - stringValue = ~ - stringValue2 = ""~"" - intList : -- 1 -- 1 - stringList : -- ~ -- ""~"" - subClassList : -- : --- a = ~ --- b = 1 -- : --- a = ""~"" --- b = 1 - intDict : -- 1 = 1 -- 2 = 2 - stringDict : -- str1 = ~ -- ""~"" = ""~"" - subClassDict : -- str1 : --- a = ~ --- b = 1 -- ""~"" : --- a = ""~"" --- b = 1 "; IEnumerable <string> lines = new ConfigSerializer( new ConfigOptions { keyFormatOption = EFormatOption.QuoteValue, valueFormatOption = EFormatOption.QuoteValue }).Serialize(exampleNullableConfig); Assert.AreEqual(expectedResult.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries), lines.ToArray()); }