Пример #1
0
        public void GivenADeserializerWithDefaultConstructorThenDefaultsAreUsed()
        {
            var serializer = new IniDeserializer();

            Assert.Same(IniDeserializationOptions.Default, serializer.Options);
            Assert.Same(IniNormalizer.Default, serializer.Normalizer);
        }
Пример #2
0
        public void GivenADeserializerReceivingCustomOptionsThenDefaultNormalizerIsUsed()
        {
            var options    = new IniDeserializationOptions();
            var serializer = new IniDeserializer(options);

            Assert.Same(options, serializer.Options);
            Assert.Same(IniNormalizer.Default, serializer.Normalizer);
        }
Пример #3
0
        public void GivenADeserializerReceivingCustomNormalizerThenDefaultOptionsAreUsed()
        {
            var normalizer = new IniNormalizer();
            var serializer = new IniDeserializer(normalizer);

            Assert.Same(IniDeserializationOptions.Default, serializer.Options);
            Assert.Same(normalizer, serializer.Normalizer);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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"]);
        }
Пример #8
0
        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"]);
        }
Пример #9
0
        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!!!
             */
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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"]);
        }
Пример #14
0
        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);
        }
Пример #16
0
        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"]);
        }
Пример #17
0
        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"]);
        }
Пример #18
0
        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);
        }