Skip to content

Commit 5fcbc46

Browse files
committed
Add explicit test class for testing configuration without test appsettings
1 parent 5c94822 commit 5fcbc46

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

examples/Xunit.Microsoft.DependencyInjection.ExampleTests/ConfigurationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
namespace Xunit.Microsoft.DependencyInjection.ExampleTests;
22

3-
public class ConfigurationTests : TestBed<TestProjectFixtureWithoutAppsettings>
3+
public class ConfigurationTests : TestBed<TestProjectFixture>
44
{
55
private const string Key = "CONFIG_KEY";
66
private const string Value = "Value";
77

8-
public ConfigurationTests(ITestOutputHelper testOutputHelper, TestProjectFixtureWithoutAppsettings fixture)
8+
public ConfigurationTests(ITestOutputHelper testOutputHelper, TestProjectFixture fixture)
99
: base(testOutputHelper, fixture)
1010
{
1111
Environment.SetEnvironmentVariable(Key, Value);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Xunit.Microsoft.DependencyInjection.ExampleTests;
2+
3+
public class ConfigurationTestsWithoutAppsettings : TestBed<TestProjectFixtureWithoutAppsettings>
4+
{
5+
private const string Key = "CONFIG_KEY";
6+
private const string Value = "Value";
7+
8+
public ConfigurationTestsWithoutAppsettings(ITestOutputHelper testOutputHelper, TestProjectFixtureWithoutAppsettings fixture)
9+
: base(testOutputHelper, fixture)
10+
{
11+
Environment.SetEnvironmentVariable(Key, Value);
12+
}
13+
14+
[Fact]
15+
public void EnvironmentVariablesViaConstructorAreAvailable()
16+
{
17+
_fixture.GetServiceProvider(_testOutputHelper);
18+
19+
var value = _fixture.Configuration!.GetValue<string>(Key);
20+
21+
Assert.Equal(Value, value);
22+
}
23+
}

0 commit comments

Comments
 (0)