-
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.
move SubjectFixture to common lib and add tests
- Loading branch information
1 parent
c3c1886
commit 4bee4de
Showing
11 changed files
with
129 additions
and
6 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
2 changes: 2 additions & 0 deletions
2
src/Ephemerally.Azure.Cosmos.Xunit/ConsumingSubjectFixture.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
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
1 change: 1 addition & 0 deletions
1
src/Ephemerally.Azure.Cosmos.Xunit/EphemeralCosmosContainerFixture.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
1 change: 1 addition & 0 deletions
1
src/Ephemerally.Azure.Cosmos.Xunit/EphemeralCosmosDatabaseFixture.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
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>disable</Nullable> | ||
<LangVersion>latest</LangVersion> | ||
<IsTestProject>false</IsTestProject> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Xunit" Version="2.4.2" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
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,92 @@ | ||
using Ephemerally.Xunit; | ||
using Shouldly; | ||
|
||
namespace Ephemerally.Tests.Fixtures; | ||
|
||
public class SubjectFixtureTests | ||
{ | ||
[Test] | ||
public void Fixture_should_be_constructed_as_uninitialized() | ||
{ | ||
var sut = new TestSubjectFixture(); | ||
sut.State.Value.ShouldBe(State.Uninitialized); | ||
} | ||
|
||
[Test] | ||
public async Task InitializeAsync_should_initialize_fixture() | ||
{ | ||
var sut = new TestSubjectFixture(); | ||
|
||
await sut.InitializeAsync(); | ||
|
||
sut.State.Value.ShouldBe(State.Initialized); | ||
} | ||
|
||
[Test] | ||
public async Task DisposeAsync_on_initialized_fixture_should_dispose_fixture() | ||
{ | ||
var sut = new TestSubjectFixture(); | ||
await sut.InitializeAsync(); | ||
|
||
await sut.DisposeAsync(); | ||
|
||
sut.State.Value.ShouldBe(State.Disposed); | ||
} | ||
|
||
[Test] | ||
public async Task DisposeAsync_on_uninitialized_fixture_should_be_uninitialized() | ||
{ | ||
var sut = new TestSubjectFixture(); | ||
|
||
await sut.DisposeAsync(); | ||
|
||
sut.State.Value.ShouldBe(State.Uninitialized); | ||
} | ||
|
||
[Test] | ||
public async Task GetOrCreateSubjectAsync_should_always_return_same_instance() | ||
{ | ||
var sut = new ObjectSubjectFixture(); | ||
await sut.InitializeAsync(); | ||
|
||
var gettingRef1 = sut.GetOrCreateSubjectAsync(); | ||
var gettingRef2 = sut.GetOrCreateSubjectAsync(); | ||
var refs = await Task.WhenAll(gettingRef1, gettingRef2); | ||
|
||
refs[1].ShouldBeSameAs(refs[0]); | ||
} | ||
} | ||
|
||
file class ObjectSubjectFixture : SubjectFixture<object> | ||
{ | ||
protected override Task<object> CreateSubjectAsync() => Task.FromResult(new object()); | ||
} | ||
|
||
file class TestSubjectFixture : SubjectFixture<StateWrapper> | ||
{ | ||
public StateWrapper State { get; } = new(); | ||
|
||
protected override Task<StateWrapper> CreateSubjectAsync() | ||
{ | ||
State.Value = Fixtures.State.Initialized; | ||
return Task.FromResult(State); | ||
} | ||
|
||
protected override Task DisposeSubjectAsync() | ||
{ | ||
State.Value = Fixtures.State.Disposed; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
internal class StateWrapper | ||
{ | ||
public State Value { get; set; } = State.Uninitialized; | ||
} | ||
|
||
internal enum State | ||
{ | ||
Uninitialized = 0, | ||
Initialized = 1, | ||
Disposed = 2 | ||
} |