diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index b49e788..1af97dd 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -10,12 +10,13 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: 1. Add code that you are using ( configuration class, invoking and creating IniWrapper) +2. If possible please add ini file if you are loading configuration **Expected behavior** A clear and concise description of what you expected to happen. **Desktop (please complete the following information):** - - Version [e.g. 22] + - Version [e.g. 1.0.0] **Additional context** Add any other context about the problem here. diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Configuration/Properties/ComplexNullConfiguration.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Configuration/Properties/ComplexNullConfiguration.cs new file mode 100644 index 0000000..f571c4d --- /dev/null +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Configuration/Properties/ComplexNullConfiguration.cs @@ -0,0 +1,7 @@ +namespace IniWrapper.IntegrationTests.Main.Configuration.Properties +{ + public class ComplexNullConfiguration + { + public NullableConfiguration NullableConfiguration { get; set; } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Configuration/Properties/DefaultValuesConfiguration.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Configuration/Properties/DefaultValuesConfiguration.cs new file mode 100644 index 0000000..7f02bae --- /dev/null +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Configuration/Properties/DefaultValuesConfiguration.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace IniWrapper.IntegrationTests.Main.Configuration.Properties +{ + public static class DefaultValuesConfigurationConsts + { + public const int DefaultInt = 100; + public const string DefaultString = "StringDefault"; + public const string DefaultList = "10,11,12,13"; + } + public class DefaultValuesConfiguration + { + public int DefaultInt { get; set; } = DefaultValuesConfigurationConsts.DefaultInt; + public string DefaultString { get; set; } = DefaultValuesConfigurationConsts.DefaultString; + public List DefaultList { get; set; } = new List() { 10, 11, 12, 13 }; + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Configuration/Properties/TwoDepthNullComplexConfiguration.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Configuration/Properties/TwoDepthNullComplexConfiguration.cs new file mode 100644 index 0000000..b9b31e9 --- /dev/null +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Configuration/Properties/TwoDepthNullComplexConfiguration.cs @@ -0,0 +1,7 @@ +namespace IniWrapper.IntegrationTests.Main.Configuration.Properties +{ + public class TwoDepthNullComplexConfiguration + { + public ComplexNullConfiguration ComplexTestConfiguration { get; set; } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/Ignore/IniIgnoreReadAttributeTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/Ignore/IniIgnoreReadAttributeTests.cs index 373dffc..8df6adb 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/Ignore/IniIgnoreReadAttributeTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/Ignore/IniIgnoreReadAttributeTests.cs @@ -20,7 +20,7 @@ public class IniIgnoreReadAttributeTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/IniOptionsAttributeReadTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/IniOptionsAttributeReadTests.cs index 3314095..a1a4a70 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/IniOptionsAttributeReadTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/IniOptionsAttributeReadTests.cs @@ -21,7 +21,7 @@ public class IniOptionsAttributeReadTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/IniOptionsOnlyKeyAttributeReadTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/IniOptionsOnlyKeyAttributeReadTests.cs index 53136a4..cafa6c6 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/IniOptionsOnlyKeyAttributeReadTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/IniOptionsOnlyKeyAttributeReadTests.cs @@ -21,7 +21,7 @@ public class IniOptionsOnlyKeyAttributeReadTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/IniOptionsOnlySectionAttributeReadTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/IniOptionsOnlySectionAttributeReadTests.cs index 3d087f0..c0c90f1 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/IniOptionsOnlySectionAttributeReadTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Attribute/IniOptionsOnlySectionAttributeReadTests.cs @@ -22,7 +22,7 @@ public class IniOptionsOnlySectionAttributeReadTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperComplexDataSaveFieldsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperComplexDataSaveFieldsTests.cs index d1b5f33..38f6b03 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperComplexDataSaveFieldsTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperComplexDataSaveFieldsTests.cs @@ -10,7 +10,7 @@ namespace IniWrapper.IntegrationTests.Main.Read.Fields { [TestFixture] - public class IniParserComplexDataSavePropertiesTests + public class IniWrapperComplexDataSavePropertiesTests { private IIniWrapper _iniWrapper; @@ -20,7 +20,7 @@ public class IniParserComplexDataSavePropertiesTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperIEnumerableOfComplexDataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperIEnumerableOfComplexDataTests.cs index 33fb4f2..3efad31 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperIEnumerableOfComplexDataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperIEnumerableOfComplexDataTests.cs @@ -11,7 +11,7 @@ namespace IniWrapper.IntegrationTests.Main.Read.Fields { [TestFixture] - public class IniParserIEnumerableOfComplexDataTests + public class IniWrapperIEnumerableOfComplexDataTests { private IIniWrapper _iniWrapper; @@ -21,7 +21,7 @@ public class IniParserIEnumerableOfComplexDataTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] @@ -29,7 +29,7 @@ public void SaveConfiguration_ShouldThrowException_WhenConfigurationHasCollectio { Action loadConfiguration = () => _iniWrapper.LoadConfiguration(); - loadConfiguration.Should().Throw(); + loadConfiguration.Should().Throw(); } } } \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperReadFieldsConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperReadFieldsConfigurationTests.cs index 3e93a55..a1d3174 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperReadFieldsConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperReadFieldsConfigurationTests.cs @@ -11,7 +11,7 @@ namespace IniWrapper.IntegrationTests.Main.Read.Fields { [TestFixture] - public sealed class IniParserReadFieldsConfigurationTests + public sealed class IniWrapperReadFieldsConfigurationTests { private IIniWrapper _iniWrapper; @@ -21,7 +21,7 @@ public sealed class IniParserReadFieldsConfigurationTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperComplexDataReadPropertiesTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperComplexDataReadPropertiesTests.cs index ec17cc2..bc5df3e 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperComplexDataReadPropertiesTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperComplexDataReadPropertiesTests.cs @@ -10,7 +10,7 @@ namespace IniWrapper.IntegrationTests.Main.Read.Properties { [TestFixture] - public class IniParserComplexDataReadPropertiesTests + public class IniWrapperComplexDataReadPropertiesTests { private IIniWrapper _iniWrapper; @@ -20,7 +20,7 @@ public class IniParserComplexDataReadPropertiesTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableNullableTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableNullableTests.cs index d23124a..5aeed56 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableNullableTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableNullableTests.cs @@ -10,7 +10,7 @@ namespace IniWrapper.IntegrationTests.Main.Read.Properties { [TestFixture] - public class IniParserIEnumerableNullableTests + public class IniWrapperIEnumerableNullableTests { private IIniWrapper _iniWrapper; @@ -20,7 +20,7 @@ public class IniParserIEnumerableNullableTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableReadingOfComplexDataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableReadingOfComplexDataTests.cs index 823522b..6f7e60e 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableReadingOfComplexDataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableReadingOfComplexDataTests.cs @@ -11,7 +11,7 @@ namespace IniWrapper.IntegrationTests.Main.Read.Properties { [TestFixture] - public class IniParserIEnumerableReadingOfComplexDataTests + public class IniWrapperIEnumerableReadingOfComplexDataTests { private IIniWrapper _iniWrapper; @@ -21,7 +21,7 @@ public class IniParserIEnumerableReadingOfComplexDataTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] @@ -29,7 +29,7 @@ public void LoadConfiguration_ShouldThrowException_WhenConfigurationHasCollectio { Action loadConfiguration = () => _iniWrapper.LoadConfiguration(); - loadConfiguration.Should().Throw(); + loadConfiguration.Should().Throw(); } } } \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDefaultValuesTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDefaultValuesTests.cs new file mode 100644 index 0000000..cb99cdf --- /dev/null +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDefaultValuesTests.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using FluentAssertions; +using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; +using IniWrapper.ParserWrapper; +using IniWrapper.Wrapper; +using NSubstitute; +using NUnit.Framework; + +namespace IniWrapper.IntegrationTests.Main.Read.Properties +{ + [TestFixture] + public class IniWrapperReadDefaultValuesTests + { + private IIniWrapper _iniWrapper; + + private IIniParser _iniParser; + + [SetUp] + public void SetUp() + { + _iniParser = Substitute.For(); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); + } + + [Test] + public void SaveConfiguration_ShouldSaveCorrectDefaultValues() + { + var result = _iniWrapper.LoadConfiguration(); + + result.DefaultInt.Should().Be(DefaultValuesConfigurationConsts.DefaultInt); + result.DefaultString.Should().Be(DefaultValuesConfigurationConsts.DefaultString); + result.DefaultList.Should().BeEquivalentTo(new List { 10, 11, 12, 13 }); + } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDictionaryTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDictionaryTests.cs index 2d5394e..1016be5 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDictionaryTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDictionaryTests.cs @@ -10,7 +10,7 @@ namespace IniWrapper.IntegrationTests.Main.Read.Properties { [TestFixture] - public class IniParserReadDictionaryTests + public class IniWrapperReadDictionaryTests { private IIniWrapper _iniWrapper; @@ -20,7 +20,7 @@ public class IniParserReadDictionaryTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadPropertiesConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadPropertiesConfigurationTests.cs index a08027b..67ea381 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadPropertiesConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadPropertiesConfigurationTests.cs @@ -10,7 +10,7 @@ namespace IniWrapper.IntegrationTests.Main.Read.Properties { [TestFixture] - public class IniParserReadPropertiesConfigurationTests + public class IniWrapperReadPropertiesConfigurationTests { private IIniWrapper _iniWrapper; @@ -20,7 +20,7 @@ public class IniParserReadPropertiesConfigurationTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingEnumOutOfRangeTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingEnumOutOfRangeTests.cs new file mode 100644 index 0000000..a7dede1 --- /dev/null +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingEnumOutOfRangeTests.cs @@ -0,0 +1,35 @@ +using FluentAssertions; +using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; +using IniWrapper.ParserWrapper; +using IniWrapper.Wrapper; +using NSubstitute; +using NUnit.Framework; + +namespace IniWrapper.IntegrationTests.Main.Read.WrongFormat +{ + [TestFixture] + public class ReadingEnumOutOfRangeTests + { + private IIniWrapper _iniWrapper; + + private IIniParser _iniParser; + + [SetUp] + public void SetUp() + { + _iniParser = Substitute.For(); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); + } + + [Test] + public void LoadConfiguration_CorrectEnumOutOfRange() + { + _iniParser.Read(nameof(TestConfiguration), nameof(TestConfiguration.TestEnum)).Returns("1000"); + + var result = _iniWrapper.LoadConfiguration(); + + result.TestEnum.Should().Be((TestEnum)1000); + } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingWrongFormattedIni.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingWrongFormattedIniTests.cs similarity index 88% rename from IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingWrongFormattedIni.cs rename to IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingWrongFormattedIniTests.cs index 55872fa..2c5126a 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingWrongFormattedIni.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingWrongFormattedIniTests.cs @@ -10,7 +10,7 @@ namespace IniWrapper.IntegrationTests.Main.Read.WrongFormat { - public class ReadingWrongFormattedIni + public class ReadingWrongFormattedIniTests { private IIniWrapper _iniWrapper; @@ -20,7 +20,7 @@ public class ReadingWrongFormattedIni public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/Ignore/IniIgnoreAttributeTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/Ignore/IniIgnoreAttributeTests.cs index 1064a1e..011810e 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/Ignore/IniIgnoreAttributeTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/Ignore/IniIgnoreAttributeTests.cs @@ -1,4 +1,5 @@ using IniWrapper.IntegrationTests.Main.Configuration.Attribute.Ignore; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -17,7 +18,7 @@ public class IniIgnoreAttributeTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/IniOptionsAttributeTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/IniOptionsAttributeTests.cs index d7bb74b..739078b 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/IniOptionsAttributeTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/IniOptionsAttributeTests.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using IniWrapper.IntegrationTests.Main.Configuration.Attribute.Save; using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -19,7 +20,7 @@ public class IniOptionsAttributeTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/IniOptionsOnlyKeyAttributeTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/IniOptionsOnlyKeyAttributeTests.cs index c6a5ba6..5aee28c 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/IniOptionsOnlyKeyAttributeTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/IniOptionsOnlyKeyAttributeTests.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using IniWrapper.IntegrationTests.Main.Configuration.Attribute.Save; using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -19,7 +20,7 @@ public class IniOptionsOnlyKeyAttributeTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/IniOptionsOnlySectionAttributeTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/IniOptionsOnlySectionAttributeTests.cs index e2ea477..8332067 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/IniOptionsOnlySectionAttributeTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Attribute/IniOptionsOnlySectionAttributeTests.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using IniWrapper.IntegrationTests.Main.Configuration.Attribute.Save; using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -19,7 +20,7 @@ public class IniOptionsOnlySectionAttributeTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperComplexDataSaveFieldsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperComplexDataSaveFieldsTests.cs index 056c7a0..0597242 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperComplexDataSaveFieldsTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperComplexDataSaveFieldsTests.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using IniWrapper.IntegrationTests.Main.Configuration.Fields; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -8,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Fields { [TestFixture] - public class IniParserComplexDataSavePropertiesTests + public class IniWrapperComplexDataSavePropertiesTests { private IIniWrapper _iniWrapper; @@ -18,7 +19,7 @@ public class IniParserComplexDataSavePropertiesTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperIEnumerableOfComplexDataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperIEnumerableOfComplexDataTests.cs index 46ae4f5..6c0ec5e 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperIEnumerableOfComplexDataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperIEnumerableOfComplexDataTests.cs @@ -2,6 +2,7 @@ using FluentAssertions; using IniWrapper.Exceptions; using IniWrapper.IntegrationTests.Main.Configuration.Fields; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -10,7 +11,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Fields { [TestFixture] - public class IniParserIEnumerableOfComplexDataTests + public class IniWrapperIEnumerableOfComplexDataTests { private IIniWrapper _iniWrapper; @@ -20,7 +21,7 @@ public class IniParserIEnumerableOfComplexDataTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] @@ -30,7 +31,7 @@ public void SaveConfiguration_ShouldThrowException_WhenConfigurationHasCollectio Action saveConfiguration = () => _iniWrapper.SaveConfiguration(config); - saveConfiguration.Should().Throw(); + saveConfiguration.Should().Throw(); } } } \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveDictionaryConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveDictionaryConfigurationTests.cs index 4a37a8b..a695461 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveDictionaryConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveDictionaryConfigurationTests.cs @@ -11,7 +11,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Fields { [TestFixture] - public class IniParserSaveDictionaryConfigurationTests + public class IniWrapperSaveDictionaryConfigurationTests { private IIniWrapper _iniWrapper; @@ -21,7 +21,7 @@ public class IniParserSaveDictionaryConfigurationTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveFieldsConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveFieldsConfigurationTests.cs index 6c0f7de..0791f6e 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveFieldsConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveFieldsConfigurationTests.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using IniWrapper.IntegrationTests.Main.Configuration.Fields; using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -9,7 +10,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Fields { [TestFixture] - public sealed class IniParserSaveFieldsConfigurationTests + public sealed class IniWrapperSaveFieldsConfigurationTests { private IIniWrapper _iniWrapper; @@ -19,7 +20,7 @@ public sealed class IniParserSaveFieldsConfigurationTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveNullableFieldsConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveNullableFieldsConfigurationTests.cs index 95f5290..4e8fae0 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveNullableFieldsConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveNullableFieldsConfigurationTests.cs @@ -1,5 +1,6 @@ using IniWrapper.IntegrationTests.Main.Configuration.Fields; using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -8,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Fields { [TestFixture] - public class IniParserSaveNullableFieldsConfigurationTests + public class IniWrapperSaveNullableFieldsConfigurationTests { private IIniWrapper _iniWrapper; @@ -18,7 +19,7 @@ public class IniParserSaveNullableFieldsConfigurationTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperComplexDataSavePropertiesTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperComplexDataSavePropertiesTests.cs index 89d8574..73cdc99 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperComplexDataSavePropertiesTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperComplexDataSavePropertiesTests.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -8,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public class IniParserComplexDataSavePropertiesTests + public class IniWrapperComplexDataSavePropertiesTests { private IIniWrapper _iniWrapper; @@ -18,7 +19,7 @@ public class IniParserComplexDataSavePropertiesTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] @@ -45,5 +46,36 @@ public void SaveConfiguration_ShouldSaveCorrectComplexType() _iniParser.Received(1).Write(nameof(TestConfiguration), nameof(TestConfiguration.TestUint), config.TestConfiguration.TestUint.ToString()); _iniParser.Received(1).Write(nameof(TestConfiguration), nameof(TestConfiguration.TestUintList), "1,2,3,4"); } + + [Test] + public void SaveConfiguration_ShouldReplaceAllNullValuesWithEmptyStringForComplexType() + { + var config = new ComplexNullConfiguration() + { + NullableConfiguration = null + }; + + _iniWrapper.SaveConfiguration(config); + + _iniParser.Received(1).Write(nameof(NullableConfiguration), nameof(NullableConfiguration.TestNullableInt), string.Empty); + _iniParser.Received(1).Write(nameof(NullableConfiguration), nameof(NullableConfiguration.TestNullableEnum), string.Empty); + _iniParser.Received(1).Write(nameof(NullableConfiguration), nameof(NullableConfiguration.TestNullableUint), string.Empty); + _iniParser.Received(1).Write(nameof(NullableConfiguration), nameof(NullableConfiguration.TestNullableChar), string.Empty); + } + [Test] + public void SaveConfiguration_ShouldReplaceAllNullValuesWithEmptyStringForTwoDepthComplexType() + { + var config = new TwoDepthNullComplexConfiguration() + { + ComplexTestConfiguration = null + }; + + _iniWrapper.SaveConfiguration(config); + + _iniParser.Received(1).Write(nameof(NullableConfiguration), nameof(NullableConfiguration.TestNullableInt), string.Empty); + _iniParser.Received(1).Write(nameof(NullableConfiguration), nameof(NullableConfiguration.TestNullableEnum), string.Empty); + _iniParser.Received(1).Write(nameof(NullableConfiguration), nameof(NullableConfiguration.TestNullableUint), string.Empty); + _iniParser.Received(1).Write(nameof(NullableConfiguration), nameof(NullableConfiguration.TestNullableChar), string.Empty); + } } } \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperDictionaryWithNullsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperDictionaryWithNullsTests.cs index b165856..208cf75 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperDictionaryWithNullsTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperDictionaryWithNullsTests.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -8,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public class IniParserDictionaryWithNullsTests + public class IniWrapperDictionaryWithNullsTests { private IIniWrapper _iniWrapper; @@ -18,7 +19,7 @@ public class IniParserDictionaryWithNullsTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] public void SaveConfiguration_ShouldIgnoreNullsForStringValues() diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableOfComplexDataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableOfComplexDataTests.cs index 5828f7c..e670932 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableOfComplexDataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableOfComplexDataTests.cs @@ -2,6 +2,7 @@ using FluentAssertions; using IniWrapper.Exceptions; using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -10,7 +11,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public class IniParserIEnumerableOfComplexDataTests + public class IniWrapperIEnumerableOfComplexDataTests { private IIniWrapper _iniWrapper; @@ -20,7 +21,7 @@ public class IniParserIEnumerableOfComplexDataTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] @@ -30,7 +31,7 @@ public void SaveConfiguration_ShouldThrowException_WhenConfigurationHasCollectio Action saveConfiguration = () => _iniWrapper.SaveConfiguration(config); - saveConfiguration.Should().Throw(); + saveConfiguration.Should().Throw(); } } } \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableWithNullsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableWithNullsTests.cs index c1cd857..d69cf3c 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableWithNullsTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableWithNullsTests.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -8,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public class IniParserIEnumerableWithNullsTests + public class IniWrapperIEnumerableWithNullsTests { private IIniWrapper _iniWrapper; @@ -18,7 +19,7 @@ public class IniParserIEnumerableWithNullsTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDefaultValuesTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDefaultValuesTests.cs new file mode 100644 index 0000000..624b092 --- /dev/null +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDefaultValuesTests.cs @@ -0,0 +1,34 @@ +using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; +using IniWrapper.ParserWrapper; +using IniWrapper.Wrapper; +using NSubstitute; +using NUnit.Framework; + +namespace IniWrapper.IntegrationTests.Main.Save.Properties +{ + [TestFixture] + public class IniWrapperSaveDefaultValuesTests + { + private IIniWrapper _iniWrapper; + + private IIniParser _iniParser; + + [SetUp] + public void SetUp() + { + _iniParser = Substitute.For(); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); + } + + [Test] + public void SaveConfiguration_ShouldSaveCorrectDefaultValues() + { + _iniWrapper.SaveConfiguration(new DefaultValuesConfiguration()); + + _iniParser.Received(1).Write(nameof(DefaultValuesConfiguration), nameof(DefaultValuesConfiguration.DefaultInt), DefaultValuesConfigurationConsts.DefaultInt.ToString()); + _iniParser.Received(1).Write(nameof(DefaultValuesConfiguration), nameof(DefaultValuesConfiguration.DefaultString), DefaultValuesConfigurationConsts.DefaultString); + _iniParser.Received(1).Write(nameof(DefaultValuesConfiguration), nameof(DefaultValuesConfiguration.DefaultList), DefaultValuesConfigurationConsts.DefaultList); + } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryConfigurationTests.cs index ea3a35d..99cf896 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryConfigurationTests.cs @@ -11,7 +11,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public class IniParserSaveDictionaryConfigurationTests + public class IniWrapperSaveDictionaryConfigurationTests { private IIniWrapper _iniWrapper; @@ -21,7 +21,7 @@ public class IniParserSaveDictionaryConfigurationTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryOfComplexdataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryOfComplexdataTests.cs index ef1c9a6..54d7284 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryOfComplexdataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryOfComplexdataTests.cs @@ -12,7 +12,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public class IniParserSaveDictionaryOfComplexdataTests + public class IniWrapperSaveDictionaryOfComplexdataTests { private IIniWrapper _iniWrapper; @@ -22,7 +22,7 @@ public class IniParserSaveDictionaryOfComplexdataTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] @@ -32,7 +32,7 @@ public void SaveConfiguration_ShouldThrowException_WhenKeyInDictionaryConfigurat Action saveConfiguration = () => _iniWrapper.SaveConfiguration(config); - saveConfiguration.Should().Throw(); + saveConfiguration.Should().Throw(); } [Test] @@ -42,7 +42,7 @@ public void SaveConfiguration_ShouldThrowException_WhenValueInDictionaryConfigur Action saveConfiguration = () => _iniWrapper.SaveConfiguration(config); - saveConfiguration.Should().Throw(); + saveConfiguration.Should().Throw(); } } diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveNullablePropertiesConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveNullablePropertiesConfigurationTests.cs index 4f87eb5..ccf08ca 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveNullablePropertiesConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveNullablePropertiesConfigurationTests.cs @@ -1,5 +1,6 @@ using System; using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -8,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public class IniParserSaveNullableFieldsConfigurationTests + public class IniWrapperSaveNullableFieldsConfigurationTests { private IIniWrapper _iniWrapper; @@ -18,7 +19,7 @@ public class IniParserSaveNullableFieldsConfigurationTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSavePropertiesConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSavePropertiesConfigurationTests.cs index a4d969e..43877fd 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSavePropertiesConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSavePropertiesConfigurationTests.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -8,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public sealed class IniParserSavePropertiesConfigurationTests + public sealed class IniWrapperSavePropertiesConfigurationTests { private IIniWrapper _iniWrapper; @@ -18,7 +19,7 @@ public sealed class IniParserSavePropertiesConfigurationTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = new IniWrapperFactory().Create("", _iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/MockParser/MockParserFactory.cs b/IniWrapper/IniWrapper.IntegrationTests/MockParser/MockWrapperFactory.cs similarity index 50% rename from IniWrapper/IniWrapper.IntegrationTests/MockParser/MockParserFactory.cs rename to IniWrapper/IniWrapper.IntegrationTests/MockParser/MockWrapperFactory.cs index 9807d9e..357394a 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/MockParser/MockParserFactory.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/MockParser/MockWrapperFactory.cs @@ -1,4 +1,5 @@ using System.IO.Abstractions; +using IniWrapper.ConfigLoadingChecker; using IniWrapper.HandlersFactory; using IniWrapper.Manager; using IniWrapper.Manager.Attribute; @@ -7,13 +8,14 @@ using IniWrapper.Manager.Save; using IniWrapper.Manager.Save.Strategy.Factory; using IniWrapper.ParserWrapper; +using IniWrapper.Settings; using IniWrapper.Utils; using IniWrapper.Wrapper; using NSubstitute; namespace IniWrapper.IntegrationTests.MockParser { - public static class MockParserFactory + public static class MockWrapperFactory { public static IIniWrapper CreateWithFileSystem(IIniParser iniParser) { @@ -22,15 +24,22 @@ public static IIniWrapper CreateWithFileSystem(IIniParser iniParser) fileSystem.File.Exists(Arg.Any()).Returns(true); return Create(iniParser, fileSystem); } + public static IIniWrapper Create(IIniParser iniParser, IFileSystem fileSystem) { + return Create(new IniSettings(), iniParser, fileSystem); + } + public static IIniWrapper Create(IniSettings iniSettings, IIniParser iniParser, IFileSystem fileSystem) + { + var handlerFactory = new HandlerFactory(new TypeManager(), iniSettings); - var handlerFactory = new HandlerFactory(new TypeManager()); + var savingManager = new SavingManager(new IniValueManager(new IniValueAttributeManager()), + new SavingStrategyFactory(handlerFactory, iniParser)); + var readingManager = new ReadingManager(new IniValueManager(new IniValueAttributeManager()), handlerFactory, + new ReadingStrategyFactory(iniParser)); + var defaultConfigurationCreationStrategy = new ConfigurationLoadingChecker(fileSystem, iniSettings); - var iniWrapper = new Wrapper.IniWrapper("dummy", - fileSystem, - new SavingManager(new IniValueManager(new IniValueAttributeManager()), new SavingStrategyFactory(handlerFactory, iniParser)), - new ReadingManager(new IniValueManager(new IniValueAttributeManager()), handlerFactory, new ReadingStrategyFactory(iniParser))); + var iniWrapper = new Wrapper.IniWrapper(savingManager, readingManager, defaultConfigurationCreationStrategy); handlerFactory.IniWrapper = iniWrapper; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparatorSettingsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparatorSettingsTests.cs new file mode 100644 index 0000000..0c90154 --- /dev/null +++ b/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparatorSettingsTests.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using FluentAssertions; +using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.ParserWrapper; +using IniWrapper.Settings; +using IniWrapper.Wrapper; +using NSubstitute; +using NUnit.Framework; + +namespace IniWrapper.IntegrationTests.Settings +{ + [TestFixture] + public class EnumerableSeparatorSettingsTests + { + [TestCase('|')] + [TestCase('*')] + public void SettingsEnumerableEntitySeparator_ShouldDetermineEntitySeparatorWhenSaving(char separator) + { + var iniParser = Substitute.For(); + var iniWrapper = new IniWrapperFactory().Create(x => + { + x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad; + x.EnumerableEntitySeparator = separator; + }, iniParser); + + var config = new TestConfiguration() + { + TestStringList = new List() + { + "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"); + } + + [TestCase('|')] + [TestCase('*')] + public void SettingsEnumerableEntitySeparator_ShouldDetermineEntitySeparatorWhenLoading(char separator) + { + var iniParser = Substitute.For(); + 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() { "a", "b", "c", "d", "f" }; + + var result = iniWrapper.LoadConfiguration(); + + result.TestStringList.Should().BeEquivalentTo(expected); + } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Settings/MissingFileSettingsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Settings/MissingFileSettingsTests.cs new file mode 100644 index 0000000..ea14a39 --- /dev/null +++ b/IniWrapper/IniWrapper.IntegrationTests/Settings/MissingFileSettingsTests.cs @@ -0,0 +1,154 @@ +using System; +using System.Collections.Generic; +using System.IO.Abstractions; +using FluentAssertions; +using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; +using IniWrapper.ParserWrapper; +using IniWrapper.Settings; +using IniWrapper.Wrapper; +using NSubstitute; +using NUnit.Framework; + +namespace IniWrapper.IntegrationTests.Settings +{ + [TestFixture] + public class MissingFileSettingsTests + { + + [TestCase(MissingFileWhenLoadingHandling.DoNotLoad)] + [TestCase(MissingFileWhenLoadingHandling.CreateWithDefaultValues)] + public void DoNotCall_And_CreateWithDefaultValues_ShouldThrow_WhenIniPathIsNullOrEmpty(MissingFileWhenLoadingHandling missingFileWhenLoadingHandling) + { + var iniParser = Substitute.For(); + + var inisettings = new IniSettings() + { + MissingFileWhenLoadingHandling = missingFileWhenLoadingHandling + }; + + Action result = () => new IniWrapperFactory().Create(inisettings, iniParser); + + result.Should().Throw(); + } + + [Test] + public void DoNotCallIniParser_When_DoNotLoadIsSet() + { + var iniParser = Substitute.For(); + + var inisettings = new IniSettings() + { + MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.DoNotLoad, + IniFilePath = "dummyPath" + }; + + var iniWrapper = new IniWrapperFactory().Create(inisettings, iniParser); + + iniWrapper.LoadConfiguration(); + + iniParser.Received(0).Write(Arg.Any(), Arg.Any(), Arg.Any()); + iniParser.Received(0).Read(Arg.Any(), Arg.Any()); + } + + [Test] + public void SaveDefaultConfiguration_When_CreateWithDefaultValuesIsSet() + { + var iniParser = Substitute.For(); + + var inisettings = new IniSettings() + { + MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.CreateWithDefaultValues, + IniFilePath = "dummyPath" + }; + + var iniWrapper = new IniWrapperFactory().Create(inisettings, iniParser); + + iniWrapper.LoadConfiguration(); + + iniParser.Received(9).Write(Arg.Any(), Arg.Any(), Arg.Any()); + iniParser.Received(0).Read(Arg.Any(), Arg.Any()); + } + + [Test] + public void LoadConfiguration_When_IgnoreCheckIsSet() + { + var iniParser = Substitute.For(); + + var inisettings = new IniSettings() + { + MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad + }; + + var iniWrapper = new IniWrapperFactory().Create(inisettings, iniParser); + + iniWrapper.LoadConfiguration(); + + iniParser.Received(0).Write(Arg.Any(), Arg.Any(), Arg.Any()); + iniParser.Received(9).Read(Arg.Any(), Arg.Any()); + } + + [Test] + public void LoadConfiguration_When_DoNotLoadIsSet_And_FileExists() + { + var iniParser = Substitute.For(); + + var fileSystem = Substitute.For(); + fileSystem.File.Exists(Arg.Any()).Returns(true); + + var inisettings = new IniSettings() + { + MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.DoNotLoad + }; + + var iniWrapper = MockWrapperFactory.Create(inisettings, iniParser, fileSystem); + + iniWrapper.LoadConfiguration(); + + iniParser.Received(0).Write(Arg.Any(), Arg.Any(), Arg.Any()); + iniParser.Received(9).Read(Arg.Any(), Arg.Any()); + } + + [Test] + public void LoadConfiguration_When_CreateWithDefaultValuesIsSet_And_FileExists() + { + var iniParser = Substitute.For(); + + var fileSystem = Substitute.For(); + fileSystem.File.Exists(Arg.Any()).Returns(true); + + var inisettings = new IniSettings() + { + MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.CreateWithDefaultValues + }; + + var iniWrapper = MockWrapperFactory.Create(inisettings, iniParser, fileSystem); + + iniWrapper.LoadConfiguration(); + + iniParser.Received(0).Write(Arg.Any(), Arg.Any(), Arg.Any()); + iniParser.Received(9).Read(Arg.Any(), Arg.Any()); + } + + [Test] + public void LoadConfiguration_When_IgnoreCheckIsSet_And_FileExists() + { + var iniParser = Substitute.For(); + + var fileSystem = Substitute.For(); + fileSystem.File.Exists(Arg.Any()).Returns(true); + + var inisettings = new IniSettings() + { + MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad + }; + + var iniWrapper = MockWrapperFactory.Create(inisettings, iniParser, fileSystem); + + iniWrapper.LoadConfiguration(); + + iniParser.Received(0).Write(Arg.Any(), Arg.Any(), Arg.Any()); + iniParser.Received(9).Read(Arg.Any(), Arg.Any()); + } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Settings/NullValueHandlingTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Settings/NullValueHandlingTests.cs new file mode 100644 index 0000000..3cbe504 --- /dev/null +++ b/IniWrapper/IniWrapper.IntegrationTests/Settings/NullValueHandlingTests.cs @@ -0,0 +1,81 @@ +using System.Collections.Generic; +using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.ParserWrapper; +using IniWrapper.Settings; +using IniWrapper.Wrapper; +using NSubstitute; +using NUnit.Framework; + +namespace IniWrapper.IntegrationTests.Settings +{ + [TestFixture] + public class NullValueHandlingTests + { + [Test] + public void SettingsNullValueHandling_Ignore_ShouldNotSaveNullValues_ForComplexType() + { + var iniParser = Substitute.For(); + var iniWrapper = new IniWrapperFactory().Create(x => + { + x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad; + x.NullValueHandling = NullValueHandling.Ignore; + }, iniParser); + + var config = new ComplexNullConfiguration(); + + iniWrapper.SaveConfiguration(config); + + iniParser.Received(0).Write(Arg.Any(), Arg.Any(), Arg.Any()); + } + + [Test] + public void SettingsNullValueHandling_ReplaceWithEmptyString_ShouldSaveDefaultValues_ForComplexType() + { + var iniParser = Substitute.For(); + 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(), Arg.Any(), Arg.Any()); + } + + [Test] + public void SettingsNullValueHandling_Ignore_ShouldNotSaveNullValues() + { + var iniParser = Substitute.For(); + var iniWrapper = new IniWrapperFactory().Create(x => + { + x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad; + x.NullValueHandling = NullValueHandling.Ignore; + }, iniParser); + + var config = new TestConfiguration(); + + iniWrapper.SaveConfiguration(config); + + iniParser.Received(4).Write(Arg.Any(), Arg.Any(), Arg.Any()); + } + [Test] + public void SettingsNullValueHandling_ReplaceWithEmptyString_ShouldSaveDefaultValues() + { + var iniParser = Substitute.For(); + var iniWrapper = new IniWrapperFactory().Create(x => + { + x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad; + x.NullValueHandling = NullValueHandling.ReplaceWithEmptyString; + }, iniParser); + + var config = new TestConfiguration(); + + iniWrapper.SaveConfiguration(config); + + iniParser.Received(9).Write(Arg.Any(), Arg.Any(), Arg.Any()); + } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/ConfigLoadingChecker/ConfigurationLoadingChecker.cs b/IniWrapper/IniWrapper/ConfigLoadingChecker/ConfigurationLoadingChecker.cs new file mode 100644 index 0000000..3835b17 --- /dev/null +++ b/IniWrapper/IniWrapper/ConfigLoadingChecker/ConfigurationLoadingChecker.cs @@ -0,0 +1,27 @@ +using System.IO.Abstractions; +using IniWrapper.Settings; + +namespace IniWrapper.ConfigLoadingChecker +{ + internal class ConfigurationLoadingChecker : IConfigurationLoadingChecker + { + private readonly IFileSystem _fileSystem; + private readonly IIniSettings _iniSettings; + + public ConfigurationLoadingChecker(IFileSystem fileSystem, IIniSettings iniSettings) + { + _fileSystem = fileSystem; + _iniSettings = iniSettings; + } + + public bool ShouldReadConfigurationFromFile() + { + return _iniSettings.MissingFileWhenLoadingHandling == MissingFileWhenLoadingHandling.ForceLoad || _fileSystem.File.Exists(_iniSettings.IniFilePath); + } + + public bool ShouldCreateDefaultConfiguration() + { + return _iniSettings.MissingFileWhenLoadingHandling == MissingFileWhenLoadingHandling.CreateWithDefaultValues; + } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/ConfigLoadingChecker/IConfigurationLoadingChecker.cs b/IniWrapper/IniWrapper/ConfigLoadingChecker/IConfigurationLoadingChecker.cs new file mode 100644 index 0000000..5550717 --- /dev/null +++ b/IniWrapper/IniWrapper/ConfigLoadingChecker/IConfigurationLoadingChecker.cs @@ -0,0 +1,8 @@ +namespace IniWrapper.ConfigLoadingChecker +{ + internal interface IConfigurationLoadingChecker + { + bool ShouldCreateDefaultConfiguration(); + bool ShouldReadConfigurationFromFile(); + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Exceptions/CollectionOfComplexTypeException.cs b/IniWrapper/IniWrapper/Exceptions/CollectionOfComplexTypeException.cs new file mode 100644 index 0000000..a61d68a --- /dev/null +++ b/IniWrapper/IniWrapper/Exceptions/CollectionOfComplexTypeException.cs @@ -0,0 +1,17 @@ +using System; +using System.Runtime.Serialization; + +namespace IniWrapper.Exceptions +{ + [Serializable] + public class CollectionOfComplexTypeException : Exception + { + public CollectionOfComplexTypeException() : base("Collection of complex type not supported") + { + } + + protected CollectionOfComplexTypeException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Exceptions/CollectionOfCopmexTypeException.cs b/IniWrapper/IniWrapper/Exceptions/CollectionOfCopmexTypeException.cs deleted file mode 100644 index 84a2042..0000000 --- a/IniWrapper/IniWrapper/Exceptions/CollectionOfCopmexTypeException.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace IniWrapper.Exceptions -{ - [Serializable] - public class CollectionOfCopmexTypeException : Exception - { - public CollectionOfCopmexTypeException() : base("Collection of complex type is not supported") - { - } - - protected CollectionOfCopmexTypeException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } - } -} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Handlers/Object/ObjectHandler.cs b/IniWrapper/IniWrapper/Handlers/ComplexType/ComplexTypeHandler.cs similarity index 76% rename from IniWrapper/IniWrapper/Handlers/Object/ObjectHandler.cs rename to IniWrapper/IniWrapper/Handlers/ComplexType/ComplexTypeHandler.cs index c259544..8537b3c 100644 --- a/IniWrapper/IniWrapper/Handlers/Object/ObjectHandler.cs +++ b/IniWrapper/IniWrapper/Handlers/ComplexType/ComplexTypeHandler.cs @@ -1,15 +1,14 @@ using System; -using System.Collections.Generic; using IniWrapper.Manager; using IniWrapper.Wrapper; -namespace IniWrapper.Handlers.Object +namespace IniWrapper.Handlers.ComplexType { - internal class ObjectHandler : IHandler + internal class ComplexTypeHandler : IHandler { private readonly IIniWrapper _iniWrapper; - public ObjectHandler(IIniWrapper iniWrapper) + public ComplexTypeHandler(IIniWrapper iniWrapper) { _iniWrapper = iniWrapper; } diff --git a/IniWrapper/IniWrapper/Handlers/Dictionary/DictionaryEnumeratorHandler.cs b/IniWrapper/IniWrapper/Handlers/Dictionary/DictionaryEnumeratorHandler.cs index 3ebd8aa..eca8c85 100644 --- a/IniWrapper/IniWrapper/Handlers/Dictionary/DictionaryEnumeratorHandler.cs +++ b/IniWrapper/IniWrapper/Handlers/Dictionary/DictionaryEnumeratorHandler.cs @@ -52,7 +52,7 @@ public IniValue FormatToWrite(object objectToFormat, IniValue defaultIniValue) if (_typeDetailsInformation.UnderlyingKeyTypeInformation.TypeCode == TypeCode.ComplexObject || _typeDetailsInformation.UnderlyingTypeInformation.TypeCode == TypeCode.ComplexObject) { - throw new CollectionOfCopmexTypeException(); + throw new CollectionOfComplexTypeException(); } if (!(objectToFormat is IDictionaryEnumerator dictionaryEnumerator)) diff --git a/IniWrapper/IniWrapper/Handlers/Enumerable/EnumerableHandler.cs b/IniWrapper/IniWrapper/Handlers/Enumerable/EnumerableHandler.cs index 57fa8de..33c6c14 100644 --- a/IniWrapper/IniWrapper/Handlers/Enumerable/EnumerableHandler.cs +++ b/IniWrapper/IniWrapper/Handlers/Enumerable/EnumerableHandler.cs @@ -6,35 +6,36 @@ using IniWrapper.Exceptions; using IniWrapper.Manager; using IniWrapper.Member; +using IniWrapper.Settings; using TypeCode = IniWrapper.Utils.TypeCode; namespace IniWrapper.Handlers.Enumerable { internal sealed class EnumerableHandler : IHandler { - private const char Separator = ','; - private readonly IHandler _underlyingTypeHandler; private readonly TypeCode _underlyingTypeCode; private readonly Type _underlyingType; + private readonly IIniSettings _iniSettings; - public EnumerableHandler(IHandler underlyingTypeHandler, TypeCode underlyingTypeCode, Type underlyingType) + public EnumerableHandler(IHandler underlyingTypeHandler, TypeCode underlyingTypeCode, Type underlyingType, IIniSettings iniSettings) { _underlyingTypeHandler = underlyingTypeHandler; _underlyingTypeCode = underlyingTypeCode; _underlyingType = underlyingType; + _iniSettings = iniSettings; } public object ParseReadValue(Type destinationType, string readValue) { if (_underlyingTypeCode == TypeCode.ComplexObject) { - throw new CollectionOfCopmexTypeException(); + throw new CollectionOfComplexTypeException(); } var returnedList = (IList)Activator.CreateInstance(destinationType); - foreach (var value in readValue.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries)) + foreach (var value in readValue.Split(new[] { _iniSettings.EnumerableEntitySeparator }, StringSplitOptions.RemoveEmptyEntries)) { returnedList.Add(_underlyingTypeHandler.ParseReadValue(_underlyingType, value)); } @@ -52,7 +53,7 @@ public IniValue FormatToWrite(object objectToFormat, IniValue defaultIniValue) if (_underlyingTypeCode == TypeCode.ComplexObject) { - throw new CollectionOfCopmexTypeException(); + throw new CollectionOfComplexTypeException(); } var enumerable = objectToFormat as IEnumerable; @@ -66,7 +67,7 @@ public IniValue FormatToWrite(object objectToFormat, IniValue defaultIniValue) } stringBuilder.Append(_underlyingTypeHandler.FormatToWrite(item, defaultIniValue)?.Value); - stringBuilder.Append(Separator); + stringBuilder.Append(_iniSettings.EnumerableEntitySeparator); } RemoveLastSeparator(stringBuilder); diff --git a/IniWrapper/IniWrapper/Handlers/NullValue/NullComplexTypeHandler.cs b/IniWrapper/IniWrapper/Handlers/NullValue/NullComplexTypeHandler.cs new file mode 100644 index 0000000..003c99c --- /dev/null +++ b/IniWrapper/IniWrapper/Handlers/NullValue/NullComplexTypeHandler.cs @@ -0,0 +1,28 @@ +using System; +using IniWrapper.Manager; + +namespace IniWrapper.Handlers.NullValue +{ + internal class NullComplexTypeHandler : IHandler + { + private readonly IHandler _complexTypeHandler; + private readonly Type _complexType; + + public NullComplexTypeHandler(IHandler complexTypeHandler, Type complexType) + { + _complexTypeHandler = complexTypeHandler; + _complexType = complexType; + } + + public object ParseReadValue(Type destinationType, string readValue) + { + throw new NotImplementedException(); + } + + public IniValue FormatToWrite(object objectToFormat, IniValue defaultIniValue) + { + objectToFormat = Activator.CreateInstance(_complexType); + return _complexTypeHandler.FormatToWrite(objectToFormat, defaultIniValue); + } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Handlers/NullValue/NullValueHandler.cs b/IniWrapper/IniWrapper/Handlers/NullValue/NullValueHandler.cs index fb5d110..afa49af 100644 --- a/IniWrapper/IniWrapper/Handlers/NullValue/NullValueHandler.cs +++ b/IniWrapper/IniWrapper/Handlers/NullValue/NullValueHandler.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using IniWrapper.Manager; namespace IniWrapper.Handlers.NullValue @@ -8,13 +7,12 @@ internal class NullValueHandler : IHandler { public object ParseReadValue(Type destinationType, string readValue) { - return readValue; + throw new NotImplementedException(); } public IniValue FormatToWrite(object objectToFormat, IniValue defaultIniValue) { - defaultIniValue.Value = string.Empty; - + defaultIniValue.Value = null; return defaultIniValue; } } diff --git a/IniWrapper/IniWrapper/Handlers/NullValue/NullValueReplaceHandler.cs b/IniWrapper/IniWrapper/Handlers/NullValue/NullValueReplaceHandler.cs new file mode 100644 index 0000000..a26824a --- /dev/null +++ b/IniWrapper/IniWrapper/Handlers/NullValue/NullValueReplaceHandler.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using IniWrapper.Manager; + +namespace IniWrapper.Handlers.NullValue +{ + internal class NullValueReplaceHandler : IHandler + { + public object ParseReadValue(Type destinationType, string readValue) + { + throw new NotImplementedException(); + } + + public IniValue FormatToWrite(object objectToFormat, IniValue defaultIniValue) + { + defaultIniValue.Value = string.Empty; + + return defaultIniValue; + } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs b/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs index 5e3a857..236481b 100644 --- a/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs +++ b/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs @@ -1,14 +1,15 @@ using System; using IniWrapper.Handlers; +using IniWrapper.Handlers.ComplexType; using IniWrapper.Handlers.Dictionary; using IniWrapper.Handlers.Enumerable; using IniWrapper.Handlers.Enums; using IniWrapper.Handlers.Ignore; using IniWrapper.Handlers.NullValue; -using IniWrapper.Handlers.Object; using IniWrapper.Handlers.Primitive; using IniWrapper.Member; using IniWrapper.ParserWrapper; +using IniWrapper.Settings; using IniWrapper.Utils; using IniWrapper.Wrapper; using TypeCode = IniWrapper.Utils.TypeCode; @@ -18,12 +19,14 @@ namespace IniWrapper.HandlersFactory internal class HandlerFactory : IHandlerFactory { private readonly ITypeManager _typeManager; + private readonly IIniSettings _iniSettings; public IIniWrapper IniWrapper { get; set; } - public HandlerFactory(ITypeManager typeManager) + public HandlerFactory(ITypeManager typeManager, IIniSettings iniSettings) { _typeManager = typeManager; + _iniSettings = iniSettings; } public (IHandler handler, TypeDetailsInformation typeDetailsInformation) GetHandler(Type type, object value, IMemberInfoWrapper memberInfoWrapper) @@ -57,7 +60,23 @@ private IHandler GetHandler(TypeDetailsInformation typeInformation) { var underlyingTypeHandler = GetBaseHandler(typeInformation.UnderlyingTypeInformation.TypeCode, typeInformation.UnderlyingTypeInformation.IsEnum); - return new EnumerableHandler(underlyingTypeHandler, typeInformation.UnderlyingTypeInformation.TypeCode, typeInformation.UnderlyingTypeInformation.Type); + return new EnumerableHandler(underlyingTypeHandler, + typeInformation.UnderlyingTypeInformation.TypeCode, + typeInformation.UnderlyingTypeInformation.Type, + _iniSettings); + } + case TypeCode.NullValue: + { + if (_iniSettings.NullValueHandling == NullValueHandling.Ignore) + { + return new NullValueHandler(); + } + + if (typeInformation.UnderlyingTypeInformation?.TypeCode == TypeCode.ComplexObject) + { + return new NullComplexTypeHandler(new ComplexTypeHandler(IniWrapper), typeInformation.UnderlyingTypeInformation.Type); + } + return new NullValueReplaceHandler(); } default: { @@ -70,12 +89,7 @@ private IHandler GetBaseHandler(TypeCode typeCode, bool? isEnum) { if (typeCode == TypeCode.ComplexObject) { - return new ObjectHandler(IniWrapper); - } - - if (typeCode == TypeCode.NullValue) - { - return new NullValueHandler(); + return new ComplexTypeHandler(IniWrapper); } if (isEnum != null && isEnum.Value) diff --git a/IniWrapper/IniWrapper/Manager/Read/ReadingManager.cs b/IniWrapper/IniWrapper/Manager/Read/ReadingManager.cs index 66303f4..6881594 100644 --- a/IniWrapper/IniWrapper/Manager/Read/ReadingManager.cs +++ b/IniWrapper/IniWrapper/Manager/Read/ReadingManager.cs @@ -43,7 +43,7 @@ public void ReadValue(IMemberInfoWrapper memberInfoWrapper, object configuration if (typeDetailsInformation.TypeCode == TypeCode.Enumerable && typeDetailsInformation.UnderlyingTypeInformation.TypeCode == TypeCode.ComplexObject) { - throw new CollectionOfCopmexTypeException(); + throw new CollectionOfComplexTypeException(); } try { diff --git a/IniWrapper/IniWrapper/Manager/Read/Strategy/DictionaryReadingStrategy.cs b/IniWrapper/IniWrapper/Manager/Read/Strategy/DictionaryReadingStrategy.cs index efb19af..6d2b151 100644 --- a/IniWrapper/IniWrapper/Manager/Read/Strategy/DictionaryReadingStrategy.cs +++ b/IniWrapper/IniWrapper/Manager/Read/Strategy/DictionaryReadingStrategy.cs @@ -20,7 +20,7 @@ public string Read(IniValue iniValue, IMemberInfoWrapper memberInfoWrapper, obje { if (_readingTypeCode == TypeCode.ComplexObject) { - throw new CollectionOfCopmexTypeException(); + throw new CollectionOfComplexTypeException(); } return _iniParser.Read(iniValue.Key, null); diff --git a/IniWrapper/IniWrapper/ParserWrapper/IniParser.cs b/IniWrapper/IniWrapper/ParserWrapper/IniParser.cs index c352e8c..b56e8ef 100644 --- a/IniWrapper/IniWrapper/ParserWrapper/IniParser.cs +++ b/IniWrapper/IniWrapper/ParserWrapper/IniParser.cs @@ -8,6 +8,8 @@ namespace IniWrapper.ParserWrapper public sealed class IniParser : IIniParser { private readonly string _filePath; + private readonly int _bufferSize; + [DllImport("kernel32", CharSet = CharSet.Unicode)] private static extern long WritePrivateProfileString(string section, string key, string value, string filePath); @@ -18,14 +20,15 @@ public sealed class IniParser : IIniParser [DllImport("kernel32.dll")] private static extern int GetPrivateProfileSection(string lpAppName, byte[] lpszReturnBuffer, int nSize, string lpFileName); - public IniParser(string iniPath) + public IniParser(string iniPath, int bufferSize) { _filePath = iniPath; + _bufferSize = bufferSize; } public string ReadAllFromSection(string section) { - var buffer = new byte[2048]; + var buffer = new byte[_bufferSize]; GetPrivateProfileSection(section, buffer, 2048, _filePath); return Encoding.ASCII.GetString(buffer).Trim('\0'); @@ -38,7 +41,7 @@ public string Read(string section, string key) return ReadAllFromSection(section); } - var returnValueBuffer = new StringBuilder(2048); + var returnValueBuffer = new StringBuilder(_bufferSize); GetPrivateProfileString(section, key, string.Empty, returnValueBuffer, returnValueBuffer.Capacity, _filePath); return returnValueBuffer.ToString(); diff --git a/IniWrapper/IniWrapper/Settings/IIniSettings.cs b/IniWrapper/IniWrapper/Settings/IIniSettings.cs new file mode 100644 index 0000000..95f44cf --- /dev/null +++ b/IniWrapper/IniWrapper/Settings/IIniSettings.cs @@ -0,0 +1,10 @@ +namespace IniWrapper.Settings +{ + internal interface IIniSettings + { + char EnumerableEntitySeparator { get; } + string IniFilePath { get; } + MissingFileWhenLoadingHandling MissingFileWhenLoadingHandling { get; } + NullValueHandling NullValueHandling { get; } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Settings/IniSettings.cs b/IniWrapper/IniWrapper/Settings/IniSettings.cs new file mode 100644 index 0000000..1f1c69f --- /dev/null +++ b/IniWrapper/IniWrapper/Settings/IniSettings.cs @@ -0,0 +1,15 @@ +namespace IniWrapper.Settings +{ + public class IniSettings : IIniSettings + { + public char EnumerableEntitySeparator { get; set; } = ','; + + public string IniFilePath { get; set; } + + public MissingFileWhenLoadingHandling MissingFileWhenLoadingHandling { get; set; } = MissingFileWhenLoadingHandling.ForceLoad; + + public NullValueHandling NullValueHandling { get; set; } = NullValueHandling.ReplaceWithEmptyString; + + public int DefaultIniWrapperBufferSize { get; set; } = 1024; + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Settings/MissingFileWhenLoadingHandling.cs b/IniWrapper/IniWrapper/Settings/MissingFileWhenLoadingHandling.cs new file mode 100644 index 0000000..ec187d5 --- /dev/null +++ b/IniWrapper/IniWrapper/Settings/MissingFileWhenLoadingHandling.cs @@ -0,0 +1,22 @@ +namespace IniWrapper.Settings +{ + /// + /// Handling situation when file is missing or FilePath is not set. + /// + public enum MissingFileWhenLoadingHandling + { + /// + /// Library will not check if file exists. It will always try to load from file. + /// + ForceLoad, + /// + /// If file is missing library will return instance of given configuration class. It won't neither write nor read anything from file. + /// + DoNotLoad, + /// + /// If file is missing library will create instance of given configuration class save it to file and return instance. + /// Note: FilePath have to be set. + /// + CreateWithDefaultValues + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Settings/NullValueHandling.cs b/IniWrapper/IniWrapper/Settings/NullValueHandling.cs new file mode 100644 index 0000000..c87649c --- /dev/null +++ b/IniWrapper/IniWrapper/Settings/NullValueHandling.cs @@ -0,0 +1,14 @@ +namespace IniWrapper.Settings +{ + public enum NullValueHandling + { + /// + /// Null values will be not written + /// + Ignore, + /// + /// Null values will be replaced with empty string, for complex types library will create instance of it and write it + /// + ReplaceWithEmptyString + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Utils/TypeManager.cs b/IniWrapper/IniWrapper/Utils/TypeManager.cs index a8874a4..2a297d0 100644 --- a/IniWrapper/IniWrapper/Utils/TypeManager.cs +++ b/IniWrapper/IniWrapper/Utils/TypeManager.cs @@ -52,11 +52,27 @@ internal class TypeManager : ITypeManager public TypeDetailsInformation GetTypeInformation(Type type, object value) { - if (value == null) + var typeInformation = GetBaseTypeInformation(type); + + if (value != null) + { + return typeInformation; + } + + if (typeInformation.TypeCode == TypeCode.ComplexObject) { - return new TypeDetailsInformation(TypeCode.NullValue, null, null); + return new TypeDetailsInformation(TypeCode.NullValue, + new UnderlyingTypeInformation(typeInformation.TypeCode, + typeInformation.UnderlyingTypeInformation.IsEnum, + typeInformation.UnderlyingTypeInformation.Type), + null); } + return new TypeDetailsInformation(TypeCode.NullValue, null, null); + } + + private TypeDetailsInformation GetBaseTypeInformation(Type type) + { if (!IsNullableType(type) && TypeCodeMap.TryGetValue(type, out var typeCode)) { return new TypeDetailsInformation(typeCode, new UnderlyingTypeInformation(typeCode, false, type), null); @@ -67,8 +83,8 @@ public TypeDetailsInformation GetTypeInformation(Type type, object value) var underlyingGenericTypeKey = type.GenericTypeArguments[0]; var underlyingGenericTypeValue = type.GenericTypeArguments[1]; - var genericKeyTypeCode = GetTypeInformation(underlyingGenericTypeKey, value); - var genericValueTypeCode = GetTypeInformation(underlyingGenericTypeValue, value); + var genericKeyTypeCode = GetBaseTypeInformation(underlyingGenericTypeKey); + var genericValueTypeCode = GetBaseTypeInformation(underlyingGenericTypeValue); var underlyingKeyTypeInformation = new UnderlyingTypeInformation(genericKeyTypeCode.TypeCode, genericKeyTypeCode.UnderlyingTypeInformation.IsEnum, genericKeyTypeCode.UnderlyingTypeInformation.Type); var underlyingTypeInformation = new UnderlyingTypeInformation(genericValueTypeCode.TypeCode, genericValueTypeCode.UnderlyingTypeInformation.IsEnum, genericValueTypeCode.UnderlyingTypeInformation.Type); @@ -79,7 +95,7 @@ public TypeDetailsInformation GetTypeInformation(Type type, object value) if (typeof(IEnumerable).IsAssignableFrom(type)) { var underlyingGenericType = type.GenericTypeArguments[0]; - var genericTypeCode = GetTypeInformation(underlyingGenericType, value); + var genericTypeCode = GetBaseTypeInformation(underlyingGenericType); return new TypeDetailsInformation(TypeCode.Enumerable, new UnderlyingTypeInformation( @@ -88,11 +104,10 @@ public TypeDetailsInformation GetTypeInformation(Type type, object value) genericTypeCode.UnderlyingTypeInformation.Type), null); } - if (type.IsEnum) { var underlyingType = Enum.GetUnderlyingType(type); - var typeDetailsInformation = GetTypeInformation(underlyingType, value); + var typeDetailsInformation = GetBaseTypeInformation(underlyingType); return new TypeDetailsInformation(typeDetailsInformation.TypeCode, new UnderlyingTypeInformation(TypeCode.Empty, true, type), null); } @@ -101,13 +116,13 @@ public TypeDetailsInformation GetTypeInformation(Type type, object value) if (nullable == null) { - return new TypeDetailsInformation(TypeCode.ComplexObject, new UnderlyingTypeInformation(TypeCode.Empty, false, null), null); + return new TypeDetailsInformation(TypeCode.ComplexObject, new UnderlyingTypeInformation(TypeCode.Empty, false, type), null); } if (nullable.IsEnum) { var nullableUnderlyingType = Enum.GetUnderlyingType(nullable); - var underlyingType = GetTypeInformation(nullableUnderlyingType, value); + var underlyingType = GetBaseTypeInformation(nullableUnderlyingType); return new TypeDetailsInformation(underlyingType.TypeCode, new UnderlyingTypeInformation(TypeCode.Empty, true, nullableUnderlyingType), null); } diff --git a/IniWrapper/IniWrapper/Wrapper/IIniWrapperFactory.cs b/IniWrapper/IniWrapper/Wrapper/IIniWrapperFactory.cs index 6dba24d..f9c7658 100644 --- a/IniWrapper/IniWrapper/Wrapper/IIniWrapperFactory.cs +++ b/IniWrapper/IniWrapper/Wrapper/IIniWrapperFactory.cs @@ -1,11 +1,17 @@ -using IniWrapper.ParserWrapper; +using System; +using IniWrapper.ParserWrapper; +using IniWrapper.Settings; namespace IniWrapper.Wrapper { public interface IIniWrapperFactory { - IIniWrapper Create(string filePath, IIniParser iniParser); + IIniWrapper Create(IIniParser iniParser); + IIniWrapper Create(IniSettings iniSettings, IIniParser iniParser); + IIniWrapper Create(Action iniSettings, IIniParser iniParser); - IIniWrapper CreateWithDefaultIniParser(string filePath); + IIniWrapper CreateWithDefaultIniParser(IniSettings iniSettings); + IIniWrapper CreateWithDefaultIniParser(Action iniSettings); + IIniWrapper CreateWithDefaultIniParser(); } } \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Wrapper/IniWrapper.cs b/IniWrapper/IniWrapper/Wrapper/IniWrapper.cs index 7cae8b0..ba605ed 100644 --- a/IniWrapper/IniWrapper/Wrapper/IniWrapper.cs +++ b/IniWrapper/IniWrapper/Wrapper/IniWrapper.cs @@ -1,6 +1,7 @@ using System; using System.IO.Abstractions; using System.Runtime.CompilerServices; +using IniWrapper.ConfigLoadingChecker; using IniWrapper.Manager.Read; using IniWrapper.Manager.Save; using IniWrapper.Member; @@ -11,20 +12,17 @@ namespace IniWrapper.Wrapper { internal sealed class IniWrapper : IIniWrapper { - private readonly string _filePath; - private readonly IFileSystem _fileSystem; private readonly ISavingManager _savingManager; private readonly IReadingManager _readingManager; + private readonly IConfigurationLoadingChecker _configurationLoadingChecker; - public IniWrapper(string filePath, - IFileSystem fileSystem, - ISavingManager savingManager, - IReadingManager readingManager) + public IniWrapper(ISavingManager savingManager, + IReadingManager readingManager, + IConfigurationLoadingChecker configurationLoadingChecker) { - _filePath = filePath; - _fileSystem = fileSystem; _savingManager = savingManager; _readingManager = readingManager; + _configurationLoadingChecker = configurationLoadingChecker; } public T LoadConfiguration() where T : new() @@ -34,15 +32,20 @@ public IniWrapper(string filePath, public object LoadConfiguration(Type destinationType) { - if (!_fileSystem.File.Exists(_filePath)) + if (_configurationLoadingChecker.ShouldReadConfigurationFromFile()) { - var defaultConfiguration = Activator.CreateInstance(destinationType); - SaveConfiguration(defaultConfiguration); - return defaultConfiguration; + var result = Activator.CreateInstance(destinationType); + return ReadFromFile(result); } - var result = Activator.CreateInstance(destinationType); - return ReadFromFile(result); + if (!_configurationLoadingChecker.ShouldCreateDefaultConfiguration()) + { + return Activator.CreateInstance(destinationType); + } + + var defaultConfiguration = Activator.CreateInstance(destinationType); + SaveConfiguration(defaultConfiguration); + return defaultConfiguration; } public void SaveConfiguration(object configuration) diff --git a/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs b/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs index 5ea3111..a6e421e 100644 --- a/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs +++ b/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs @@ -1,4 +1,6 @@ -using System.IO.Abstractions; +using System; +using System.IO.Abstractions; +using IniWrapper.ConfigLoadingChecker; using IniWrapper.HandlersFactory; using IniWrapper.Manager; using IniWrapper.Manager.Attribute; @@ -7,29 +9,81 @@ using IniWrapper.Manager.Save; using IniWrapper.Manager.Save.Strategy.Factory; using IniWrapper.ParserWrapper; +using IniWrapper.Settings; using IniWrapper.Utils; namespace IniWrapper.Wrapper { public class IniWrapperFactory : IIniWrapperFactory { - public IIniWrapper Create(string filePath, IIniParser iniParser) + public IIniWrapper Create(IniSettings iniSettings, IIniParser iniParser) { - var handlerFactory = new HandlerFactory(new TypeManager()); + CheckSettings(iniSettings); - var iniWrapper = new IniWrapper(filePath, - new FileSystem(), - new SavingManager(new IniValueManager(new IniValueAttributeManager()), new SavingStrategyFactory(handlerFactory, iniParser)), - new ReadingManager(new IniValueManager(new IniValueAttributeManager()), handlerFactory, new ReadingStrategyFactory(iniParser))); + var handlerFactory = new HandlerFactory(new TypeManager(), iniSettings); + + var savingManager = new SavingManager(new IniValueManager(new IniValueAttributeManager()), + new SavingStrategyFactory(handlerFactory, iniParser)); + + var readingManager = new ReadingManager(new IniValueManager(new IniValueAttributeManager()), handlerFactory, + new ReadingStrategyFactory(iniParser)); + + var defaultConfigurationCreationStrategy = new ConfigurationLoadingChecker(new FileSystem(), iniSettings); + + var iniWrapper = new IniWrapper(savingManager, readingManager, defaultConfigurationCreationStrategy); handlerFactory.IniWrapper = iniWrapper; return iniWrapper; } - public IIniWrapper CreateWithDefaultIniParser(string filePath) + public IIniWrapper Create(IIniParser iniParser) + { + return Create(new IniSettings(), iniParser); + } + + + public IIniWrapper Create(Action iniSettings, IIniParser iniParser) + { + var settings = new IniSettings(); + + iniSettings(settings); + + return Create(settings, iniParser); + } + + public IIniWrapper CreateWithDefaultIniParser(IniSettings iniSettings) + { + if (string.IsNullOrEmpty(iniSettings.IniFilePath)) + { + throw new ArgumentException($"{nameof(iniSettings.IniFilePath)} must be provided when calling CreateWithDefaultIniParser. Assign it or use Create with custom IniParser."); + } + + return Create(iniSettings, new IniParser(iniSettings.IniFilePath, iniSettings.DefaultIniWrapperBufferSize)); + } + + public IIniWrapper CreateWithDefaultIniParser(Action iniSettings) + { + var settings = new IniSettings(); + + iniSettings(settings); + + return CreateWithDefaultIniParser(settings); + } + + public IIniWrapper CreateWithDefaultIniParser() + { + return CreateWithDefaultIniParser(new IniSettings()); + } + private static void CheckSettings(IniSettings iniSettings) { - return Create(filePath, new IniParser(filePath)); + if ((iniSettings.MissingFileWhenLoadingHandling == MissingFileWhenLoadingHandling.CreateWithDefaultValues || + iniSettings.MissingFileWhenLoadingHandling == MissingFileWhenLoadingHandling.DoNotLoad) && + string.IsNullOrEmpty(iniSettings.IniFilePath)) + { + throw new ArgumentException( + $"Please specify {nameof(iniSettings.IniFilePath)} in settings with chosen {nameof(MissingFileWhenLoadingHandling)}"); + } } } } \ No newline at end of file diff --git a/README.md b/README.md index 9cfb62d..74a243c 100644 --- a/README.md +++ b/README.md @@ -13,18 +13,29 @@ IniWrapper uses reflection to bind value read from ini file to provided model. T You can use custom IniParser class by passing it to Create Method in IniWrapperFactory class. Then call LoadConfiguration method with class that IniWrapper should discover and bind values. ``` csharp var iniWrapperFactory = new IniWrapperFactory(); -var iniWrapper = iniWrapperFactory.Create("test.ini", new CustomIniParser()); +var iniWrapper = iniWrapperFactory.Create(new CustomIniParser()); var loadedIniConfiguration = iniWrapper.LoadConfiguration(); ``` - -If you want to use default IniParser you can call CreateWithDefaultIniParser method. By doing this library will create IniParser that wraps Windows C++ methods from kernel. For more information see Microsoft documentation for WritePrivateProfileString, GetPrivateProfileString and GetPrivateProfileSection and [IniParser.cs](https://github.com/Szpi/IniWrapper/blob/master/IniWrapper/IniWrapper/ParserWrapper/IniParser.cs). +If you want to use default IniParser you can call CreateWithDefaultIniParser method. By doing this library will create IniParser that wraps Windows C++ methods from kernel. For more information see Microsoft documentation for WritePrivateProfileString, GetPrivateProfileString and GetPrivateProfileSection and [IniParser.cs](https://github.com/Szpi/IniWrapper/blob/master/IniWrapper/IniWrapper/ParserWrapper/IniParser.cs). ``` csharp var iniWrapperFactory = new IniWrapperFactory();; -var iniWrapper = iniWrapperFactory.CreateWithDefaultIniParser("test.ini"); +var iniWrapper = iniWrapperFactory.CreateWithDefaultIniParser(); var loadedIniConfiguration = iniWrapper.LoadConfiguration(); ``` + +Configure library's [Settings](https://github.com/Szpi/IniWrapper/wiki/Settings) to change it's default behaviour. +```csharp +var iniWrapper = new IniWrapperFactory().Create(iniSettings => +{ + iniSettings.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad; + iniSettings.EnumerableEntitySeparator = '*'; + iniSettings.IniFilePath = "test.ini"; + iniSettings.NullValueHandling = NullValueHandling.ReplaceWithEmptyString; + iniSettings.DefaultIniWrapperBufferSize = 1024; +}, iniParser); +``` **Note:** In version 1.1.0 and 1.0.0 you have to call IniWrapperFactory with CreateWithDefaultIniWrapper. @@ -35,7 +46,7 @@ var iniWrapper = iniWrapperFactory.CreateWithDefaultIniWrapper("test.ini"); To save configuration just call Save method and pass configuration class. ``` csharp var iniWrapperFactory = new IniWrapperFactory(); -var iniWrapper = iniWrapperFactory.CreateWithDefaultIniParser("test.ini"); +var iniWrapper = iniWrapperFactory.CreateWithDefaultIniParser(); iniWrapper.SaveConfiguration(new TestConfiguration()); ``` @@ -49,10 +60,10 @@ var iniWrapper = iniWrapperFactory.CreateWithDefaultIniWrapper("test.ini"); For given configuration class: ``` csharp public struct TestConfiguration - { +{ public string TestString { get; set; } public List TestIntList { get; set; } - } +} ``` IniWrapper will call IIniParser with following ini parameters Section:TestConfiguration, Key: TestString, Value : value in TestString property. @@ -67,4 +78,6 @@ Overall rules: - Key is taken from Key (from IDictionary) - Value is taken from Value (from IDictionary) +To override library's default name resolving you can use [IniOptionsAttribute](https://github.com/Szpi/IniWrapper/wiki/Attributes). + ***For more information please go to [wiki page](https://github.com/Szpi/IniWrapper/wiki).*** \ No newline at end of file