Exemple #1
0
        public void GivenANormalizerReceivingCustomOptionsThenReferencesAreTheSame()
        {
            var options    = new IniNormalizationOptions();
            var normalizer = new IniNormalizer(options);

            Assert.Same(options, normalizer.Options);
        }
        public void GivenASerializerReceivingCustomNormalizerThenDefaultOptionsAreUsed()
        {
            var normalizer = new IniNormalizer();
            var serializer = new IniSerializer(normalizer);

            Assert.Same(IniSerializationOptions.Default, serializer.Options);
            Assert.Same(normalizer, serializer.Normalizer);
        }
        public void GivenASerializerReceivingCustomParametersThenReferencesAreTheSame()
        {
            var options    = new IniSerializationOptions();
            var normalizer = new IniNormalizer();
            var serializer = new IniSerializer(options, normalizer);

            Assert.Same(options, serializer.Options);
            Assert.Same(normalizer, serializer.Normalizer);
        }
Exemple #4
0
        public void GivenANormalizerWithDefaultOptionsWhenTryedToNormalizeSectionCollectionThenDuplicatedMustFaild()
        {
            var normalizer = new IniNormalizer();

            var source      = SectionsWithDuplicatedCaseInsensitiveNames;
            var destination = new List <IniSection>();

            Assert.False(normalizer.TryNormalizeInto(source, destination));

            Assert.Equal(0, destination.Count);
        }
Exemple #5
0
        public void GivenANormalizerWithDefaultOptionsWhenNormalizedSectionThenNameMustBeUpperCase()
        {
            var normalizer = new IniNormalizer();

            var source = SectionForCaseSensitive;
            var result = normalizer.Normalize(source);

            Assert.NotNull(result);
            Assert.NotEqual(source.Name, result.Name);
            Assert.Equal(source.Name.ToUpperInvariant(), result.Name);
        }
Exemple #6
0
        public void GivenANormalizerWithDefaultOptionsWhenNormalizedSectionThenEmptyCommentsMustBeRemoved()
        {
            var normalizer = new IniNormalizer();

            var source = SectionForEmptyComments;
            var result = normalizer.Normalize(source);

            Assert.NotNull(result);
            Assert.NotEmpty(result.Comments);
            Assert.False(result.Comments.Any(string.IsNullOrWhiteSpace));
        }
        public void GivenANormalizerWithDefaultOptionsWhenNormalizedContainerThenEmptyGlobalPropertiesMustBeRemoved()
        {
            var normalizer = new IniNormalizer();

            var source = ContainerForEmptyProperties;
            var result = normalizer.Normalize(source);

            Assert.NotNull(result);
            Assert.NotEmpty(result.GlobalProperties);
            Assert.Equal(1, result.GlobalProperties.Count);
            Assert.False(result.GlobalProperties.Any(e => e.IsEmpty));
        }
        public void GivenANormalizerWithDefaultOptionsWhenNormalizedContainerThenEmptyGlobalCommentsMustBeRemoved()
        {
            var normalizer = new IniNormalizer();

            var source = ContainerForEmptyComments;
            var result = normalizer.Normalize(source);

            Assert.NotNull(result);
            Assert.NotEmpty(result.GlobalComments);
            Assert.Equal(1, result.GlobalComments.Count);
            Assert.False(result.GlobalComments.Any(string.IsNullOrWhiteSpace));
        }
Exemple #9
0
        public void GivenANormalizerWithDefaultOptionsWhenTryedToNormalizeSectionCollectionThenEmptyMustBeRemoved()
        {
            var normalizer = new IniNormalizer();

            var source      = SectionsWithEmptyContent;
            var destination = new List <IniSection>();

            Assert.True(normalizer.TryNormalizeInto(source, destination));

            Assert.NotEmpty(destination);
            Assert.False(destination.Any(e => e.IsEmpty));
        }
Exemple #10
0
        public void GivenANormalizerWithDefaultOptionsWhenNormalizedPropertyCollectionThenEmptyMustBeRemoved()
        {
            var normalizer = new IniNormalizer();

            var source      = PropertiesWithEmptyValues;
            var destination = new List <IniProperty>();

            normalizer.NormalizeInto(source, destination);

            Assert.NotEmpty(destination);
            Assert.False(destination.Any(e => e.IsEmpty));
        }
