-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
106 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<SolutionConfiguration> | ||
<Settings> | ||
<AllowParallelTestExecution>True</AllowParallelTestExecution> | ||
<InstrumentationMode>Optimised</InstrumentationMode> | ||
<SolutionConfigured>True</SolutionConfigured> | ||
</Settings> | ||
</SolutionConfiguration> |
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
45 changes: 45 additions & 0 deletions
45
test/Extensionsions.Configuration.Object.UnitTests/EnumTest.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,45 @@ | ||
using AutoFixture.Xunit2; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using Xunit; | ||
|
||
namespace Extensions.Configuration.Object.UnitTests | ||
{ | ||
public class EnumTest | ||
{ | ||
public enum TestEnum | ||
{ | ||
Undefined = 0, | ||
Foo, | ||
Bar | ||
} | ||
|
||
public class TestOptions | ||
{ | ||
public static string Test => "Test"; | ||
|
||
public TestEnum[] Property { get; set; } | ||
} | ||
|
||
[Theory, AutoData] | ||
public void AddObject_WithEnum_ShoulBeSameInOptions(TestOptions expected) | ||
{ | ||
// Arrange | ||
var configuration = new ConfigurationBuilder() | ||
.AddObject(expected) | ||
.Build(); | ||
|
||
var serviceProvider = new ServiceCollection() | ||
.Configure<TestOptions>(configuration) | ||
.BuildServiceProvider(); | ||
|
||
// Act | ||
var actual = serviceProvider.GetRequiredService<IOptions<TestOptions>>().Value; | ||
|
||
// Assert | ||
actual.Should().BeEquivalentTo(expected); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
test/Extensionsions.Configuration.Object.UnitTests/NullValueTest.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,29 @@ | ||
using FluentAssertions; | ||
using Microsoft.Extensions.Configuration; | ||
using Xunit; | ||
|
||
namespace Extensions.Configuration.Object.UnitTests | ||
{ | ||
public class NullValueTest | ||
{ | ||
class TestOptions | ||
{ | ||
public object Actual { get; set; } | ||
} | ||
|
||
[Fact] | ||
public void AddObject_WithFieldNullValue_ShouldReturnNull() | ||
{ | ||
// Arrange | ||
var configuration = new ConfigurationBuilder() | ||
.AddObject(new TestOptions { Actual = null }) | ||
.Build(); | ||
|
||
// Act | ||
var actual = configuration["Actual"]; | ||
|
||
// Assert | ||
actual.Should().BeNull(); | ||
} | ||
} | ||
} |
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