Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
<PackageVersion Include="TestContainers.MongoDb" Version="$(TestContainersVersion)" />
<PackageVersion Include="TestContainers.MsSql" Version="$(TestContainersVersion)" />
<PackageVersion Include="TestContainers.PostgreSql" Version="$(TestContainersVersion)" />
<PackageVersion Include="xRetry" Version="1.9.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.v3" Version="3.2.2" />
<PackageVersion Include="xunit.v3.core" Version="3.2.2" />
<PackageVersion Include="xunit.v3.assert" Version="3.2.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
<PackageVersion Include="coverlet.collector" Version="10.0.1" />
<PackageVersion Include="coverlet.msbuild" Version="10.0.1" />
<PackageVersion Include="Ulid" Version="1.4.1" />
<!-- Do not change XUnit.Combinatorial to v2 (xUnit v2 compatibility) -->
<PackageVersion Include="XUnit.Combinatorial" Version="1.6.24" />
<PackageVersion Include="XUnit.SkippableFact" Version="1.5.61" />
<!-- XUnit.Combinatorial v2.x targets xUnit v3 (xunit.v3.extensibility.core) -->
<PackageVersion Include="XUnit.Combinatorial" Version="2.0.24" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using CommunityToolkit.Datasync.TestCommon.Databases;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Xunit.Abstractions;

namespace CommunityToolkit.Datasync.Server.Automapper.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace CommunityToolkit.Datasync.Server.CosmosDb.Test;

[ExcludeFromCodeCoverage]
public class CosmosDbRepository_Tests : RepositoryTests<CosmosDbMovie>, IDisposable, IAsyncLifetime
public class CosmosDbRepository_Tests : RepositoryTests<CosmosDbMovie>, IAsyncLifetime
{
#region Setup
private readonly Random random = new();
Expand All @@ -26,20 +26,6 @@ public class CosmosDbRepository_Tests : RepositoryTests<CosmosDbMovie>, IDisposa
private Container _container;
private CosmosTableRepository<CosmosDbMovie> _repository;

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
this._client?.Dispose();
}
}

override protected bool CanRunLiveTests() => !string.IsNullOrEmpty(this.connectionString);

protected override async Task<CosmosDbMovie> GetEntityAsync(string id)
Expand Down Expand Up @@ -69,7 +55,7 @@ protected override Task<string> GetRandomEntityIdAsync(bool exists)
return Task.FromResult(exists ? this.movies[this.random.Next(this.movies.Count)].Id : Guid.NewGuid().ToString());
}

public async Task InitializeAsync()
public async ValueTask InitializeAsync()
{
if (!string.IsNullOrEmpty(this.connectionString))
{
Expand Down Expand Up @@ -137,7 +123,7 @@ public async Task InitializeAsync()
}
}

public async Task DisposeAsync()
public async ValueTask DisposeAsync()
{
if (this._client != null)
{
Expand All @@ -149,6 +135,8 @@ public async Task DisposeAsync()
{
// Ignore
}

this._client.Dispose();
}
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace CommunityToolkit.Datasync.Server.CosmosDb.Test;

[ExcludeFromCodeCoverage]
public class PackedKeyRepository_Tests : RepositoryTests<CosmosDbMovie>, IDisposable, IAsyncLifetime
public class PackedKeyRepository_Tests : RepositoryTests<CosmosDbMovie>, IAsyncLifetime
{
#region Setup
private readonly Random random = new();
Expand All @@ -29,20 +29,6 @@ public class PackedKeyRepository_Tests : RepositoryTests<CosmosDbMovie>, IDispos
private Container _container;
private CosmosTableRepository<CosmosDbMovie> _repository;

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
this._client?.Dispose();
}
}

override protected bool CanRunLiveTests() => !string.IsNullOrEmpty(this.connectionString);
protected override async Task<CosmosDbMovie> GetEntityAsync(string id)
{
Expand Down Expand Up @@ -83,7 +69,7 @@ protected override Task<string> GetRandomEntityIdAsync(bool exists)
return Task.FromResult(exists ? this.movies[this.random.Next(this.movies.Count)].Id : $"{Guid.NewGuid()}:2018");
}

public async Task InitializeAsync()
public async ValueTask InitializeAsync()
{
if (!string.IsNullOrEmpty(this.connectionString))
{
Expand Down Expand Up @@ -152,7 +138,7 @@ public async Task InitializeAsync()
}
}

public async Task DisposeAsync()
public async ValueTask DisposeAsync()
{
if (this._client != null)
{
Expand All @@ -164,29 +150,31 @@ public async Task DisposeAsync()
{
// Ignore
}

this._client.Dispose();
}
}
#endregion

