public void BoolBinaryConverter_ShouldLoadBool(string readValue, bool expected)
        {
            var iniParser = Substitute.For <IIniParser>();

            iniParser.Read(Arg.Any <string>(), Arg.Any <string>()).Returns(readValue);

            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
                x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad;
            }, iniParser);

            var result = iniWrapper.LoadConfiguration <BoolBinaryConverterConfiguration>();

            result.TestBool.Should().Be(expected);
        }
示例#2
0
        public void EnumStringConverter_ShouldLoadEnumAsString()
        {
            var iniParser = Substitute.For <IIniParser>();

            iniParser.Read(Arg.Any <string>(), Arg.Any <string>()).Returns("Five");

            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
                x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad;
            }, iniParser);

            var result = iniWrapper.LoadConfiguration <IniConverterEnumStringConverterConfiguration>();

            result.TestEnum.Should().Be(TestEnum.Five);
        }
示例#3
0
        public void ShouldThrow_LoadConfiguration_WhenCustomConverter_DoesNotImplementIIniCustomConverterInterface()
        {
            var iniParser = Substitute.For <IIniParser>();

            iniParser.Read(Arg.Any <string>(), Arg.Any <string>()).Returns("dummy");

            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
                x.MissingFileWhenLoadingHandling =
                    MissingFileWhenLoadingHandling.ForceLoad;
            }, iniParser);

            Action result = () => iniWrapper.LoadConfiguration <CustomConverterWithoutInterface>();

            result.Should().Throw <InvalidCastException>().WithMessage($"Custom converter of type {typeof(ConverterWithoutInterface)} must implement IIniConverter interface.");
        }
示例#4
0
        public void LoadConfiguration_When_IgnoreCheckIsSet()
        {
            var iniParser = Substitute.For <IIniParser>();

            var inisettings = new IniSettings()
            {
                MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad
            };

            var iniWrapper = new IniWrapperFactory().Create(inisettings, iniParser);

            iniWrapper.LoadConfiguration <ImmutableConfiguration>();

            iniParser.Received(0).Write(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
            iniParser.Received(10).Read(Arg.Any <string>(), Arg.Any <string>());
        }
示例#5
0
        public void PropertyDecoratedWithIniConverterShouldInstantiateConverter_AndCallParseReadValue_WhenLoading()
        {
            var iniParser = Substitute.For <IIniParser>();

            iniParser.Read(Arg.Any <string>(), Arg.Any <string>()).Returns("dummy");

            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
                x.MissingFileWhenLoadingHandling =
                    MissingFileWhenLoadingHandling.ForceLoad;
            }, iniParser);

            Action result = () => iniWrapper.LoadConfiguration <IniConverterWithConstructorParameters>();

            result.Should().Throw <TestCustomIniHandlerException>().WithMessage("ParseReadValue");
        }
示例#6
0
        public void DoNotCallIniParser_When_DoNotLoadIsSet()
        {
            var iniParser = Substitute.For <IIniParser>();

            var inisettings = new IniSettings()
            {
                MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.DoNotLoad,
                IniFilePath = "dummyPath"
            };

            var iniWrapper = new IniWrapperFactory().Create(inisettings, iniParser);

            iniWrapper.LoadConfiguration <TestConfiguration>();

            iniParser.Received(0).Write(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
            iniParser.Received(0).Read(Arg.Any <string>(), Arg.Any <string>());
        }
示例#7
0
        public void SaveDefaultConfiguration_When_CreateWithDefaultValuesIsSet()
        {
            var iniParser = Substitute.For <IIniParser>();

            var inisettings = new IniSettings()
            {
                MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.CreateWithDefaultValues,
                IniFilePath = "dummyPath"
            };

            var iniWrapper = new IniWrapperFactory().Create(inisettings, iniParser);

            iniWrapper.LoadConfiguration <ImmutableConfiguration>();

            iniParser.Received(10).Write(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
            iniParser.Received(0).Read(Arg.Any <string>(), Arg.Any <string>());
        }
示例#8
0
        public void LoadConfiguration_When_IgnoreCheckIsSet()
        {
            var iniParser = Substitute.For <IIniParser>();

            var inisettings = new IniSettings()
            {
                MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad
            };

            var iniWrapper = new IniWrapperFactory().Create(inisettings, iniParser);

            iniWrapper.LoadConfiguration <TestConfiguration>();

            iniParser.Received(0).Write(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
            var properties = typeof(TestConfiguration).GetProperties().Length;

            iniParser.Received(properties).Read(Arg.Any <string>(), Arg.Any <string>());
        }
示例#9
0
        public void ShouldThrow_LoadConfiguration_WhenCustomConverter_DoesNotHaveParameterlessConstructor_And_ConverterParametersWereNotPassed()
        {
            var iniParser = Substitute.For <IIniParser>();

            iniParser.Read(Arg.Any <string>(), Arg.Any <string>()).Returns("dummy");

            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
                x.MissingFileWhenLoadingHandling =
                    MissingFileWhenLoadingHandling.ForceLoad;
            }, iniParser);

            Action result = () => iniWrapper.LoadConfiguration <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 })])");
        }
        public void SettingsEnumerableEntitySeparator_ShouldDetermineEntitySeparatorWhenLoading(char separator)
        {
            var iniParser  = Substitute.For <IIniParser>();
            var iniWrapper = new IniWrapperFactory().Create(x =>
            {
                x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad;
                x.EnumerableEntitySeparator      = separator;
            }, iniParser);

            iniParser.Read(nameof(TestConfiguration), nameof(TestConfiguration.TestStringList)).Returns($"a{separator}b{separator}c{separator}d{separator}f");

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

            var result = iniWrapper.LoadConfiguration <TestConfiguration>();

            result.TestStringList.Should().BeEquivalentTo(expected);
        }