Exemple #11
0
        public void GivenANormalizerWithDefaultOptionsWhenTryedToNormalizeSectionThenEmptyCommentsMustBeRemoved()
        {
            var normalizer = new IniNormalizer();

            var        source = SectionForEmptyComments;
            IniSection result;

            Assert.True(normalizer.TryNormalize(source, out result));

            Assert.NotNull(result);
            Assert.NotEmpty(result.Comments);
            Assert.False(result.Comments.Any(string.IsNullOrWhiteSpace));
        }
Exemple #12
0
        public void GivenANormalizerCaseSensitiveWhenNormalizedSectionThenNameMustBeOriginal()
        {
            var normalizer = new IniNormalizer(new IniNormalizationOptions
            {
                IsCaseSensitive = true
            });

            var source = SectionForCaseSensitive;
            var result = normalizer.Normalize(source);

            Assert.NotNull(result);
            Assert.Equal(source.Name, result.Name);
        }
Exemple #13
0
        public void GivenANormalizerWithDefaultOptionsWhenTryedToNormalizeSectionThenNameMustBeUpperCase()
        {
            var normalizer = new IniNormalizer();

            var        source = SectionForCaseSensitive;
            IniSection result;

            Assert.True(normalizer.TryNormalize(source, out result));

            Assert.NotNull(result);
            Assert.NotEqual(source.Name, result.Name);
            Assert.Equal(source.Name.ToUpperInvariant(), result.Name);
        }
Exemple #14
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!!!
             */
        }
Exemple #15
0
        public void GivenANormalizerCaseSensitiveWhenNormalizedPropertyCollectionThenCaseSensitiveKeysWillPass()
        {
            var normalizer = new IniNormalizer(new IniNormalizationOptions
            {
                IsCaseSensitive = true
            });

            var source      = PropertiesWithDuplicatedCaseInsensitiveKeys;
            var destination = new List <IniProperty>();

            normalizer.NormalizeInto(source, destination);

            Assert.Equal(source.Length, destination.Count);
        }
Exemple #16
0
        public void GivenANormalizerMergingSectionsWhenTryedToNormalizeSectionCollectionThenDuplicatedWillPass()
        {
            var normalizer = new IniNormalizer(new IniNormalizationOptions
            {
                MergeOnDuplicatedSections = true
            });

            var source      = SectionsWithDuplicatedCaseInsensitiveNames;
            var destination = new List <IniSection>();

            Assert.True(normalizer.TryNormalizeInto(source, destination));

            Assert.Equal(1, destination.Count);
        }
Exemple #17
0
        public void GivenANormalizerIgnoringExceptionsWhenTryedToNormalizeSectionCollectionThenDuplicatedWillPass()
        {
            var normalizer = new IniNormalizer(new IniNormalizationOptions
            {
                ThrowExceptions = false
            });

            var source      = SectionsWithDuplicatedCaseInsensitiveNames;
            var destination = new List <IniSection>();

            Assert.False(normalizer.TryNormalizeInto(source, destination));

            Assert.Equal(0, destination.Count);
        }
Exemple #18
0
        public void GivenANormalizerCaseSensitiveWhenTryedToNormalizeSectionCollectionThenCaseSensitiveKeysWillPass()
        {
            var normalizer = new IniNormalizer(new IniNormalizationOptions
            {
                IsCaseSensitive = true
            });

            var source      = SectionsWithDuplicatedCaseInsensitiveNames;
            var destination = new List <IniSection>();

            Assert.True(normalizer.TryNormalizeInto(source, destination));

            Assert.Equal(source.Length, destination.Count);
        }
Exemple #19
0
        public void GivenANormalizerIgnoringExceptionsWhenTryedToNormalizePropertyCollectionThenDuplicatedWillPass()
        {
            var normalizer = new IniNormalizer(new IniNormalizationOptions
            {
                ThrowExceptions = false
            });

            var source      = PropertiesWithDuplicatedCaseInsensitiveKeys;
            var destination = new List <IniProperty>();

            Assert.True(normalizer.TryNormalizeInto(source, destination));

            Assert.Equal(source.Length / 2, destination.Count);
        }