[SkippableTheory]
[Theory]
[InlineData("BadId")]
[InlineData("12345-12345")]
public async Task ReadAsync_Throws_OnMalformedId(string id)
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");

IRepository<CosmosDbMovie> Repository = await GetPopulatedRepositoryAsync();
Func<Task> act = async () => _ = await Repository.ReadAsync(id);

(await act.Should().ThrowAsync<HttpException>()).WithStatusCode(400);
}

[SkippableTheory]
[Theory]
[InlineData("BadId")]
[InlineData("12345-12345")]
public async Task DeleteAsync_Throws_OnMalformedIds(string id)
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");

IRepository<CosmosDbMovie> Repository = await GetPopulatedRepositoryAsync();
Func<Task> act = async () => await Repository.DeleteAsync(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using CommunityToolkit.Datasync.TestCommon.Databases;
using CommunityToolkit.Datasync.TestCommon.Fixtures;
using Microsoft.EntityFrameworkCore;
using Xunit.Abstractions;

#pragma warning disable CS9113 // Parameter is unread.

Expand All @@ -20,13 +19,13 @@ public class AzureSqlEntityTableRepository_Tests(MsSqlDatabaseFixture fixture, I
private readonly Random random = new();
private List<AzureSqlEntityMovie> movies = [];

public async Task InitializeAsync()
public async ValueTask InitializeAsync()
{
Context = await AzureSqlDbContext.CreateContextAsync(fixture.ConnectionString, output);
this.movies = await Context.Movies.AsNoTracking().ToListAsync();
}

public async Task DisposeAsync()
public async ValueTask DisposeAsync()
{
if (Context is not null)
{
Expand All @@ -51,26 +50,26 @@ protected override Task<string> GetRandomEntityIdAsync(bool exists)
=> Task.FromResult(exists ? this.movies[this.random.Next(this.movies.Count)].Id : Guid.NewGuid().ToString());
#endregion

[SkippableFact]
[Fact]
public void EntityTableRepository_BadDbSet_Throws()
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");
Action act = () => _ = new EntityTableRepository<EntityTableData>(Context);
act.Should().Throw<ArgumentException>();
}

[SkippableFact]
[Fact]
public void EntityTableRepository_GoodDbSet_Works()
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");
Action act = () => _ = new EntityTableRepository<AzureSqlEntityMovie>(Context);
act.Should().NotThrow();
}

[SkippableFact]
[Fact]
public async Task WrapExceptionAsync_ThrowsConflictException_WhenDbConcurrencyUpdateExceptionThrown()
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");
EntityTableRepository<AzureSqlEntityMovie> repository = await GetPopulatedRepositoryAsync() as EntityTableRepository<AzureSqlEntityMovie>;
string id = await GetRandomEntityIdAsync(true);
AzureSqlEntityMovie expectedPayload = await GetEntityAsync(id);
Expand All @@ -81,10 +80,10 @@ public async Task WrapExceptionAsync_ThrowsConflictException_WhenDbConcurrencyUp
(await act.Should().ThrowAsync<HttpException>()).WithStatusCode(409).And.WithPayload(expectedPayload);
}

[SkippableFact]
[Fact]
public async Task WrapExceptionAsync_ThrowsRepositoryException_WhenDbUpdateExceptionThrown()
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");
EntityTableRepository<AzureSqlEntityMovie> repository = await GetPopulatedRepositoryAsync() as EntityTableRepository<AzureSqlEntityMovie>;
string id = await GetRandomEntityIdAsync(true);
AzureSqlEntityMovie expectedPayload = await GetEntityAsync(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Ulid" />
<PackageReference Include="xRetry" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using CommunityToolkit.Datasync.TestCommon;
using CommunityToolkit.Datasync.TestCommon.Databases;
using Microsoft.EntityFrameworkCore;
using Xunit.Abstractions;

#pragma warning disable CS9113 // Parameter is unread.

Expand All @@ -19,7 +18,7 @@ public class CosmosEntityTableRepository_Tests(DatabaseFixture fixture, ITestOut
private readonly Random random = new();
private List<CosmosEntityMovie> movies = [];

public async Task InitializeAsync()
public async ValueTask InitializeAsync()
{
if (!string.IsNullOrEmpty(ConnectionStrings.CosmosDb))
{
Expand All @@ -28,7 +27,7 @@ public async Task InitializeAsync()
}
}

public async Task DisposeAsync()
public async ValueTask DisposeAsync()
{
if (Context is not null)
{
Expand All @@ -53,26 +52,26 @@ protected override Task<string> GetRandomEntityIdAsync(bool exists)
=> Task.FromResult(exists ? this.movies[this.random.Next(this.movies.Count)].Id : Guid.NewGuid().ToString());
#endregion

[SkippableFact]
[Fact]
public void EntityTableRepository_BadDbSet_Throws()
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");
Action act = () => _ = new EntityTableRepository<EntityTableData>(Context);
act.Should().Throw<ArgumentException>();
}

[SkippableFact]
[Fact]
public void EntityTableRepository_GoodDbSet_Works()
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");
Action act = () => _ = new EntityTableRepository<CosmosEntityMovie>(Context);
act.Should().NotThrow();
}

[SkippableFact]
[Fact]
public async Task WrapExceptionAsync_ThrowsConflictException_WhenDbConcurrencyUpdateExceptionThrown()
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");
EntityTableRepository<CosmosEntityMovie> repository = await GetPopulatedRepositoryAsync() as EntityTableRepository<CosmosEntityMovie>;
string id = await GetRandomEntityIdAsync(true);
CosmosEntityMovie expectedPayload = await GetEntityAsync(id);
Expand All @@ -83,10 +82,10 @@ public async Task WrapExceptionAsync_ThrowsConflictException_WhenDbConcurrencyUp
(await act.Should().ThrowAsync<HttpException>()).WithStatusCode(409).And.WithPayload(expectedPayload);
}

[SkippableFact]
[Fact]
public async Task WrapExceptionAsync_ThrowsRepositoryException_WhenDbUpdateExceptionThrown()
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");
EntityTableRepository<CosmosEntityMovie> repository = await GetPopulatedRepositoryAsync() as EntityTableRepository<CosmosEntityMovie>;
string id = await GetRandomEntityIdAsync(true);
CosmosEntityMovie expectedPayload = await GetEntityAsync(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using CommunityToolkit.Datasync.TestCommon.Databases;
using CommunityToolkit.Datasync.TestCommon.Fixtures;
using Microsoft.EntityFrameworkCore;
using Xunit.Abstractions;

#pragma warning disable CS9113 // Parameter is unread.

Expand All @@ -20,13 +19,13 @@ public class PgEntityTableRepository_Tests(PostgreSqlDatabaseFixture fixture, IT
private readonly Random random = new();
private List<PgEntityMovie> movies = [];

public async Task InitializeAsync()
public async ValueTask InitializeAsync()
{
Context = await PgDbContext.CreateContextAsync(fixture.ConnectionString, output);
this.movies = await Context.Movies.AsNoTracking().ToListAsync();
}

public async Task DisposeAsync()
public async ValueTask DisposeAsync()
{
if (Context is not null)
{
Expand All @@ -51,26 +50,26 @@ protected override Task<string> GetRandomEntityIdAsync(bool exists)
=> Task.FromResult(exists ? this.movies[this.random.Next(this.movies.Count)].Id : Guid.NewGuid().ToString());
#endregion

[SkippableFact]
[Fact]
public void EntityTableRepository_BadDbSet_Throws()
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");
Action act = () => _ = new EntityTableRepository<EntityTableData>(Context);
act.Should().Throw<ArgumentException>();
}

[SkippableFact]
[Fact]
public void EntityTableRepository_GoodDbSet_Works()
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");
Action act = () => _ = new EntityTableRepository<PgEntityMovie>(Context);
act.Should().NotThrow();
}

[SkippableFact]
[Fact]
public async Task WrapExceptionAsync_ThrowsConflictException_WhenDbConcurrencyUpdateExceptionThrown()
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");
EntityTableRepository<PgEntityMovie> repository = await GetPopulatedRepositoryAsync() as EntityTableRepository<PgEntityMovie>;
string id = await GetRandomEntityIdAsync(true);
PgEntityMovie expectedPayload = await GetEntityAsync(id);
Expand All @@ -81,10 +80,10 @@ public async Task WrapExceptionAsync_ThrowsConflictException_WhenDbConcurrencyUp
(await act.Should().ThrowAsync<HttpException>()).WithStatusCode(409).And.WithPayload(expectedPayload);
}

[SkippableFact]
[Fact]
public async Task WrapExceptionAsync_ThrowsRepositoryException_WhenDbUpdateExceptionThrown()
{
Skip.IfNot(CanRunLiveTests());
Assert.SkipUnless(CanRunLiveTests(), "Live tests are not enabled.");
EntityTableRepository<PgEntityMovie> repository = await GetPopulatedRepositoryAsync() as EntityTableRepository<PgEntityMovie>;
string id = await GetRandomEntityIdAsync(true);
PgEntityMovie expectedPayload = await GetEntityAsync(id);
Expand Down
Loading
Loading