public void GivenADeserializerWithDefaultConstructorThenDefaultsAreUsed() { var serializer = new IniDeserializer(); Assert.Same(IniDeserializationOptions.Default, serializer.Options); Assert.Same(IniNormalizer.Default, serializer.Normalizer); }
public void GivenADeserializerReceivingCustomOptionsThenDefaultNormalizerIsUsed() { var options = new IniDeserializationOptions(); var serializer = new IniDeserializer(options); Assert.Same(options, serializer.Options); Assert.Same(IniNormalizer.Default, serializer.Normalizer); }
public void GivenADeserializerReceivingCustomNormalizerThenDefaultOptionsAreUsed() { var normalizer = new IniNormalizer(); var serializer = new IniDeserializer(normalizer); Assert.Same(IniDeserializationOptions.Default, serializer.Options); Assert.Same(normalizer, serializer.Normalizer); }
public void GivenADeserializerReceivingCustomParametersThenReferencesAreTheSame() { var options = new IniDeserializationOptions(); var normalizer = new IniNormalizer(); var serializer = new IniDeserializer(options, normalizer); Assert.Same(options, serializer.Options); Assert.Same(normalizer, serializer.Normalizer); }
public void DeserializesSectionIntoPoco() { // Arrange. var deserializer = new IniDeserializer(); // Act. var foo = deserializer.DeserializeSection <FooSection>("[Foo]\nBar = 123\n", "Foo"); // Assert. Assert.NotNull(foo); Assert.Equal(123, foo.Bar); }
public void DeserializesSectionIntoPocoWithAttributes() { // Arrange. var deserializer = new IniDeserializer(); // Act. var foo = deserializer.DeserializeSection <FooSectionWithAttributes>("[Fuzz]\nBuzz = 123\n", "Fuzz"); // Assert. Assert.NotNull(foo); Assert.Equal(123, foo.Bar); }
public void DeserializesSectionIntoDictionary() { // Arrange. var deserializer = new IniDeserializer(); // Act. IDictionary<string, string> dict = deserializer.DeserializeSection("[Foo]\nBar = 123\n", "Foo"); // Assert. Assert.Equal(1, dict.Count); Assert.True(dict.ContainsKey("Bar")); Assert.Equal("123", dict["Bar"]); }
public void DeserializesSectionIntoDictionary() { // Arrange. var deserializer = new IniDeserializer(); // Act. IDictionary <string, string> dict = deserializer.DeserializeSection("[Foo]\nBar = 123\n", "Foo"); // Assert. Assert.Equal(1, dict.Count); Assert.True(dict.ContainsKey("Bar")); Assert.Equal("123", dict["Bar"]); }
public void Run() { const string initialIni = @" ;This is a comment SomeGP=This is a global property [SomeSection] ;This is a comment inside a section SomeSP=This is a property inside a section [AnotherSection] ;Another comment... AnotherSP=More? Response=YES!!! "; _logger.LogInformation("Initial INI string: '{initialIniString}'", initialIni); _logger.LogDebug("Deserializing string as an IniContainer..."); var deserializer = new IniDeserializer { Options = { NormalizeAfterDeserialization = false } }; var iniContainer = deserializer.DeserializeAsContainer(initialIni); _logger.LogDebug("Normalizing IniContainer..."); var normalizer = new IniNormalizer(); iniContainer = normalizer.Normalize(iniContainer); _logger.LogDebug("Serializing IniContainer as a string..."); var serializer = new IniSerializer { Options = { EmptyLineBeforeSection = true, NormalizeBeforeSerialization = false } }; var finalIni = serializer.SerializeAsString(iniContainer); _logger.LogInformation("Final INI string: " + Environment.NewLine + "'{finalIniString}'", finalIni); /* * ;This is a comment * SOMEGP=This is a global property * * [SOMESECTION] * ;This is a comment inside a section * SOMESP=This is a property inside a section * * [ANOTHERSECTION] * ;Another comment... * ANOTHERSP=More? * RESPONSE=YES!!! */ }
public void DeserializesIntoPocoWithAttributes() { // Arrange. var deserializer = new IniDeserializer(); // Act. var cfg = deserializer.Deserialize <ConfigWithAttributes>("Num = 321\n[Fuzz]\nBuzz = 123\n"); // Assert. Assert.NotNull(cfg); Assert.NotNull(cfg.Foo); Assert.Equal(321, cfg.Number); Assert.Equal(123, cfg.Foo.Bar); }
public void DeserializesIntoPoco() { // Arrange. var deserializer = new IniDeserializer(); // Act. var cfg = deserializer.Deserialize <Config>("Number = 321\n[Foo]\nBar = 123\n"); // Assert. Assert.NotNull(cfg); Assert.NotNull(cfg.Foo); Assert.Equal(321, cfg.Number); Assert.Equal(123, cfg.Foo.Bar); }
public void DeserializesIntoPoco() { // Arrange. var deserializer = new IniDeserializer(); // Act. var cfg = deserializer.Deserialize<Config>("Number = 321\n[Foo]\nBar = 123\n"); // Assert. Assert.NotNull(cfg); Assert.NotNull(cfg.Foo); Assert.Equal(321, cfg.Number); Assert.Equal(123, cfg.Foo.Bar); }
public void DeserializesTopLevelIntoDictionary() { // Arrange. var deserializer = new IniDeserializer(); // Act. var dict = deserializer.Deserialize("Bar = 123\n"); // Assert. Assert.Equal(1, dict.Count); Assert.Equal("", dict.First().Key); Assert.Equal(1, dict.First().Value.Count); Assert.True(dict.First().Value.ContainsKey("Bar")); Assert.Equal("123", dict.First().Value["Bar"]); }
public void GivenADeserializerWithDefaultConstructorWhenDeserializingFromStringThenStandardContainerMatch() { var deserializer = new IniDeserializer(); var container = deserializer.DeserializeAsContainer(StandardNoErrors); Assert.NotNull(container); Assert.Equal(2, container.GlobalComments.Count); Assert.Equal("gc 01", container.GlobalComments[0]); Assert.Equal("gc 02", container.GlobalComments[1]); Assert.Equal(2, container.GlobalProperties.Count); Assert.Equal("GP01", container.GlobalProperties[0].Name); Assert.Equal("gp 01 value", container.GlobalProperties[0].Value); Assert.Equal("GP02", container.GlobalProperties[1].Name); Assert.Equal("gp 02 value", container.GlobalProperties[1].Value); Assert.Equal(2, container.Sections.Count); }
public void DeserializesIntoDictionary() { // Arrange. var deserializer = new IniDeserializer(); // Act. var dict = deserializer.Deserialize("Abc = 321\n[Foo]\nBar = 123\n"); // Assert. Assert.Equal(2, dict.Count); var first = dict.First(); var second = dict.ElementAt(1); Assert.Equal("", first.Key); Assert.Equal(1, first.Value.Count); Assert.True(first.Value.ContainsKey("Abc")); Assert.Equal("321", first.Value["Abc"]); Assert.Equal("Foo", second.Key); Assert.Equal(1, second.Value.Count); Assert.True(second.Value.ContainsKey("Bar")); Assert.Equal("123", second.Value["Bar"]); }
public void DeserializesSectionIntoPoco() { // Arrange. var deserializer = new IniDeserializer(); // Act. var foo = deserializer.DeserializeSection<FooSection>("[Foo]\nBar = 123\n", "Foo"); // Assert. Assert.NotNull(foo); Assert.Equal(123, foo.Bar); }