Ejemplo n.º 1
0
        public ReadToOneBufferBenchmark()
        {
            if (Directory.Exists(TestDirectory))
            {
                Directory.Delete(TestDirectory, true);
            }

            Directory.CreateDirectory(TestDirectory);
            var fixture       = new Fixture();
            var customization = new SupportMutableValueTypesCustomization();

            var newParser = $"{TestDirectory}newParser";
            var oldParser = $"{TestDirectory}oldParser";

            customization.Customize(fixture);
            _iniParser    = new IniWrapper.ParserWrapper.IniParser(newParser, 1024);
            _oldIniParser = new OldParserWrapper.IniParser(oldParser, 1024);

            var configuration = fixture.Create <OldParserWrapper.Configuration>();

            var iniWrapper = new IniWrapperFactory().CreateWithDefaultIniParser(x =>
            {
                x.IniFilePath = newParser;
            });

            var oldIni = new IniWrapperFactory().CreateWithDefaultIniParser(x =>
            {
                x.IniFilePath = oldParser;
            });

            iniWrapper.SaveConfiguration(configuration);
            oldIni.SaveConfiguration(configuration);
        }
Ejemplo n.º 2
0
        public void ShouldThrow_SaveConfiguration_WhenCustomConverter_DoesNotImplementIIniCustomConverterInterface()
        {
            var iniParser  = Substitute.For <IIniParser>();
            var iniWrapper = new IniWrapperFactory().Create(x => { }, iniParser);

            Action result = () => iniWrapper.SaveConfiguration(new CustomConverterWithoutInterface());

            result.Should().Throw <InvalidCastException>()
            .WithMessage($"Custom converter of type {typeof(ConverterWithoutInterface)} must implement IIniConverter interface.");
        }
Ejemplo n.º 3
0
        public void PropertyDecoratedWithIniConverter_ShouldInstantiateConverter_AndCallFormatToWrite_WhenSaving()
        {
            var iniParser  = Substitute.For <IIniParser>();
            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
            }, iniParser);

            Action result = () => iniWrapper.SaveConfiguration(new IniConverterWithConstructorParameters());

            result.Should().Throw <TestCustomIniHandlerException>().WithMessage("FormatToWrite");
        }
Ejemplo n.º 4
0
        public void ShouldThrow_SaveConfiguration_WhenCustomConverter_DoesNotHaveParameterlessConstructor_And_ConverterParametersWereNotPassed()
        {
            var iniParser  = Substitute.For <IIniParser>();
            var iniWrapper = new IniWrapperFactory().Create(iniParser);

            Action result = () => iniWrapper.SaveConfiguration(new IniConverterWithConstructorParametersNotSpecified());

            result.Should().Throw <MissingMethodException>().WithMessage($"Please provide parameterless constructor for custom converter of type {typeof(CustomIniConverterWithConstructor)} " +
                                                                         "or pass arguments via converterParameters." +
                                                                         " (e.g. [IniConverter(typeof(CustomIniConverterWithConstructor), new object[] { \"Argument\", 10 })])");
        }
Ejemplo n.º 5
0
        public void SettingsNullValueHandling_Ignore_ShouldNotSaveNullValues()
        {
            var iniParser  = Substitute.For <IIniParser>();
            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
                x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad;
                x.NullValueHandling = NullValueHandling.Ignore;
            }, iniParser);

            var config = new TestConfiguration();

            iniWrapper.SaveConfiguration(config);

            iniParser.Received(5).Write(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
        }
Ejemplo n.º 6
0
        public void SettingsNullValueHandling_ReplaceWithEmptyString_ShouldSaveDefaultValues_ForComplexType()
        {
            var iniParser  = Substitute.For <IIniParser>();
            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
                x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad;
                x.NullValueHandling = NullValueHandling.ReplaceWithEmptyString;
            }, iniParser);

            var config = new ComplexNullConfiguration();

            iniWrapper.SaveConfiguration(config);

            iniParser.Received(4).Write(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
        }
Ejemplo n.º 7
0
        public void BoolBinaryConverter_ShouldSaveBool(string expected, bool value)
        {
            var iniParser  = Substitute.For <IIniParser>();
            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
            }, iniParser);

            var config = new BoolBinaryConverterConfiguration()
            {
                TestBool = value
            };

            iniWrapper.SaveConfiguration(config);

            iniParser.Received(1).Write(nameof(BoolBinaryConverterConfiguration), nameof(BoolBinaryConverterConfiguration.TestBool), expected);
        }
Ejemplo n.º 8
0
        public void EnumStringConverter_ShouldWriteEnumAsString()
        {
            var iniParser  = Substitute.For <IIniParser>();
            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
            }, iniParser);

            var config = new IniConverterEnumStringConverterConfiguration()
            {
                TestEnum = TestEnum.Five
            };

            iniWrapper.SaveConfiguration(config);

            iniParser.Received(1).Write(nameof(IniConverterEnumStringConverterConfiguration), nameof(IniConverterEnumStringConverterConfiguration.TestEnum), "Five");
        }
Ejemplo n.º 9
0
        public void SettingsNullValueHandling_ReplaceWithEmptyString_ShouldSaveDefaultValues()
        {
            var iniParser  = Substitute.For <IIniParser>();
            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
                x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad;
                x.NullValueHandling = NullValueHandling.ReplaceWithEmptyString;
            }, iniParser);

            var config = new TestConfiguration();

            iniWrapper.SaveConfiguration(config);

            var properties = typeof(TestConfiguration).GetProperties().Length;

            iniParser.Received(properties).Write(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
        }
        public void SettingsEnumerableEntitySeparator_ShouldDetermineEntitySeparatorWhenSaving(char separator)
        {
            var iniParser  = Substitute.For <IIniParser>();
            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
                x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad;
                x.EnumerableEntitySeparator      = separator;
            }, iniParser);

            var config = new TestConfiguration()
            {
                TestStringList = new List <string>()
                {
                    "a", "b", "c", "d", "f"
                },
            };

            iniWrapper.SaveConfiguration(config);

            iniParser.Received(1).Write(nameof(TestConfiguration), nameof(TestConfiguration.TestStringList), $"a{separator}b{separator}c{separator}d{separator}f");
        }