-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Szpi/FixIEnumerableOfNullableType
Support DateTime, TimeSpan, DateTimeOffset, Guid, Uri
- Loading branch information
Showing
13 changed files
with
317 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
IniWrapper/IniWrapper.ModuleTests/Main/Configuration/Properties/GuidConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
|
||
namespace IniWrapper.ModuleTests.Main.Configuration.Properties | ||
{ | ||
public class GuidConfiguration | ||
{ | ||
public Guid Guid { get; set; } | ||
public Uri Uri { get; set; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
IniWrapper/IniWrapper.ModuleTests/Main/Configuration/Properties/TimeConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
|
||
namespace IniWrapper.ModuleTests.Main.Configuration.Properties | ||
{ | ||
public class TimeConfiguration | ||
{ | ||
public DateTime DateTime { get; set; } | ||
|
||
public TimeSpan TimeSpan { get; set; } | ||
|
||
public DateTimeOffset DateTimeOffset { get; set; } | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...apper/IniWrapper.ModuleTests/Main/Read/Properties/IniWrapperReadGuidConfigurationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using FluentAssertions; | ||
using IniWrapper.ModuleTests.Main.Configuration.Properties; | ||
using IniWrapper.ModuleTests.MockParser; | ||
using IniWrapper.ParserWrapper; | ||
using IniWrapper.Wrapper; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace IniWrapper.ModuleTests.Main.Read.Properties | ||
{ | ||
[TestFixture] | ||
public class IniWrapperReadGuidConfigurationTests | ||
{ | ||
private IIniWrapper _iniWrapper; | ||
|
||
private IIniParser _iniParser; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_iniParser = Substitute.For<IIniParser>(); | ||
_iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); | ||
} | ||
|
||
[Test] | ||
public void LoadConfiguration_ShouldLoadGuid() | ||
{ | ||
var configuration = new GuidConfiguration() | ||
{ | ||
Guid = Guid.NewGuid(), | ||
Uri = new Uri("http://testttt.com/") | ||
}; | ||
|
||
_iniParser.Read(nameof(GuidConfiguration), nameof(GuidConfiguration.Guid)).Returns(configuration.Guid.ToString()); | ||
_iniParser.Read(nameof(GuidConfiguration), nameof(GuidConfiguration.Uri)).Returns(configuration.Uri.ToString()); | ||
|
||
var result = _iniWrapper.LoadConfiguration<GuidConfiguration>(); | ||
|
||
result.Guid.Should().Be(configuration.Guid); | ||
result.Uri.Should().Be(configuration.Uri); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...apper/IniWrapper.ModuleTests/Main/Read/Properties/IniWrapperReadTimeConfigurationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using FluentAssertions; | ||
using IniWrapper.ModuleTests.Main.Configuration.Properties; | ||
using IniWrapper.ModuleTests.MockParser; | ||
using IniWrapper.ParserWrapper; | ||
using IniWrapper.Wrapper; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace IniWrapper.ModuleTests.Main.Read.Properties | ||
{ | ||
[TestFixture] | ||
public class IniWrapperReadTimeConfigurationTests | ||
{ | ||
private IIniWrapper _iniWrapper; | ||
|
||
private IIniParser _iniParser; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_iniParser = Substitute.For<IIniParser>(); | ||
_iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); | ||
} | ||
|
||
[Test] | ||
public void LoadConfiguration_ShouldLoadDateTimeAndTimeSpan() | ||
{ | ||
var dateTime = new DateTime(2019, 02, 07, 18, 58, 58); | ||
var timeSpan = new TimeSpan(10, 10, 10); | ||
var datetimeOffset = new DateTimeOffset(2019, 02, 07, 18, 58,10,TimeSpan.FromMinutes(20)); | ||
|
||
_iniParser.Read(nameof(TimeConfiguration), nameof(TimeConfiguration.DateTime)).Returns(dateTime.ToString("O")); | ||
_iniParser.Read(nameof(TimeConfiguration), nameof(TimeConfiguration.TimeSpan)).Returns(timeSpan.ToString()); | ||
_iniParser.Read(nameof(TimeConfiguration), nameof(TimeConfiguration.DateTimeOffset)).Returns(datetimeOffset.ToString()); | ||
|
||
var result = _iniWrapper.LoadConfiguration<TimeConfiguration>(); | ||
|
||
result.DateTime.Should().Be(dateTime); | ||
result.TimeSpan.Should().Be(timeSpan); | ||
result.DateTimeOffset.Should().Be(datetimeOffset); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...apper/IniWrapper.ModuleTests/Main/Save/Properties/IniWrapperSaveGuidConfigurationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using IniWrapper.ModuleTests.Main.Configuration.Properties; | ||
using IniWrapper.ModuleTests.MockParser; | ||
using IniWrapper.ParserWrapper; | ||
using IniWrapper.Wrapper; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace IniWrapper.ModuleTests.Main.Save.Properties | ||
{ | ||
[TestFixture] | ||
public class IniWrapperSaveGuidConfigurationTests | ||
{ | ||
private IIniWrapper _iniWrapper; | ||
|
||
private IIniParser _iniParser; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_iniParser = Substitute.For<IIniParser>(); | ||
_iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); | ||
} | ||
|
||
[Test] | ||
public void SaveConfiguration_ShouldSaveCorrectWriteDateTime_And_TimeSpan() | ||
{ | ||
var config = new GuidConfiguration() | ||
{ | ||
Guid = Guid.NewGuid(), | ||
Uri = new Uri("http://testttt.com/") | ||
}; | ||
|
||
_iniWrapper.SaveConfiguration(config); | ||
_iniParser.Received(1).Write(nameof(GuidConfiguration), nameof(GuidConfiguration.Guid), config.Guid.ToString()); | ||
_iniParser.Received(1).Write(nameof(GuidConfiguration), nameof(GuidConfiguration.Uri), config.Uri.ToString()); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...apper/IniWrapper.ModuleTests/Main/Save/Properties/IniWrapperSaveTimeConfigurationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using IniWrapper.ModuleTests.Main.Configuration.Properties; | ||
using IniWrapper.ModuleTests.MockParser; | ||
using IniWrapper.ParserWrapper; | ||
using IniWrapper.Wrapper; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace IniWrapper.ModuleTests.Main.Save.Properties | ||
{ | ||
[TestFixture] | ||
public class IniWrapperSaveTimeConfigurationTests | ||
{ | ||
private IIniWrapper _iniWrapper; | ||
|
||
private IIniParser _iniParser; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_iniParser = Substitute.For<IIniParser>(); | ||
_iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser); | ||
} | ||
|
||
[Test] | ||
public void SaveConfiguration_ShouldSaveCorrectWriteDateTime_And_TimeSpan() | ||
{ | ||
var config = new TimeConfiguration() | ||
{ | ||
DateTime = new DateTime(2019, 02, 07, 18, 58, 58), | ||
TimeSpan = new TimeSpan(10, 10, 10), | ||
DateTimeOffset = new DateTimeOffset(2019, 02, 07, 18, 58, 10, TimeSpan.FromMinutes(20)) | ||
}; | ||
|
||
_iniWrapper.SaveConfiguration(config); | ||
|
||
_iniParser.Received(1).Write(nameof(TimeConfiguration), nameof(TimeConfiguration.DateTime), config.DateTime.ToString("O")); | ||
_iniParser.Received(1).Write(nameof(TimeConfiguration), nameof(TimeConfiguration.TimeSpan), config.TimeSpan.ToString()); | ||
_iniParser.Received(1).Write(nameof(TimeConfiguration), nameof(TimeConfiguration.DateTimeOffset), config.DateTimeOffset.ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using IniWrapper.Manager; | ||
|
||
namespace IniWrapper.Converters.Guid | ||
{ | ||
public class GuidConverter : IIniConverter | ||
{ | ||
public object ParseReadValue(string readValue, Type destinationType, IniContext iniContext) | ||
{ | ||
return System.Guid.Parse(readValue); | ||
} | ||
|
||
public IniValue FormatToWrite(object objectToFormat, IniContext iniContext) | ||
{ | ||
iniContext.IniValue.Value = objectToFormat.ToString(); | ||
return iniContext.IniValue; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
IniWrapper/IniWrapper/Converters/Time/DateTimeConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using IniWrapper.Manager; | ||
|
||
namespace IniWrapper.Converters.Time | ||
{ | ||
public class DateTimeConverter : IIniConverter | ||
{ | ||
public object ParseReadValue(string readValue, Type destinationType, IniContext iniContext) | ||
{ | ||
return DateTime.Parse(readValue); | ||
} | ||
|
||
public IniValue FormatToWrite(object objectToFormat, IniContext iniContext) | ||
{ | ||
var dateTime = (DateTime) objectToFormat; | ||
iniContext.IniValue.Value = dateTime.ToString("O"); | ||
return iniContext.IniValue; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
IniWrapper/IniWrapper/Converters/Time/DateTimeOffsetConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using IniWrapper.Manager; | ||
|
||
namespace IniWrapper.Converters.Time | ||
{ | ||
public class DateTimeOffsetConverter : IIniConverter | ||
{ | ||
public object ParseReadValue(string readValue, Type destinationType, IniContext iniContext) | ||
{ | ||
return DateTimeOffset.Parse(readValue); | ||
} | ||
|
||
public IniValue FormatToWrite(object objectToFormat, IniContext iniContext) | ||
{ | ||
iniContext.IniValue.Value = objectToFormat.ToString(); | ||
return iniContext.IniValue; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
IniWrapper/IniWrapper/Converters/Time/TimeSpanConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using IniWrapper.Manager; | ||
|
||
namespace IniWrapper.Converters.Time | ||
{ | ||
public class TimeSpanConverter : IIniConverter | ||
{ | ||
public object ParseReadValue(string readValue, Type destinationType, IniContext iniContext) | ||
{ | ||
return TimeSpan.Parse(readValue); | ||
} | ||
|
||
public IniValue FormatToWrite(object objectToFormat, IniContext iniContext) | ||
{ | ||
iniContext.IniValue.Value = objectToFormat.ToString(); | ||
return iniContext.IniValue; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using IniWrapper.Manager; | ||
|
||
namespace IniWrapper.Converters.Uri | ||
{ | ||
public class UriConverter : IIniConverter | ||
{ | ||
public object ParseReadValue(string readValue, Type destinationType, IniContext iniContext) | ||
{ | ||
return new System.Uri(readValue); | ||
} | ||
|
||
public IniValue FormatToWrite(object objectToFormat, IniContext iniContext) | ||
{ | ||
iniContext.IniValue.Value = objectToFormat.ToString(); | ||
return iniContext.IniValue; | ||
} | ||
} | ||
} |