Skip to content

Commit

Permalink
test(app): stabilize and randomize options test
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Apr 10, 2023
1 parent f89b653 commit 7df9591
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions tests/Sitko.Core.App.Tests/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,30 @@ public async Task NestedModules()
options.Should().HaveCount(3);
}


public static IEnumerable<object[]> BaseOptionsData =>
new List<object[]>
{
new object[]
{
"Baz__Foo", Guid.NewGuid().ToString(), "Baz__Bar", Guid.NewGuid().ToString()
}, // all from base options
new object[]
{
"Baz__Inner__Foo", Guid.NewGuid().ToString(), "Baz__Bar", Guid.NewGuid().ToString()
}, // first from module, second from base
new object[]
{
"Baz__Foo", Guid.NewGuid().ToString(), "Baz__Inner__Bar", Guid.NewGuid().ToString()
}, // first from base, second from module
new object[]
{
"Baz__Inner__Foo", Guid.NewGuid().ToString(), "Baz__Inner__Bar", Guid.NewGuid().ToString()
}, // all from module options
};

[Theory]
[InlineData("Baz__Foo", "123", "Baz__Bar", "456")] // all from base options
[InlineData("Baz__Inner__Foo", "123", "Baz__Bar", "456")] // first from module, second from base
[InlineData("Baz__Foo", "123", "Baz__Inner__Bar", "456")] // first from base, second from module
[InlineData("Baz__Inner__Foo", "123", "Baz__Inner__Bar", "456")] // all from module options
[MemberData(nameof(BaseOptionsData))]
public async Task BaseOptions(string fooKey, string fooValue, string barKey, string barValue)
{
Environment.SetEnvironmentVariable(fooKey, fooValue);
Expand All @@ -39,6 +58,8 @@ public async Task BaseOptions(string fooKey, string fooValue, string barKey, str
var options = sp.GetRequiredService<IOptions<TestModuleBazOptions>>();
options.Value.Foo.Should().Be(fooValue);
options.Value.Bar.Should().Be(barValue);
Environment.SetEnvironmentVariable(fooKey,"");
Environment.SetEnvironmentVariable(barKey, "");
}
}

Expand Down

0 comments on commit 7df9591

Please sign in to comment.