Skip to content

Commit

Permalink
wip: maybe done refactoring + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Confusingboat committed Dec 6, 2024
1 parent 11e69ec commit 8009132
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/Ephemerally.Azure.Cosmos.Xunit/CosmosContainerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@

namespace Ephemerally.Azure.Cosmos.Xunit;

public interface ICosmosContainerFixture<out TContainer>
: ISubjectFixture<Container>
where TContainer : Container
{
TContainer Container { get; }
}

public abstract class CosmosContainerFixture
: CosmosContainerFixture<Container>;

public abstract class CosmosContainerFixture<TContainer>
: CosmosSubjectFixture<TContainer>,
ISubjectFixture<Container> where TContainer : Container
: CosmosSubjectFixture<TContainer>, ICosmosContainerFixture<TContainer>
where TContainer : Container
{
Task<Container> ISubjectFixture<Container>.GetOrCreateSubjectAsync() =>
GetOrCreateSubjectAsync().ContinueWith(Container (x) => x.Result);
Expand Down
11 changes: 9 additions & 2 deletions src/Ephemerally.Azure.Cosmos.Xunit/CosmosDatabaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@

namespace Ephemerally.Azure.Cosmos.Xunit;

public interface ICosmosDatabaseFixture<out TDatabase>
: ISubjectFixture<Database>
where TDatabase : Database
{
TDatabase Database { get; }
}

public abstract class CosmosDatabaseFixture
: CosmosDatabaseFixture<Database>;

public abstract class CosmosDatabaseFixture<TDatabase>
: CosmosSubjectFixture<TDatabase>,
ISubjectFixture<Database> where TDatabase : Database
: CosmosSubjectFixture<TDatabase>, ICosmosDatabaseFixture<TDatabase>
where TDatabase : Database
{
Task<Database> ISubjectFixture<Database>.GetOrCreateSubjectAsync() =>
GetOrCreateSubjectAsync().ContinueWith(Database (x) => x.Result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

namespace Ephemerally.Azure.Cosmos.Tests.Fixtures;

public class DefaultCosmosEmulatorClientFixtureTests : CosmosClientFixtureTests<DefaultCosmosEmulatorClientFixture>;
public class DefaultCosmosEmulatorClientFixtureTests
: CosmosClientFixtureTests<DefaultCosmosEmulatorClientFixture>;

public abstract class CosmosClientFixtureTests<TFixture> where TFixture : CosmosClientFixture, new()
public abstract class CosmosClientFixtureTests<TFixture>
where TFixture : CosmosClientFixture, new()
{
[Test]
public async Task Fixture_provides_usable_cosmos_client()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Ephemerally.Azure.Cosmos.Xunit;
using Microsoft.Azure.Cosmos;
using Shouldly;

namespace Ephemerally.Azure.Cosmos.Tests.Fixtures;

public class DefaultEphemeralCosmosContainerFixtureTests
: CosmosContainerFixtureTests<DefaultEphemeralCosmosContainerFixture>;

public abstract class CosmosContainerFixtureTests<TFixture>
where TFixture : ICosmosContainerFixture<Container>, new()
{
[Test]
public async Task Fixture_provides_usable_cosmos_container()
{
// Arrange
await using var fixture = new TFixture();
await fixture.InitializeAsync();

// Act
var exists = await fixture.Container.ExistsAsync();

// Assert
exists.ShouldBeTrue();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
using Ephemerally.Azure.Cosmos.Xunit;
using Microsoft.Azure.Cosmos;
using Shouldly;

namespace Ephemerally.Azure.Cosmos.Tests.Fixtures;

public abstract class CosmosDatabaseFixtureTests<TFixture> where TFixture : EphemeralCosmosDatabaseFixture
public class DefaultEphemeralCosmosDatabaseFixtureTests
: CosmosDatabaseFixtureTests<DefaultEphemeralCosmosDatabaseFixture>;

public abstract class CosmosDatabaseFixtureTests<TFixture>
where TFixture : ICosmosDatabaseFixture<Database>, new()
{
[Test]
public async Task Fixture_provides_usable_cosmos_database()
{
// Arrange
await using var fixture = new TFixture();
await fixture.InitializeAsync();

// Act
var exists = await fixture.Database.ExistsAsync();

// Assert
exists.ShouldBeTrue();
}
}

0 comments on commit 8009132

Please sign in to comment.