Exemple #20
0
        public void GivenANormalizerWithDefaultOptionsWhenNormalizedSectionCollectionThenDuplicatedMustFaild()
        {
            var normalizer = new IniNormalizer();

            var source      = SectionsWithDuplicatedCaseInsensitiveNames;
            var destination = new List <IniSection>();

            var ex = Assert.Throws <DuplicatedSection>(() =>
            {
                normalizer.NormalizeInto(source, destination);
            });

            Assert.NotNull(ex.SectionName);
        }
Exemple #21
0
        public void GivenANormalizerCaseSensitiveWhenNormalizedSectionThenEmptyCommentsMustBeKept()
        {
            var normalizer = new IniNormalizer(new IniNormalizationOptions
            {
                IncludeEmptyComments = true
            });

            var source = SectionForEmptyComments;
            var result = normalizer.Normalize(source);

            Assert.NotNull(result);
            Assert.NotEmpty(result.Comments);
            Assert.True(result.Comments.Any(string.IsNullOrWhiteSpace));
        }
Exemple #22
0
        public void GivenANormalizerIncludingEmptyPropertiesWhenNormalizedPropertyCollectionThenEmptyMustBeKept()
        {
            var normalizer = new IniNormalizer(new IniNormalizationOptions
            {
                IncludeEmptyProperties = true
            });

            var source      = PropertiesWithEmptyValues;
            var destination = new List <IniProperty>();

            normalizer.NormalizeInto(source, destination);

            Assert.Equal(source.Length, destination.Count);
            Assert.True(destination.Any(e => e.IsEmpty));
        }
Exemple #23
0
        public void GivenANormalizerCaseSensitiveWhenTryedToNormalizeSectionThenNameMustBeOriginal()
        {
            var normalizer = new IniNormalizer(new IniNormalizationOptions
            {
                IsCaseSensitive = true
            });

            var        source = SectionForCaseSensitive;
            IniSection result;

            Assert.True(normalizer.TryNormalize(source, out result));

            Assert.NotNull(result);
            Assert.Equal(source.Name, result.Name);
        }
Exemple #24
0
        public void GivenANormalizerIncludingEmptyPropertiesWhenTryedToNormalizeSectionCollectionThenEmptyMustBeKept()
        {
            var normalizer = new IniNormalizer(new IniNormalizationOptions
            {
                IncludeEmptySections = true
            });

            var source      = SectionsWithEmptyContent;
            var destination = new List <IniSection>();

            Assert.True(normalizer.TryNormalizeInto(source, destination));

            Assert.Equal(source.Length, destination.Count);
            Assert.True(destination.Any(e => e.IsEmpty));
        }
        public void GivenANormalizerWithDefaultOptionsWhenNormalizedContainerThenEmptyGlobalCommentsMustBeKept()
        {
            var normalizer = new IniNormalizer(new IniNormalizationOptions
            {
                IncludeEmptyComments = true
            });

            var source = ContainerForEmptyComments;
            var result = normalizer.Normalize(source);

            Assert.NotNull(result);
            Assert.NotEmpty(result.GlobalComments);
            Assert.Equal(source.GlobalComments.Count, result.GlobalComments.Count);
            Assert.True(result.GlobalComments.Any(string.IsNullOrWhiteSpace));
        }
        public void GivenANormalizerWithDefaultOptionsWhenNormalizedContainerThenEmptyGlobalPropertiesMustBeKept()
        {
            var normalizer = new IniNormalizer(new IniNormalizationOptions
            {
                IncludeEmptyProperties = true
            });

            var source = ContainerForEmptyProperties;
            var result = normalizer.Normalize(source);

            Assert.NotNull(result);
            Assert.NotEmpty(result.GlobalProperties);
            Assert.Equal(source.GlobalProperties.Count, result.GlobalProperties.Count);
            Assert.True(result.GlobalProperties.Any(e => e.IsEmpty));
        }
Exemple #27
0
        public void GivenANormalizerWithDefaultConstructorThenDefaultsAreUsed()
        {
            var normalizer = new IniNormalizer();

            Assert.Same(IniNormalizationOptions.Default, normalizer.Options);
        }