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); }
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); }
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."); }
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>()); }
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"); }
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>()); }
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>()); }
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>()); }
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); }