From 48844a2f0d732d6a4345fa27700eea3838a33f6e Mon Sep 17 00:00:00 2001 From: Tisu Date: Sun, 15 Jul 2018 21:07:54 +0200 Subject: [PATCH 01/11] Renamed misspelled exception --- .../Properties/ComplexNullConfiguration.cs | 7 ++ .../IniParserIEnumerableOfComplexDataTests.cs | 2 +- ...serIEnumerableReadingOfComplexDataTests.cs | 2 +- .../IniParserIEnumerableOfComplexDataTests.cs | 2 +- ...IniParserComplexDataSavePropertiesTests.cs | 14 ++++ .../IniParserIEnumerableOfComplexDataTests.cs | 2 +- ...iParserSaveDictionaryOfComplexdataTests.cs | 4 +- .../CollectionOfComplexTypeException.cs | 17 +++++ .../CollectionOfCopmexTypeException.cs | 17 ----- .../Dictionary/DictionaryEnumeratorHandler.cs | 2 +- .../Handlers/Enumerable/EnumerableHandler.cs | 4 +- .../IniWrapper/Manager/Read/ReadingManager.cs | 2 +- .../Strategy/DictionaryReadingStrategy.cs | 2 +- README.md | 75 +++++++++++++++++-- 14 files changed, 119 insertions(+), 33 deletions(-) create mode 100644 IniWrapper/IniWrapper.IntegrationTests/Main/Configuration/Properties/ComplexNullConfiguration.cs create mode 100644 IniWrapper/IniWrapper/Exceptions/CollectionOfComplexTypeException.cs delete mode 100644 IniWrapper/IniWrapper/Exceptions/CollectionOfCopmexTypeException.cs 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/Read/Fields/IniParserIEnumerableOfComplexDataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniParserIEnumerableOfComplexDataTests.cs index 33fb4f2..aa4d935 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniParserIEnumerableOfComplexDataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniParserIEnumerableOfComplexDataTests.cs @@ -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/Properties/IniParserIEnumerableReadingOfComplexDataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniParserIEnumerableReadingOfComplexDataTests.cs index 823522b..dad9041 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniParserIEnumerableReadingOfComplexDataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniParserIEnumerableReadingOfComplexDataTests.cs @@ -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/Save/Fields/IniParserIEnumerableOfComplexDataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniParserIEnumerableOfComplexDataTests.cs index 46ae4f5..33b7930 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniParserIEnumerableOfComplexDataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniParserIEnumerableOfComplexDataTests.cs @@ -30,7 +30,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/IniParserComplexDataSavePropertiesTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniParserComplexDataSavePropertiesTests.cs index 89d8574..84a573e 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniParserComplexDataSavePropertiesTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniParserComplexDataSavePropertiesTests.cs @@ -45,5 +45,19 @@ 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_ShouldSaveCorrectComplexType1() + { + var testString = "test_string_to_save"; + var config = new ComplexNullConfiguration() + { + NullableConfiguration = null + }; + + _iniWrapper.SaveConfiguration(config); + + _iniParser.Received(0).Write(Arg.Any(), Arg.Any(), Arg.Any()); + } } } \ No newline at end of file diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniParserIEnumerableOfComplexDataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniParserIEnumerableOfComplexDataTests.cs index 5828f7c..86cb600 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniParserIEnumerableOfComplexDataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniParserIEnumerableOfComplexDataTests.cs @@ -30,7 +30,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/IniParserSaveDictionaryOfComplexdataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniParserSaveDictionaryOfComplexdataTests.cs index ef1c9a6..00e9409 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniParserSaveDictionaryOfComplexdataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniParserSaveDictionaryOfComplexdataTests.cs @@ -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/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 1c06169..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 not supported") - { - } - - protected CollectionOfCopmexTypeException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } - } -} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Handlers/Dictionary/DictionaryEnumeratorHandler.cs b/IniWrapper/IniWrapper/Handlers/Dictionary/DictionaryEnumeratorHandler.cs index 32bb1b1..f7e81b3 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.ReferenceObject || _typeDetailsInformation.UnderlyingTypeInformation.TypeCode == TypeCode.ReferenceObject) { - 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 5f030e8..6f624ec 100644 --- a/IniWrapper/IniWrapper/Handlers/Enumerable/EnumerableHandler.cs +++ b/IniWrapper/IniWrapper/Handlers/Enumerable/EnumerableHandler.cs @@ -29,7 +29,7 @@ public object ParseReadValue(Type destinationType, string readValue) { if (_underlyingTypeCode == TypeCode.ReferenceObject) { - throw new CollectionOfCopmexTypeException(); + throw new CollectionOfComplexTypeException(); } var returnedList = (IList)Activator.CreateInstance(destinationType); @@ -52,7 +52,7 @@ public IniValue FormatToWrite(object objectToFormat, IniValue defaultIniValue) if (_underlyingTypeCode == TypeCode.ReferenceObject) { - throw new CollectionOfCopmexTypeException(); + throw new CollectionOfComplexTypeException(); } var enumerable = objectToFormat as IEnumerable; diff --git a/IniWrapper/IniWrapper/Manager/Read/ReadingManager.cs b/IniWrapper/IniWrapper/Manager/Read/ReadingManager.cs index be1351b..43830fc 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.ReferenceObject) { - 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 3fba7c2..5c91997 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.ReferenceObject) { - throw new CollectionOfCopmexTypeException(); + throw new CollectionOfComplexTypeException(); } return _iniParser.Read(iniValue.Key, null); diff --git a/README.md b/README.md index 92079e7..69b792d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,70 @@ -# IniWrapper -![VSTS](https://iniwrapper.visualstudio.com/_apis/public/build/definitions/9232e33a-db8d-4617-a1b1-8cf3ce4c88f5/3/badge) -![Travis](https://travis-ci.org/Szpi/IniWrapper.svg?branch=master) -[![codecov](https://codecov.io/gh/Szpi/IniWrapper/branch/master/graph/badge.svg)](https://codecov.io/gh/Szpi/IniWrapper) -![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg) \ No newline at end of file +# IniWrapper +[![Latest version](https://img.shields.io/nuget/v/IniWrapper.svg)](https://www.nuget.org/packages/IniWrapper/) [![codecov](https://codecov.io/gh/Szpi/IniWrapper/branch/master/graph/badge.svg)](https://codecov.io/gh/Szpi/IniWrapper) ![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg) + +## Build Status +  | `VSTS` | `Travis` +--- | --- | --- +**master** | ![VSTS](https://iniwrapper.visualstudio.com/_apis/public/build/definitions/9232e33a-db8d-4617-a1b1-8cf3ce4c88f5/3/badge) | ![Travis](https://travis-ci.org/Szpi/IniWrapper.svg?branch=master) + +IniWrapper uses reflection to bind value read from ini file to provided model. The purpose of this library is NOT parsing ini file, but to wrap it to provide easier use of existing parsing libraries. In configuration there is possibility to pass IniParser interface, which is used as file access layer. This library provides class that wraps Windows C++ methods to retrieve values from ini file. +## Quick start +### Loading configuration + +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 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). +``` csharp +var iniWrapperFactory = new IniWrapperFactory(); +var iniWrapper = iniWrapperFactory.CreateWithDefaultIniParser("test.ini"); + +var loadedIniConfiguration = iniWrapper.LoadConfiguration(); +``` +**Note:** +In version 1.1.0 and 1.0.0 you have to call IniWrapperFactory with CreateWithDefaultIniWrapper. + +``` csharp +var iniWrapper = iniWrapperFactory.CreateWithDefaultIniWrapper("test.ini"); +``` +### Saving configuration +To save configuration just call Save method and pass configuration class. +``` csharp +var iniWrapperFactory = new IniWrapperFactory(); +var iniWrapper = iniWrapperFactory.CreateWithDefaultIniParser("test.ini"); + +iniWrapper.SaveConfiguration(new TestConfiguration()); +``` +**Note:** +In version 1.1.0 and 1.0.0 you have to call IniWrapperFactory with CreateWithDefaultIniWrapper. + +``` csharp +var iniWrapper = iniWrapperFactory.CreateWithDefaultIniWrapper("test.ini"); +``` +## How does it work? +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. + +Overall rules: +- Section is evaluated from class / struct name +- Key is evaluated from property / field name +- Value is taken from property / field value + +**Exception is for IDictionary type:** +- Section is evaluated from property / field name +- Key is taken from Key (from IDictionary) +- Value is taken from Value (from IDictionary) + +***For more information please go to [wiki page](https://github.com/Szpi/IniWrapper/wiki).*** \ No newline at end of file From 314104c2bfe086acfa2e4b6b8ec995686f2fb525 Mon Sep 17 00:00:00 2001 From: Tisu Date: Sun, 15 Jul 2018 22:03:07 +0200 Subject: [PATCH 02/11] Handle null complex type by writing its all properties / fields with empty string --- .../TwoDepthNullComplexConfiguration.cs | 7 ++++ ...niWrapperComplexDataSavePropertiesTests.cs | 23 +++++++++++-- .../ComplexTypeHandler.cs} | 7 ++-- .../ComplexType/NullComplexTypeHandler.cs | 28 ++++++++++++++++ .../Handlers/NullValue/NullValueHandler.cs | 2 +- .../HandlersFactory/HandlerFactory.cs | 17 ++++++---- IniWrapper/IniWrapper/Utils/TypeManager.cs | 33 ++++++++++++++----- 7 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 IniWrapper/IniWrapper.IntegrationTests/Main/Configuration/Properties/TwoDepthNullComplexConfiguration.cs rename IniWrapper/IniWrapper/Handlers/{Object/ObjectHandler.cs => ComplexType/ComplexTypeHandler.cs} (76%) create mode 100644 IniWrapper/IniWrapper/Handlers/ComplexType/NullComplexTypeHandler.cs 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/Save/Properties/IniWrapperComplexDataSavePropertiesTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperComplexDataSavePropertiesTests.cs index 84a573e..64d74da 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperComplexDataSavePropertiesTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperComplexDataSavePropertiesTests.cs @@ -47,9 +47,8 @@ public void SaveConfiguration_ShouldSaveCorrectComplexType() } [Test] - public void SaveConfiguration_ShouldSaveCorrectComplexType1() + public void SaveConfiguration_ShouldReplaceAllNullValuesWithEmptyStringForComplexType() { - var testString = "test_string_to_save"; var config = new ComplexNullConfiguration() { NullableConfiguration = null @@ -57,7 +56,25 @@ public void SaveConfiguration_ShouldSaveCorrectComplexType1() _iniWrapper.SaveConfiguration(config); - _iniParser.Received(0).Write(Arg.Any(), Arg.Any(), Arg.Any()); + _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/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/ComplexType/NullComplexTypeHandler.cs b/IniWrapper/IniWrapper/Handlers/ComplexType/NullComplexTypeHandler.cs new file mode 100644 index 0000000..8dc0ffe --- /dev/null +++ b/IniWrapper/IniWrapper/Handlers/ComplexType/NullComplexTypeHandler.cs @@ -0,0 +1,28 @@ +using System; +using IniWrapper.Manager; + +namespace IniWrapper.Handlers.ComplexType +{ + 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..a1f61b1 100644 --- a/IniWrapper/IniWrapper/Handlers/NullValue/NullValueHandler.cs +++ b/IniWrapper/IniWrapper/Handlers/NullValue/NullValueHandler.cs @@ -8,7 +8,7 @@ internal class NullValueHandler : IHandler { public object ParseReadValue(Type destinationType, string readValue) { - return readValue; + throw new NotImplementedException(); } public IniValue FormatToWrite(object objectToFormat, IniValue defaultIniValue) diff --git a/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs b/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs index 5e3a857..c9b86fb 100644 --- a/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs +++ b/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs @@ -1,11 +1,11 @@ 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; @@ -59,6 +59,14 @@ private IHandler GetHandler(TypeDetailsInformation typeInformation) return new EnumerableHandler(underlyingTypeHandler, typeInformation.UnderlyingTypeInformation.TypeCode, typeInformation.UnderlyingTypeInformation.Type); } + case TypeCode.NullValue: + { + if (typeInformation.UnderlyingTypeInformation?.TypeCode == TypeCode.ComplexObject) + { + return new NullComplexTypeHandler(new ComplexTypeHandler(IniWrapper), typeInformation.UnderlyingTypeInformation.Type); + } + return new NullValueHandler(); + } default: { return GetBaseHandler(typeInformation.TypeCode, typeInformation.UnderlyingTypeInformation?.IsEnum); @@ -70,12 +78,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/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); } From a89abb2f3e16d9906f233f65f014a7d61a7589bb Mon Sep 17 00:00:00 2001 From: Tisu Date: Sun, 15 Jul 2018 22:28:22 +0200 Subject: [PATCH 03/11] Added test for reading enum out of range --- .../WrongFormat/ReadingEnumOutOfRangeTests.cs | 35 +++++++++++++++++++ ...ni.cs => ReadingWrongFormattedIniTests.cs} | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingEnumOutOfRangeTests.cs rename IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/{ReadingWrongFormattedIni.cs => ReadingWrongFormattedIniTests.cs} (95%) 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..e7c33b3 --- /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 = MockParserFactory.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 95% rename from IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingWrongFormattedIni.cs rename to IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingWrongFormattedIniTests.cs index 55872fa..d5377ee 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; From 9025cd403b9958939b82fdfa64437fa9d1445e12 Mon Sep 17 00:00:00 2001 From: Tisu Date: Sun, 15 Jul 2018 23:13:49 +0200 Subject: [PATCH 04/11] Add test for default values when saving / loading --- .../Properties/DefaultValuesConfiguration.cs | 17 +++++++++ .../IniWrapperReadDefaultValuesTests.cs | 36 +++++++++++++++++++ .../IniWrapperSaveDefaultValuesTests.cs | 33 +++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 IniWrapper/IniWrapper.IntegrationTests/Main/Configuration/Properties/DefaultValuesConfiguration.cs create mode 100644 IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDefaultValuesTests.cs create mode 100644 IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDefaultValuesTests.cs 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/Read/Properties/IniWrapperReadDefaultValuesTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDefaultValuesTests.cs new file mode 100644 index 0000000..0301d08 --- /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 = MockParserFactory.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/Save/Properties/IniWrapperSaveDefaultValuesTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDefaultValuesTests.cs new file mode 100644 index 0000000..74cc998 --- /dev/null +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDefaultValuesTests.cs @@ -0,0 +1,33 @@ +using IniWrapper.IntegrationTests.Main.Configuration.Properties; +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 = new IniWrapperFactory().Create("", _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 From 16b6f0933d4eb456818c5bb4957b9ea617d12f5e Mon Sep 17 00:00:00 2001 From: Tisu Date: Tue, 17 Jul 2018 21:28:32 +0200 Subject: [PATCH 05/11] Introducing IniSettings --- .../Ignore/IniIgnoreReadAttributeTests.cs | 2 +- .../Attribute/IniOptionsAttributeReadTests.cs | 2 +- .../IniOptionsOnlyKeyAttributeReadTests.cs | 2 +- ...IniOptionsOnlySectionAttributeReadTests.cs | 2 +- .../IniWrapperComplexDataSaveFieldsTests.cs | 2 +- ...IniWrapperIEnumerableOfComplexDataTests.cs | 2 +- .../IniWrapperReadFieldsConfigurationTests.cs | 2 +- ...niWrapperComplexDataReadPropertiesTests.cs | 2 +- .../IniWrapperIEnumerableNullableTests.cs | 2 +- ...perIEnumerableReadingOfComplexDataTests.cs | 2 +- .../IniWrapperReadDefaultValuesTests.cs | 2 +- .../IniWrapperReadDictionaryTests.cs | 2 +- ...WrapperReadPropertiesConfigurationTests.cs | 2 +- .../WrongFormat/ReadingEnumOutOfRangeTests.cs | 2 +- .../ReadingWrongFormattedIniTests.cs | 2 +- .../Ignore/IniIgnoreAttributeTests.cs | 3 +- .../Attribute/IniOptionsAttributeTests.cs | 3 +- .../IniOptionsOnlyKeyAttributeTests.cs | 3 +- .../IniOptionsOnlySectionAttributeTests.cs | 3 +- .../IniWrapperComplexDataSaveFieldsTests.cs | 3 +- ...IniWrapperIEnumerableOfComplexDataTests.cs | 3 +- ...WrapperSaveDictionaryConfigurationTests.cs | 2 +- .../IniWrapperSaveFieldsConfigurationTests.cs | 3 +- ...perSaveNullableFieldsConfigurationTests.cs | 3 +- ...niWrapperComplexDataSavePropertiesTests.cs | 3 +- .../IniWrapperDictionaryWithNullsTests.cs | 3 +- ...IniWrapperIEnumerableOfComplexDataTests.cs | 3 +- .../IniWrapperIEnumerableWithNullsTests.cs | 3 +- .../IniWrapperSaveDefaultValuesTests.cs | 3 +- ...WrapperSaveDictionaryConfigurationTests.cs | 2 +- ...WrapperSaveDictionaryOfComplexdataTests.cs | 2 +- ...aveNullablePropertiesConfigurationTests.cs | 3 +- ...WrapperSavePropertiesConfigurationTests.cs | 3 +- ...ParserFactory.cs => MockWrapperFactory.cs} | 17 ++++-- .../DefaultConfigurationCreationStrategy.cs | 22 +++++++ .../IDefaultConfigurationCreationStrategy.cs | 7 +++ IniWrapper/IniWrapper/Settings/IniSettings.cs | 11 ++++ .../IniWrapper/Wrapper/IIniWrapperFactory.cs | 12 +++- IniWrapper/IniWrapper/Wrapper/IniWrapper.cs | 16 +++-- .../IniWrapper/Wrapper/IniWrapperFactory.cs | 58 ++++++++++++++++--- 40 files changed, 165 insertions(+), 59 deletions(-) rename IniWrapper/IniWrapper.IntegrationTests/MockParser/{MockParserFactory.cs => MockWrapperFactory.cs} (56%) create mode 100644 IniWrapper/IniWrapper/DefaultConfiguration/DefaultConfigurationCreationStrategy.cs create mode 100644 IniWrapper/IniWrapper/DefaultConfiguration/IDefaultConfigurationCreationStrategy.cs create mode 100644 IniWrapper/IniWrapper/Settings/IniSettings.cs 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..29979ff 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperComplexDataSaveFieldsTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperComplexDataSaveFieldsTests.cs @@ -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 aa4d935..6854859 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperIEnumerableOfComplexDataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperIEnumerableOfComplexDataTests.cs @@ -21,7 +21,7 @@ public class IniParserIEnumerableOfComplexDataTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperReadFieldsConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperReadFieldsConfigurationTests.cs index 3e93a55..081eafd 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperReadFieldsConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperReadFieldsConfigurationTests.cs @@ -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..90e0bba 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperComplexDataReadPropertiesTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperComplexDataReadPropertiesTests.cs @@ -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..41e2251 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableNullableTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableNullableTests.cs @@ -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 dad9041..6c34375 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableReadingOfComplexDataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableReadingOfComplexDataTests.cs @@ -21,7 +21,7 @@ public class IniParserIEnumerableReadingOfComplexDataTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDefaultValuesTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDefaultValuesTests.cs index 0301d08..cb99cdf 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDefaultValuesTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDefaultValuesTests.cs @@ -20,7 +20,7 @@ public class IniWrapperReadDefaultValuesTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDictionaryTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDictionaryTests.cs index 2d5394e..891110b 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDictionaryTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDictionaryTests.cs @@ -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..d5faf24 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadPropertiesConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadPropertiesConfigurationTests.cs @@ -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 index e7c33b3..a7dede1 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingEnumOutOfRangeTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingEnumOutOfRangeTests.cs @@ -19,7 +19,7 @@ public class ReadingEnumOutOfRangeTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingWrongFormattedIniTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingWrongFormattedIniTests.cs index d5377ee..2c5126a 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingWrongFormattedIniTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/WrongFormat/ReadingWrongFormattedIniTests.cs @@ -20,7 +20,7 @@ public class ReadingWrongFormattedIniTests 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..e9bbbfd 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; @@ -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 33b7930..b685f31 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; @@ -20,7 +21,7 @@ public class IniParserIEnumerableOfComplexDataTests 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/IniWrapperSaveDictionaryConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveDictionaryConfigurationTests.cs index 4a37a8b..06923ab 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveDictionaryConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveDictionaryConfigurationTests.cs @@ -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..3a6dabb 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; @@ -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..5b60b62 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; @@ -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 64d74da..419ebf7 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; @@ -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/Properties/IniWrapperDictionaryWithNullsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperDictionaryWithNullsTests.cs index b165856..8c67ace 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; @@ -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 86cb600..69e7c34 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; @@ -20,7 +21,7 @@ public class IniParserIEnumerableOfComplexDataTests 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/IniWrapperIEnumerableWithNullsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableWithNullsTests.cs index c1cd857..5b0a88a 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; @@ -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 index 74cc998..624b092 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDefaultValuesTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDefaultValuesTests.cs @@ -1,4 +1,5 @@ using IniWrapper.IntegrationTests.Main.Configuration.Properties; +using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; using IniWrapper.Wrapper; using NSubstitute; @@ -17,7 +18,7 @@ public class IniWrapperSaveDefaultValuesTests 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/IniWrapperSaveDictionaryConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryConfigurationTests.cs index ea3a35d..8283bc4 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryConfigurationTests.cs @@ -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 00e9409..d335769 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryOfComplexdataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryOfComplexdataTests.cs @@ -22,7 +22,7 @@ public class IniParserSaveDictionaryOfComplexdataTests public void SetUp() { _iniParser = Substitute.For(); - _iniWrapper = MockParserFactory.CreateWithFileSystem(_iniParser); + _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); } [Test] diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveNullablePropertiesConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveNullablePropertiesConfigurationTests.cs index 4f87eb5..03307cd 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; @@ -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..9deb0ee 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; @@ -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 56% rename from IniWrapper/IniWrapper.IntegrationTests/MockParser/MockParserFactory.cs rename to IniWrapper/IniWrapper.IntegrationTests/MockParser/MockWrapperFactory.cs index 9807d9e..30dc0f6 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.DefaultConfiguration; 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,18 @@ 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) { - var handlerFactory = new HandlerFactory(new TypeManager()); - 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 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 DefaultConfigurationCreationStrategy(fileSystem, new IniSettings()); + + var iniWrapper = new Wrapper.IniWrapper(savingManager, readingManager, defaultConfigurationCreationStrategy); handlerFactory.IniWrapper = iniWrapper; diff --git a/IniWrapper/IniWrapper/DefaultConfiguration/DefaultConfigurationCreationStrategy.cs b/IniWrapper/IniWrapper/DefaultConfiguration/DefaultConfigurationCreationStrategy.cs new file mode 100644 index 0000000..789833f --- /dev/null +++ b/IniWrapper/IniWrapper/DefaultConfiguration/DefaultConfigurationCreationStrategy.cs @@ -0,0 +1,22 @@ +using System.IO.Abstractions; +using IniWrapper.Settings; + +namespace IniWrapper.DefaultConfiguration +{ + internal class DefaultConfigurationCreationStrategy : IDefaultConfigurationCreationStrategy + { + private readonly IFileSystem _fileSystem; + private readonly IniSettings _iniSettings; + + public DefaultConfigurationCreationStrategy(IFileSystem fileSystem, IniSettings iniSettings) + { + _fileSystem = fileSystem; + _iniSettings = iniSettings; + } + + public bool ShouldCreateDefaultConfiguration() + { + return _iniSettings.ShouldCreateDefaultConfiguration && !_fileSystem.File.Exists(_iniSettings.IniFilePath); + } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/DefaultConfiguration/IDefaultConfigurationCreationStrategy.cs b/IniWrapper/IniWrapper/DefaultConfiguration/IDefaultConfigurationCreationStrategy.cs new file mode 100644 index 0000000..64c3764 --- /dev/null +++ b/IniWrapper/IniWrapper/DefaultConfiguration/IDefaultConfigurationCreationStrategy.cs @@ -0,0 +1,7 @@ +namespace IniWrapper.DefaultConfiguration +{ + internal interface IDefaultConfigurationCreationStrategy + { + bool ShouldCreateDefaultConfiguration(); + } +} \ 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..1689254 --- /dev/null +++ b/IniWrapper/IniWrapper/Settings/IniSettings.cs @@ -0,0 +1,11 @@ +namespace IniWrapper.Settings +{ + public class IniSettings + { + public char EnumerableEntitySeparator { get; set; } = ','; + + public string IniFilePath { get; set; } + + public bool ShouldCreateDefaultConfiguration { get; set; } = true; + } +} \ No newline at end of file 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..f2a288e 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.DefaultConfiguration; 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 IDefaultConfigurationCreationStrategy _configurationCreationStrategy; - public IniWrapper(string filePath, - IFileSystem fileSystem, - ISavingManager savingManager, - IReadingManager readingManager) + public IniWrapper(ISavingManager savingManager, + IReadingManager readingManager, + IDefaultConfigurationCreationStrategy configurationCreationStrategy) { - _filePath = filePath; - _fileSystem = fileSystem; _savingManager = savingManager; _readingManager = readingManager; + _configurationCreationStrategy = configurationCreationStrategy; } public T LoadConfiguration() where T : new() @@ -34,7 +32,7 @@ public IniWrapper(string filePath, public object LoadConfiguration(Type destinationType) { - if (!_fileSystem.File.Exists(_filePath)) + if (_configurationCreationStrategy.ShouldCreateDefaultConfiguration()) { var defaultConfiguration = Activator.CreateInstance(destinationType); SaveConfiguration(defaultConfiguration); diff --git a/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs b/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs index 5ea3111..ff0b57c 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.DefaultConfiguration; using IniWrapper.HandlersFactory; using IniWrapper.Manager; using IniWrapper.Manager.Attribute; @@ -7,29 +9,69 @@ 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()); - 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 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 DefaultConfigurationCreationStrategy(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)); + } + + public IIniWrapper CreateWithDefaultIniParser(Action iniSettings) + { + var settings = new IniSettings(); + + iniSettings(settings); + + return CreateWithDefaultIniParser(settings); + } + + public IIniWrapper CreateWithDefaultIniParser() { - return Create(filePath, new IniParser(filePath)); + return CreateWithDefaultIniParser(new IniSettings()); } } } \ No newline at end of file From afc05b1e7767baba126017eca0244ac2d2453fb1 Mon Sep 17 00:00:00 2001 From: Tisu Date: Tue, 17 Jul 2018 23:53:42 +0200 Subject: [PATCH 06/11] Added setting for replacing null value, renamed test classes according to file names --- .../IniWrapper.IntegrationTests.csproj | 4 ++++ .../IniWrapperComplexDataSaveFieldsTests.cs | 2 +- ...IniWrapperIEnumerableOfComplexDataTests.cs | 2 +- .../IniWrapperReadFieldsConfigurationTests.cs | 2 +- ...niWrapperComplexDataReadPropertiesTests.cs | 2 +- .../IniWrapperIEnumerableNullableTests.cs | 2 +- ...perIEnumerableReadingOfComplexDataTests.cs | 2 +- .../IniWrapperReadDictionaryTests.cs | 2 +- ...WrapperReadPropertiesConfigurationTests.cs | 2 +- .../IniWrapperComplexDataSaveFieldsTests.cs | 2 +- ...IniWrapperIEnumerableOfComplexDataTests.cs | 2 +- ...WrapperSaveDictionaryConfigurationTests.cs | 2 +- .../IniWrapperSaveFieldsConfigurationTests.cs | 2 +- ...perSaveNullableFieldsConfigurationTests.cs | 2 +- ...niWrapperComplexDataSavePropertiesTests.cs | 2 +- .../IniWrapperDictionaryWithNullsTests.cs | 2 +- ...IniWrapperIEnumerableOfComplexDataTests.cs | 2 +- .../IniWrapperIEnumerableWithNullsTests.cs | 2 +- ...WrapperSaveDictionaryConfigurationTests.cs | 2 +- ...WrapperSaveDictionaryOfComplexdataTests.cs | 2 +- ...aveNullablePropertiesConfigurationTests.cs | 2 +- ...WrapperSavePropertiesConfigurationTests.cs | 2 +- .../MockParser/MockWrapperFactory.cs | 5 +++-- .../DefaultConfigurationCreationStrategy.cs | 4 ++-- .../Handlers/Enumerable/EnumerableHandler.cs | 11 +++++----- .../Handlers/NullValue/NullValueHandler.cs | 4 +--- .../NullValue/NullValueReplaceHandler.cs | 21 +++++++++++++++++++ .../HandlersFactory/HandlerFactory.cs | 17 ++++++++++++--- .../IniWrapper/Settings/IIniSettings.cs | 10 +++++++++ IniWrapper/IniWrapper/Settings/IniSettings.cs | 4 +++- .../IniWrapper/Wrapper/IniWrapperFactory.cs | 2 +- 31 files changed, 86 insertions(+), 38 deletions(-) create mode 100644 IniWrapper/IniWrapper/Handlers/NullValue/NullValueReplaceHandler.cs create mode 100644 IniWrapper/IniWrapper/Settings/IIniSettings.cs diff --git a/IniWrapper/IniWrapper.IntegrationTests/IniWrapper.IntegrationTests.csproj b/IniWrapper/IniWrapper.IntegrationTests/IniWrapper.IntegrationTests.csproj index d29a70e..6ddad76 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/IniWrapper.IntegrationTests.csproj +++ b/IniWrapper/IniWrapper.IntegrationTests/IniWrapper.IntegrationTests.csproj @@ -34,4 +34,8 @@ + + + + diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperComplexDataSaveFieldsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperComplexDataSaveFieldsTests.cs index 29979ff..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; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperIEnumerableOfComplexDataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperIEnumerableOfComplexDataTests.cs index 6854859..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; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperReadFieldsConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Fields/IniWrapperReadFieldsConfigurationTests.cs index 081eafd..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; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperComplexDataReadPropertiesTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperComplexDataReadPropertiesTests.cs index 90e0bba..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; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableNullableTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableNullableTests.cs index 41e2251..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; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableReadingOfComplexDataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperIEnumerableReadingOfComplexDataTests.cs index 6c34375..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; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDictionaryTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadDictionaryTests.cs index 891110b..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; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadPropertiesConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Read/Properties/IniWrapperReadPropertiesConfigurationTests.cs index d5faf24..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; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperComplexDataSaveFieldsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperComplexDataSaveFieldsTests.cs index e9bbbfd..0597242 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperComplexDataSaveFieldsTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperComplexDataSaveFieldsTests.cs @@ -9,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Fields { [TestFixture] - public class IniParserComplexDataSavePropertiesTests + public class IniWrapperComplexDataSavePropertiesTests { private IIniWrapper _iniWrapper; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperIEnumerableOfComplexDataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperIEnumerableOfComplexDataTests.cs index b685f31..6c0ec5e 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperIEnumerableOfComplexDataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperIEnumerableOfComplexDataTests.cs @@ -11,7 +11,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Fields { [TestFixture] - public class IniParserIEnumerableOfComplexDataTests + public class IniWrapperIEnumerableOfComplexDataTests { private IIniWrapper _iniWrapper; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveDictionaryConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveDictionaryConfigurationTests.cs index 06923ab..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; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveFieldsConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveFieldsConfigurationTests.cs index 3a6dabb..0791f6e 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveFieldsConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveFieldsConfigurationTests.cs @@ -10,7 +10,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Fields { [TestFixture] - public sealed class IniParserSaveFieldsConfigurationTests + public sealed class IniWrapperSaveFieldsConfigurationTests { private IIniWrapper _iniWrapper; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveNullableFieldsConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveNullableFieldsConfigurationTests.cs index 5b60b62..4e8fae0 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveNullableFieldsConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Fields/IniWrapperSaveNullableFieldsConfigurationTests.cs @@ -9,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Fields { [TestFixture] - public class IniParserSaveNullableFieldsConfigurationTests + public class IniWrapperSaveNullableFieldsConfigurationTests { private IIniWrapper _iniWrapper; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperComplexDataSavePropertiesTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperComplexDataSavePropertiesTests.cs index 419ebf7..73cdc99 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperComplexDataSavePropertiesTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperComplexDataSavePropertiesTests.cs @@ -9,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public class IniParserComplexDataSavePropertiesTests + public class IniWrapperComplexDataSavePropertiesTests { private IIniWrapper _iniWrapper; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperDictionaryWithNullsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperDictionaryWithNullsTests.cs index 8c67ace..208cf75 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperDictionaryWithNullsTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperDictionaryWithNullsTests.cs @@ -9,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public class IniParserDictionaryWithNullsTests + public class IniWrapperDictionaryWithNullsTests { private IIniWrapper _iniWrapper; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableOfComplexDataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableOfComplexDataTests.cs index 69e7c34..e670932 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableOfComplexDataTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableOfComplexDataTests.cs @@ -11,7 +11,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public class IniParserIEnumerableOfComplexDataTests + public class IniWrapperIEnumerableOfComplexDataTests { private IIniWrapper _iniWrapper; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableWithNullsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableWithNullsTests.cs index 5b0a88a..d69cf3c 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableWithNullsTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperIEnumerableWithNullsTests.cs @@ -9,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public class IniParserIEnumerableWithNullsTests + public class IniWrapperIEnumerableWithNullsTests { private IIniWrapper _iniWrapper; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryConfigurationTests.cs index 8283bc4..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; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryOfComplexdataTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveDictionaryOfComplexdataTests.cs index d335769..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; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveNullablePropertiesConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveNullablePropertiesConfigurationTests.cs index 03307cd..ccf08ca 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveNullablePropertiesConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSaveNullablePropertiesConfigurationTests.cs @@ -9,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public class IniParserSaveNullableFieldsConfigurationTests + public class IniWrapperSaveNullableFieldsConfigurationTests { private IIniWrapper _iniWrapper; diff --git a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSavePropertiesConfigurationTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSavePropertiesConfigurationTests.cs index 9deb0ee..43877fd 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSavePropertiesConfigurationTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Main/Save/Properties/IniWrapperSavePropertiesConfigurationTests.cs @@ -9,7 +9,7 @@ namespace IniWrapper.IntegrationTests.Main.Save.Properties { [TestFixture] - public sealed class IniParserSavePropertiesConfigurationTests + public sealed class IniWrapperSavePropertiesConfigurationTests { private IIniWrapper _iniWrapper; diff --git a/IniWrapper/IniWrapper.IntegrationTests/MockParser/MockWrapperFactory.cs b/IniWrapper/IniWrapper.IntegrationTests/MockParser/MockWrapperFactory.cs index 30dc0f6..dd1b07c 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/MockParser/MockWrapperFactory.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/MockParser/MockWrapperFactory.cs @@ -27,13 +27,14 @@ public static IIniWrapper CreateWithFileSystem(IIniParser iniParser) public static IIniWrapper Create(IIniParser iniParser, IFileSystem fileSystem) { - var handlerFactory = new HandlerFactory(new TypeManager()); + var defaultIniSettings = new IniSettings(); + var handlerFactory = new HandlerFactory(new TypeManager(), defaultIniSettings); 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 DefaultConfigurationCreationStrategy(fileSystem, new IniSettings()); + var defaultConfigurationCreationStrategy = new DefaultConfigurationCreationStrategy(fileSystem, defaultIniSettings); var iniWrapper = new Wrapper.IniWrapper(savingManager, readingManager, defaultConfigurationCreationStrategy); diff --git a/IniWrapper/IniWrapper/DefaultConfiguration/DefaultConfigurationCreationStrategy.cs b/IniWrapper/IniWrapper/DefaultConfiguration/DefaultConfigurationCreationStrategy.cs index 789833f..b3773d0 100644 --- a/IniWrapper/IniWrapper/DefaultConfiguration/DefaultConfigurationCreationStrategy.cs +++ b/IniWrapper/IniWrapper/DefaultConfiguration/DefaultConfigurationCreationStrategy.cs @@ -6,9 +6,9 @@ namespace IniWrapper.DefaultConfiguration internal class DefaultConfigurationCreationStrategy : IDefaultConfigurationCreationStrategy { private readonly IFileSystem _fileSystem; - private readonly IniSettings _iniSettings; + private readonly IIniSettings _iniSettings; - public DefaultConfigurationCreationStrategy(IFileSystem fileSystem, IniSettings iniSettings) + public DefaultConfigurationCreationStrategy(IFileSystem fileSystem, IIniSettings iniSettings) { _fileSystem = fileSystem; _iniSettings = iniSettings; diff --git a/IniWrapper/IniWrapper/Handlers/Enumerable/EnumerableHandler.cs b/IniWrapper/IniWrapper/Handlers/Enumerable/EnumerableHandler.cs index b76e93d..33c6c14 100644 --- a/IniWrapper/IniWrapper/Handlers/Enumerable/EnumerableHandler.cs +++ b/IniWrapper/IniWrapper/Handlers/Enumerable/EnumerableHandler.cs @@ -6,23 +6,24 @@ 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) @@ -34,7 +35,7 @@ public object ParseReadValue(Type destinationType, string readValue) 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)); } @@ -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/NullValueHandler.cs b/IniWrapper/IniWrapper/Handlers/NullValue/NullValueHandler.cs index a1f61b1..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 @@ -13,8 +12,7 @@ public object ParseReadValue(Type destinationType, string readValue) 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 c9b86fb..a8fc88f 100644 --- a/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs +++ b/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs @@ -9,6 +9,7 @@ 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,15 +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.ReplaceNullValuesWithEmptyString) + { + return new NullValueHandler(); + } + if (typeInformation.UnderlyingTypeInformation?.TypeCode == TypeCode.ComplexObject) { return new NullComplexTypeHandler(new ComplexTypeHandler(IniWrapper), typeInformation.UnderlyingTypeInformation.Type); } - return new NullValueHandler(); + return new NullValueReplaceHandler(); } default: { diff --git a/IniWrapper/IniWrapper/Settings/IIniSettings.cs b/IniWrapper/IniWrapper/Settings/IIniSettings.cs new file mode 100644 index 0000000..9d564b7 --- /dev/null +++ b/IniWrapper/IniWrapper/Settings/IIniSettings.cs @@ -0,0 +1,10 @@ +namespace IniWrapper.Settings +{ + internal interface IIniSettings + { + char EnumerableEntitySeparator { get; } + string IniFilePath { get; } + bool ShouldCreateDefaultConfiguration { get; } + bool ReplaceNullValuesWithEmptyString { get; } + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Settings/IniSettings.cs b/IniWrapper/IniWrapper/Settings/IniSettings.cs index 1689254..15c64d8 100644 --- a/IniWrapper/IniWrapper/Settings/IniSettings.cs +++ b/IniWrapper/IniWrapper/Settings/IniSettings.cs @@ -1,11 +1,13 @@ namespace IniWrapper.Settings { - public class IniSettings + public class IniSettings : IIniSettings { public char EnumerableEntitySeparator { get; set; } = ','; public string IniFilePath { get; set; } public bool ShouldCreateDefaultConfiguration { get; set; } = true; + + public bool ReplaceNullValuesWithEmptyString { get; set; } = true; } } \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs b/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs index ff0b57c..3bdf9b7 100644 --- a/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs +++ b/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs @@ -18,7 +18,7 @@ public class IniWrapperFactory : IIniWrapperFactory { public IIniWrapper Create(IniSettings iniSettings, IIniParser iniParser) { - var handlerFactory = new HandlerFactory(new TypeManager()); + var handlerFactory = new HandlerFactory(new TypeManager(), iniSettings); var savingManager = new SavingManager(new IniValueManager(new IniValueAttributeManager()), new SavingStrategyFactory(handlerFactory, iniParser)); From 6591c2aae4dd92716ed797d11f9d0b3e64335ec7 Mon Sep 17 00:00:00 2001 From: Tisu Date: Wed, 18 Jul 2018 00:15:43 +0200 Subject: [PATCH 07/11] Added tests for EnumerableEntitySeparator setting --- .../IniWrapper.IntegrationTests.csproj | 4 -- .../EnumerableSeparatorSettingsTests.cs | 58 +++++++++++++++++++ README.md | 2 +- 3 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparator/EnumerableSeparatorSettingsTests.cs diff --git a/IniWrapper/IniWrapper.IntegrationTests/IniWrapper.IntegrationTests.csproj b/IniWrapper/IniWrapper.IntegrationTests/IniWrapper.IntegrationTests.csproj index 6ddad76..d29a70e 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/IniWrapper.IntegrationTests.csproj +++ b/IniWrapper/IniWrapper.IntegrationTests/IniWrapper.IntegrationTests.csproj @@ -34,8 +34,4 @@ - - - - diff --git a/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparator/EnumerableSeparatorSettingsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparator/EnumerableSeparatorSettingsTests.cs new file mode 100644 index 0000000..40ce097 --- /dev/null +++ b/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparator/EnumerableSeparatorSettingsTests.cs @@ -0,0 +1,58 @@ +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.Settings.EnumerableSeparator +{ + [TestFixture] + public class EnumerableSeparatorSettingsTests + { + [TestCase('|')] + [TestCase('*')] + public void SettingsEnumerableEntitySeparator_ShouldDetermineEntitySeparatorWhenSaving(char separator) + { + var iniParser = Substitute.For(); + var iniWrapper = new IniWrapperFactory().Create(x => + { + x.ShouldCreateDefaultConfiguration = false; + 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.ShouldCreateDefaultConfiguration = false; + 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/README.md b/README.md index 9cfb62d..7d2e2bc 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ var iniWrapper = iniWrapperFactory.Create("test.ini", 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"); From 526c7ca20775b06dee61f0afef85bf00330a9125 Mon Sep 17 00:00:00 2001 From: Tisu Date: Wed, 18 Jul 2018 21:58:11 +0200 Subject: [PATCH 08/11] Changed bools in settings to enums, added tests for MissingFileWhenLoadingHandling --- .../MockParser/MockWrapperFactory.cs | 11 +- .../EnumerableSeparatorSettingsTests.cs | 5 +- .../Settings/MissingFileSettingsTests.cs | 133 ++++++++++++++++++ .../ConfigurationLoadingChecker.cs | 27 ++++ .../IConfigurationLoadingChecker.cs | 8 ++ .../DefaultConfigurationCreationStrategy.cs | 22 --- .../IDefaultConfigurationCreationStrategy.cs | 7 - .../HandlersFactory/HandlerFactory.cs | 2 +- .../IniWrapper/Settings/IIniSettings.cs | 4 +- IniWrapper/IniWrapper/Settings/IniSettings.cs | 4 +- .../MissingFileWhenLoadingHandling.cs | 9 ++ .../IniWrapper/Settings/NullValueHandling.cs | 8 ++ IniWrapper/IniWrapper/Wrapper/IniWrapper.cs | 25 ++-- .../IniWrapper/Wrapper/IniWrapperFactory.cs | 4 +- 14 files changed, 217 insertions(+), 52 deletions(-) create mode 100644 IniWrapper/IniWrapper.IntegrationTests/Settings/MissingFileSettingsTests.cs create mode 100644 IniWrapper/IniWrapper/ConfigLoadingChecker/ConfigurationLoadingChecker.cs create mode 100644 IniWrapper/IniWrapper/ConfigLoadingChecker/IConfigurationLoadingChecker.cs delete mode 100644 IniWrapper/IniWrapper/DefaultConfiguration/DefaultConfigurationCreationStrategy.cs delete mode 100644 IniWrapper/IniWrapper/DefaultConfiguration/IDefaultConfigurationCreationStrategy.cs create mode 100644 IniWrapper/IniWrapper/Settings/MissingFileWhenLoadingHandling.cs create mode 100644 IniWrapper/IniWrapper/Settings/NullValueHandling.cs diff --git a/IniWrapper/IniWrapper.IntegrationTests/MockParser/MockWrapperFactory.cs b/IniWrapper/IniWrapper.IntegrationTests/MockParser/MockWrapperFactory.cs index dd1b07c..357394a 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/MockParser/MockWrapperFactory.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/MockParser/MockWrapperFactory.cs @@ -1,5 +1,5 @@ using System.IO.Abstractions; -using IniWrapper.DefaultConfiguration; +using IniWrapper.ConfigLoadingChecker; using IniWrapper.HandlersFactory; using IniWrapper.Manager; using IniWrapper.Manager.Attribute; @@ -27,14 +27,17 @@ public static IIniWrapper CreateWithFileSystem(IIniParser iniParser) public static IIniWrapper Create(IIniParser iniParser, IFileSystem fileSystem) { - var defaultIniSettings = new IniSettings(); - var handlerFactory = new HandlerFactory(new TypeManager(), defaultIniSettings); + return Create(new IniSettings(), iniParser, fileSystem); + } + public static IIniWrapper Create(IniSettings iniSettings, IIniParser iniParser, IFileSystem fileSystem) + { + 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 DefaultConfigurationCreationStrategy(fileSystem, defaultIniSettings); + var defaultConfigurationCreationStrategy = new ConfigurationLoadingChecker(fileSystem, iniSettings); var iniWrapper = new Wrapper.IniWrapper(savingManager, readingManager, defaultConfigurationCreationStrategy); diff --git a/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparator/EnumerableSeparatorSettingsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparator/EnumerableSeparatorSettingsTests.cs index 40ce097..b219208 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparator/EnumerableSeparatorSettingsTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparator/EnumerableSeparatorSettingsTests.cs @@ -3,6 +3,7 @@ using IniWrapper.IntegrationTests.Main.Configuration.Properties; using IniWrapper.IntegrationTests.MockParser; using IniWrapper.ParserWrapper; +using IniWrapper.Settings; using IniWrapper.Wrapper; using NSubstitute; using NUnit.Framework; @@ -19,7 +20,7 @@ public void SettingsEnumerableEntitySeparator_ShouldDetermineEntitySeparatorWhen var iniParser = Substitute.For(); var iniWrapper = new IniWrapperFactory().Create(x => { - x.ShouldCreateDefaultConfiguration = false; + x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.IgnoreCheck; x.EnumerableEntitySeparator = separator; }, iniParser); @@ -42,7 +43,7 @@ public void SettingsEnumerableEntitySeparator_ShouldDetermineEntitySeparatorWhen var iniParser = Substitute.For(); var iniWrapper = new IniWrapperFactory().Create(x => { - x.ShouldCreateDefaultConfiguration = false; + x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.IgnoreCheck; x.EnumerableEntitySeparator = separator; }, iniParser); diff --git a/IniWrapper/IniWrapper.IntegrationTests/Settings/MissingFileSettingsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Settings/MissingFileSettingsTests.cs new file mode 100644 index 0000000..c557bcb --- /dev/null +++ b/IniWrapper/IniWrapper.IntegrationTests/Settings/MissingFileSettingsTests.cs @@ -0,0 +1,133 @@ +using System.Collections.Generic; +using System.IO.Abstractions; +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 + { + [Test] + public void DoNotCallIniParser_When_DoNotLoadIsSet() + { + var iniParser = Substitute.For(); + + var inisettings = new IniSettings() + { + MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.DoNotLoad + }; + + 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 + }; + + 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.IgnoreCheck + }; + + 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.IgnoreCheck + }; + + 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/ConfigLoadingChecker/ConfigurationLoadingChecker.cs b/IniWrapper/IniWrapper/ConfigLoadingChecker/ConfigurationLoadingChecker.cs new file mode 100644 index 0000000..1a80412 --- /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.IgnoreCheck || _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/DefaultConfiguration/DefaultConfigurationCreationStrategy.cs b/IniWrapper/IniWrapper/DefaultConfiguration/DefaultConfigurationCreationStrategy.cs deleted file mode 100644 index b3773d0..0000000 --- a/IniWrapper/IniWrapper/DefaultConfiguration/DefaultConfigurationCreationStrategy.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.IO.Abstractions; -using IniWrapper.Settings; - -namespace IniWrapper.DefaultConfiguration -{ - internal class DefaultConfigurationCreationStrategy : IDefaultConfigurationCreationStrategy - { - private readonly IFileSystem _fileSystem; - private readonly IIniSettings _iniSettings; - - public DefaultConfigurationCreationStrategy(IFileSystem fileSystem, IIniSettings iniSettings) - { - _fileSystem = fileSystem; - _iniSettings = iniSettings; - } - - public bool ShouldCreateDefaultConfiguration() - { - return _iniSettings.ShouldCreateDefaultConfiguration && !_fileSystem.File.Exists(_iniSettings.IniFilePath); - } - } -} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/DefaultConfiguration/IDefaultConfigurationCreationStrategy.cs b/IniWrapper/IniWrapper/DefaultConfiguration/IDefaultConfigurationCreationStrategy.cs deleted file mode 100644 index 64c3764..0000000 --- a/IniWrapper/IniWrapper/DefaultConfiguration/IDefaultConfigurationCreationStrategy.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace IniWrapper.DefaultConfiguration -{ - internal interface IDefaultConfigurationCreationStrategy - { - bool ShouldCreateDefaultConfiguration(); - } -} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs b/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs index a8fc88f..236481b 100644 --- a/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs +++ b/IniWrapper/IniWrapper/HandlersFactory/HandlerFactory.cs @@ -67,7 +67,7 @@ private IHandler GetHandler(TypeDetailsInformation typeInformation) } case TypeCode.NullValue: { - if (!_iniSettings.ReplaceNullValuesWithEmptyString) + if (_iniSettings.NullValueHandling == NullValueHandling.Ignore) { return new NullValueHandler(); } diff --git a/IniWrapper/IniWrapper/Settings/IIniSettings.cs b/IniWrapper/IniWrapper/Settings/IIniSettings.cs index 9d564b7..95f44cf 100644 --- a/IniWrapper/IniWrapper/Settings/IIniSettings.cs +++ b/IniWrapper/IniWrapper/Settings/IIniSettings.cs @@ -4,7 +4,7 @@ internal interface IIniSettings { char EnumerableEntitySeparator { get; } string IniFilePath { get; } - bool ShouldCreateDefaultConfiguration { get; } - bool ReplaceNullValuesWithEmptyString { 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 index 15c64d8..4c0c089 100644 --- a/IniWrapper/IniWrapper/Settings/IniSettings.cs +++ b/IniWrapper/IniWrapper/Settings/IniSettings.cs @@ -6,8 +6,8 @@ public class IniSettings : IIniSettings public string IniFilePath { get; set; } - public bool ShouldCreateDefaultConfiguration { get; set; } = true; + public MissingFileWhenLoadingHandling MissingFileWhenLoadingHandling { get; set; } = MissingFileWhenLoadingHandling.CreateWithDefaultValues; - public bool ReplaceNullValuesWithEmptyString { get; set; } = true; + public NullValueHandling NullValueHandling { get; set; } = NullValueHandling.ReplaceWithEmptyString; } } \ 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..7947872 --- /dev/null +++ b/IniWrapper/IniWrapper/Settings/MissingFileWhenLoadingHandling.cs @@ -0,0 +1,9 @@ +namespace IniWrapper.Settings +{ + public enum MissingFileWhenLoadingHandling + { + IgnoreCheck, + DoNotLoad, + 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..700ee0d --- /dev/null +++ b/IniWrapper/IniWrapper/Settings/NullValueHandling.cs @@ -0,0 +1,8 @@ +namespace IniWrapper.Settings +{ + public enum NullValueHandling + { + Ignore, + ReplaceWithEmptyString + } +} \ No newline at end of file diff --git a/IniWrapper/IniWrapper/Wrapper/IniWrapper.cs b/IniWrapper/IniWrapper/Wrapper/IniWrapper.cs index f2a288e..ba605ed 100644 --- a/IniWrapper/IniWrapper/Wrapper/IniWrapper.cs +++ b/IniWrapper/IniWrapper/Wrapper/IniWrapper.cs @@ -1,7 +1,7 @@ using System; using System.IO.Abstractions; using System.Runtime.CompilerServices; -using IniWrapper.DefaultConfiguration; +using IniWrapper.ConfigLoadingChecker; using IniWrapper.Manager.Read; using IniWrapper.Manager.Save; using IniWrapper.Member; @@ -14,15 +14,15 @@ internal sealed class IniWrapper : IIniWrapper { private readonly ISavingManager _savingManager; private readonly IReadingManager _readingManager; - private readonly IDefaultConfigurationCreationStrategy _configurationCreationStrategy; + private readonly IConfigurationLoadingChecker _configurationLoadingChecker; public IniWrapper(ISavingManager savingManager, IReadingManager readingManager, - IDefaultConfigurationCreationStrategy configurationCreationStrategy) + IConfigurationLoadingChecker configurationLoadingChecker) { _savingManager = savingManager; _readingManager = readingManager; - _configurationCreationStrategy = configurationCreationStrategy; + _configurationLoadingChecker = configurationLoadingChecker; } public T LoadConfiguration() where T : new() @@ -32,15 +32,20 @@ public IniWrapper(ISavingManager savingManager, public object LoadConfiguration(Type destinationType) { - if (_configurationCreationStrategy.ShouldCreateDefaultConfiguration()) + 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 3bdf9b7..3f9e09f 100644 --- a/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs +++ b/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs @@ -1,6 +1,6 @@ using System; using System.IO.Abstractions; -using IniWrapper.DefaultConfiguration; +using IniWrapper.ConfigLoadingChecker; using IniWrapper.HandlersFactory; using IniWrapper.Manager; using IniWrapper.Manager.Attribute; @@ -26,7 +26,7 @@ public IIniWrapper Create(IniSettings iniSettings, IIniParser iniParser) var readingManager = new ReadingManager(new IniValueManager(new IniValueAttributeManager()), handlerFactory, new ReadingStrategyFactory(iniParser)); - var defaultConfigurationCreationStrategy = new DefaultConfigurationCreationStrategy(new FileSystem(), iniSettings); + var defaultConfigurationCreationStrategy = new ConfigurationLoadingChecker(new FileSystem(), iniSettings); var iniWrapper = new IniWrapper(savingManager, readingManager, defaultConfigurationCreationStrategy); From 0ea2bb16eaa8ec4e554832843911c94910ddd5ee Mon Sep 17 00:00:00 2001 From: Tisu Date: Wed, 18 Jul 2018 23:03:15 +0200 Subject: [PATCH 09/11] Added tests for NullValueHandling, moving files --- .../EnumerableSeparatorSettingsTests.cs | 3 +- .../Settings/NullValueHandlingTests.cs | 81 +++++++++++++++++++ .../NullComplexTypeHandler.cs | 2 +- .../MissingFileWhenLoadingHandling.cs | 13 +++ .../IniWrapper/Settings/NullValueHandling.cs | 6 ++ 5 files changed, 102 insertions(+), 3 deletions(-) rename IniWrapper/IniWrapper.IntegrationTests/Settings/{EnumerableSeparator => }/EnumerableSeparatorSettingsTests.cs (94%) create mode 100644 IniWrapper/IniWrapper.IntegrationTests/Settings/NullValueHandlingTests.cs rename IniWrapper/IniWrapper/Handlers/{ComplexType => NullValue}/NullComplexTypeHandler.cs (95%) diff --git a/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparator/EnumerableSeparatorSettingsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparatorSettingsTests.cs similarity index 94% rename from IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparator/EnumerableSeparatorSettingsTests.cs rename to IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparatorSettingsTests.cs index b219208..277b120 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparator/EnumerableSeparatorSettingsTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparatorSettingsTests.cs @@ -1,14 +1,13 @@ using System.Collections.Generic; 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.EnumerableSeparator +namespace IniWrapper.IntegrationTests.Settings { [TestFixture] public class EnumerableSeparatorSettingsTests diff --git a/IniWrapper/IniWrapper.IntegrationTests/Settings/NullValueHandlingTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Settings/NullValueHandlingTests.cs new file mode 100644 index 0000000..490add2 --- /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.IgnoreCheck; + 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.IgnoreCheck; + 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.IgnoreCheck; + 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.IgnoreCheck; + 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/Handlers/ComplexType/NullComplexTypeHandler.cs b/IniWrapper/IniWrapper/Handlers/NullValue/NullComplexTypeHandler.cs similarity index 95% rename from IniWrapper/IniWrapper/Handlers/ComplexType/NullComplexTypeHandler.cs rename to IniWrapper/IniWrapper/Handlers/NullValue/NullComplexTypeHandler.cs index 8dc0ffe..003c99c 100644 --- a/IniWrapper/IniWrapper/Handlers/ComplexType/NullComplexTypeHandler.cs +++ b/IniWrapper/IniWrapper/Handlers/NullValue/NullComplexTypeHandler.cs @@ -1,7 +1,7 @@ using System; using IniWrapper.Manager; -namespace IniWrapper.Handlers.ComplexType +namespace IniWrapper.Handlers.NullValue { internal class NullComplexTypeHandler : IHandler { diff --git a/IniWrapper/IniWrapper/Settings/MissingFileWhenLoadingHandling.cs b/IniWrapper/IniWrapper/Settings/MissingFileWhenLoadingHandling.cs index 7947872..2d4808a 100644 --- a/IniWrapper/IniWrapper/Settings/MissingFileWhenLoadingHandling.cs +++ b/IniWrapper/IniWrapper/Settings/MissingFileWhenLoadingHandling.cs @@ -1,9 +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. + /// IgnoreCheck, + /// + /// 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 index 700ee0d..c87649c 100644 --- a/IniWrapper/IniWrapper/Settings/NullValueHandling.cs +++ b/IniWrapper/IniWrapper/Settings/NullValueHandling.cs @@ -2,7 +2,13 @@ { 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 From 754cf315db0b9fb57d967240caaf307b27aca3a5 Mon Sep 17 00:00:00 2001 From: Tisu Date: Sat, 21 Jul 2018 16:12:15 +0200 Subject: [PATCH 10/11] Added configuration for buffer size, check configuration when creating iniwrapper --- .github/ISSUE_TEMPLATE/bug_report.md | 3 +- .../EnumerableSeparatorSettingsTests.cs | 4 +-- .../Settings/MissingFileSettingsTests.cs | 31 ++++++++++++++++--- .../Settings/NullValueHandlingTests.cs | 8 ++--- .../ConfigurationLoadingChecker.cs | 2 +- .../IniWrapper/ParserWrapper/IniParser.cs | 9 ++++-- IniWrapper/IniWrapper/Settings/IniSettings.cs | 4 ++- .../MissingFileWhenLoadingHandling.cs | 2 +- .../IniWrapper/Wrapper/IniWrapperFactory.cs | 14 ++++++++- 9 files changed, 58 insertions(+), 19 deletions(-) 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/Settings/EnumerableSeparatorSettingsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparatorSettingsTests.cs index 277b120..0c90154 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparatorSettingsTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Settings/EnumerableSeparatorSettingsTests.cs @@ -19,7 +19,7 @@ public void SettingsEnumerableEntitySeparator_ShouldDetermineEntitySeparatorWhen var iniParser = Substitute.For(); var iniWrapper = new IniWrapperFactory().Create(x => { - x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.IgnoreCheck; + x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad; x.EnumerableEntitySeparator = separator; }, iniParser); @@ -42,7 +42,7 @@ public void SettingsEnumerableEntitySeparator_ShouldDetermineEntitySeparatorWhen var iniParser = Substitute.For(); var iniWrapper = new IniWrapperFactory().Create(x => { - x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.IgnoreCheck; + x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad; x.EnumerableEntitySeparator = separator; }, iniParser); diff --git a/IniWrapper/IniWrapper.IntegrationTests/Settings/MissingFileSettingsTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Settings/MissingFileSettingsTests.cs index c557bcb..ea14a39 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Settings/MissingFileSettingsTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Settings/MissingFileSettingsTests.cs @@ -1,5 +1,7 @@ -using System.Collections.Generic; +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; @@ -13,6 +15,23 @@ 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() { @@ -20,7 +39,8 @@ public void DoNotCallIniParser_When_DoNotLoadIsSet() var inisettings = new IniSettings() { - MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.DoNotLoad + MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.DoNotLoad, + IniFilePath = "dummyPath" }; var iniWrapper = new IniWrapperFactory().Create(inisettings, iniParser); @@ -38,7 +58,8 @@ public void SaveDefaultConfiguration_When_CreateWithDefaultValuesIsSet() var inisettings = new IniSettings() { - MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.CreateWithDefaultValues + MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.CreateWithDefaultValues, + IniFilePath = "dummyPath" }; var iniWrapper = new IniWrapperFactory().Create(inisettings, iniParser); @@ -56,7 +77,7 @@ public void LoadConfiguration_When_IgnoreCheckIsSet() var inisettings = new IniSettings() { - MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.IgnoreCheck + MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad }; var iniWrapper = new IniWrapperFactory().Create(inisettings, iniParser); @@ -119,7 +140,7 @@ public void LoadConfiguration_When_IgnoreCheckIsSet_And_FileExists() var inisettings = new IniSettings() { - MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.IgnoreCheck + MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad }; var iniWrapper = MockWrapperFactory.Create(inisettings, iniParser, fileSystem); diff --git a/IniWrapper/IniWrapper.IntegrationTests/Settings/NullValueHandlingTests.cs b/IniWrapper/IniWrapper.IntegrationTests/Settings/NullValueHandlingTests.cs index 490add2..3cbe504 100644 --- a/IniWrapper/IniWrapper.IntegrationTests/Settings/NullValueHandlingTests.cs +++ b/IniWrapper/IniWrapper.IntegrationTests/Settings/NullValueHandlingTests.cs @@ -17,7 +17,7 @@ public void SettingsNullValueHandling_Ignore_ShouldNotSaveNullValues_ForComplexT var iniParser = Substitute.For(); var iniWrapper = new IniWrapperFactory().Create(x => { - x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.IgnoreCheck; + x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad; x.NullValueHandling = NullValueHandling.Ignore; }, iniParser); @@ -34,7 +34,7 @@ public void SettingsNullValueHandling_ReplaceWithEmptyString_ShouldSaveDefaultVa var iniParser = Substitute.For(); var iniWrapper = new IniWrapperFactory().Create(x => { - x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.IgnoreCheck; + x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad; x.NullValueHandling = NullValueHandling.ReplaceWithEmptyString; }, iniParser); @@ -51,7 +51,7 @@ public void SettingsNullValueHandling_Ignore_ShouldNotSaveNullValues() var iniParser = Substitute.For(); var iniWrapper = new IniWrapperFactory().Create(x => { - x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.IgnoreCheck; + x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad; x.NullValueHandling = NullValueHandling.Ignore; }, iniParser); @@ -67,7 +67,7 @@ public void SettingsNullValueHandling_ReplaceWithEmptyString_ShouldSaveDefaultVa var iniParser = Substitute.For(); var iniWrapper = new IniWrapperFactory().Create(x => { - x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.IgnoreCheck; + x.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad; x.NullValueHandling = NullValueHandling.ReplaceWithEmptyString; }, iniParser); diff --git a/IniWrapper/IniWrapper/ConfigLoadingChecker/ConfigurationLoadingChecker.cs b/IniWrapper/IniWrapper/ConfigLoadingChecker/ConfigurationLoadingChecker.cs index 1a80412..3835b17 100644 --- a/IniWrapper/IniWrapper/ConfigLoadingChecker/ConfigurationLoadingChecker.cs +++ b/IniWrapper/IniWrapper/ConfigLoadingChecker/ConfigurationLoadingChecker.cs @@ -16,7 +16,7 @@ public ConfigurationLoadingChecker(IFileSystem fileSystem, IIniSettings iniSetti public bool ShouldReadConfigurationFromFile() { - return _iniSettings.MissingFileWhenLoadingHandling == MissingFileWhenLoadingHandling.IgnoreCheck || _fileSystem.File.Exists(_iniSettings.IniFilePath); + return _iniSettings.MissingFileWhenLoadingHandling == MissingFileWhenLoadingHandling.ForceLoad || _fileSystem.File.Exists(_iniSettings.IniFilePath); } public bool ShouldCreateDefaultConfiguration() 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/IniSettings.cs b/IniWrapper/IniWrapper/Settings/IniSettings.cs index 4c0c089..1f1c69f 100644 --- a/IniWrapper/IniWrapper/Settings/IniSettings.cs +++ b/IniWrapper/IniWrapper/Settings/IniSettings.cs @@ -6,8 +6,10 @@ public class IniSettings : IIniSettings public string IniFilePath { get; set; } - public MissingFileWhenLoadingHandling MissingFileWhenLoadingHandling { get; set; } = MissingFileWhenLoadingHandling.CreateWithDefaultValues; + 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 index 2d4808a..ec187d5 100644 --- a/IniWrapper/IniWrapper/Settings/MissingFileWhenLoadingHandling.cs +++ b/IniWrapper/IniWrapper/Settings/MissingFileWhenLoadingHandling.cs @@ -8,7 +8,7 @@ public enum MissingFileWhenLoadingHandling /// /// Library will not check if file exists. It will always try to load from file. /// - IgnoreCheck, + ForceLoad, /// /// If file is missing library will return instance of given configuration class. It won't neither write nor read anything from file. /// diff --git a/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs b/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs index 3f9e09f..a6e421e 100644 --- a/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs +++ b/IniWrapper/IniWrapper/Wrapper/IniWrapperFactory.cs @@ -18,6 +18,8 @@ public class IniWrapperFactory : IIniWrapperFactory { public IIniWrapper Create(IniSettings iniSettings, IIniParser iniParser) { + CheckSettings(iniSettings); + var handlerFactory = new HandlerFactory(new TypeManager(), iniSettings); var savingManager = new SavingManager(new IniValueManager(new IniValueAttributeManager()), @@ -57,7 +59,7 @@ public IIniWrapper CreateWithDefaultIniParser(IniSettings iniSettings) 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)); + return Create(iniSettings, new IniParser(iniSettings.IniFilePath, iniSettings.DefaultIniWrapperBufferSize)); } public IIniWrapper CreateWithDefaultIniParser(Action iniSettings) @@ -73,5 +75,15 @@ public IIniWrapper CreateWithDefaultIniParser() { return CreateWithDefaultIniParser(new IniSettings()); } + private static void CheckSettings(IniSettings iniSettings) + { + 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 From 19995d568cdeab71f2852860ea81cb3a35c725de Mon Sep 17 00:00:00 2001 From: Tisu Date: Sat, 21 Jul 2018 20:50:18 +0200 Subject: [PATCH 11/11] Changed readme --- README.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7d2e2bc..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). ``` 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