Skip to content

Commit afa80e8

Browse files
authored
Merge pull request #1218 from json-api-dotnet/xunit-perf-throttling
Improve speed of running tests
2 parents aecf4c7 + 7cdf273 commit afa80e8

31 files changed

+100
-79
lines changed

test/AnnotationTests/AnnotationTests.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
<LangVersion>latest</LangVersion>
55
</PropertyGroup>
66

7-
<ItemGroup>
8-
<None Update="xunit.runner.json">
9-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
10-
</None>
11-
</ItemGroup>
12-
137
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' ">
148
<Using Remove="System.Net.Http" />
159
</ItemGroup>

test/DiscoveryTests/DiscoveryTests.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
<TargetFramework>$(TargetFrameworkName)</TargetFramework>
44
</PropertyGroup>
55

6-
<ItemGroup>
7-
<None Update="xunit.runner.json">
8-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9-
</None>
10-
</ItemGroup>
11-
126
<ItemGroup>
137
<ProjectReference Include="..\..\src\Examples\JsonApiDotNetCoreExample\JsonApiDotNetCoreExample.csproj" />
148
<ProjectReference Include="..\TestBuildingBlocks\TestBuildingBlocks.csproj" />

test/DiscoveryTests/xunit.runner.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/OperationsDbContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ protected override void OnModelCreating(ModelBuilder builder)
3131
builder.Entity<MusicTrack>()
3232
.HasMany(musicTrack => musicTrack.OccursIn)
3333
.WithMany(playlist => playlist.Tracks);
34+
35+
base.OnModelCreating(builder);
3436
}
3537
}

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Transactions/AtomicTransactionConsistencyTests.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
namespace JsonApiDotNetCoreTests.IntegrationTests.AtomicOperations.Transactions;
1111

12-
public sealed class AtomicTransactionConsistencyTests : IClassFixture<IntegrationTestContext<TestableStartup<OperationsDbContext>, OperationsDbContext>>
12+
public sealed class AtomicTransactionConsistencyTests
13+
: IClassFixture<IntegrationTestContext<TestableStartup<OperationsDbContext>, OperationsDbContext>>, IAsyncLifetime
1314
{
1415
private readonly IntegrationTestContext<TestableStartup<OperationsDbContext>, OperationsDbContext> _testContext;
1516
private readonly OperationsFakers _fakers = new();
@@ -27,7 +28,7 @@ public AtomicTransactionConsistencyTests(IntegrationTestContext<TestableStartup<
2728
services.AddResourceRepository<LyricRepository>();
2829

2930
string postgresPassword = Environment.GetEnvironmentVariable("PGPASSWORD") ?? "postgres";
30-
string dbConnectionString = $"Host=localhost;Port=5432;Database=JsonApiTest-{Guid.NewGuid():N};User ID=postgres;Password={postgresPassword}";
31+
string dbConnectionString = $"Host=localhost;Port=5432;Database=JsonApiTest-Extra-{Guid.NewGuid():N};User ID=postgres;Password={postgresPassword}";
3132

3233
services.AddDbContext<ExtraDbContext>(options => options.UseNpgsql(dbConnectionString));
3334
});
@@ -158,4 +159,22 @@ public async Task Cannot_use_distributed_transaction()
158159
error.Source.ShouldNotBeNull();
159160
error.Source.Pointer.Should().Be("/atomic:operations[0]");
160161
}
162+
163+
public Task InitializeAsync()
164+
{
165+
return Task.CompletedTask;
166+
}
167+
168+
Task IAsyncLifetime.DisposeAsync()
169+
{
170+
return DeleteExtraDatabaseAsync();
171+
}
172+
173+
private async Task DeleteExtraDatabaseAsync()
174+
{
175+
await using AsyncServiceScope scope = _testContext.Factory.Services.CreateAsyncScope();
176+
var dbContext = scope.ServiceProvider.GetRequiredService<ExtraDbContext>();
177+
178+
await dbContext.Database.EnsureDeletedAsync();
179+
}
161180
}

test/JsonApiDotNetCoreTests/IntegrationTests/CompositeKeys/CompositeDbContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ protected override void OnModelCreating(ModelBuilder builder)
3939
builder.Entity<Car>()
4040
.HasMany(car => car.PreviousDealerships)
4141
.WithMany(dealership => dealership.SoldCars);
42+
43+
base.OnModelCreating(builder);
4244
}
4345
}

test/JsonApiDotNetCoreTests/IntegrationTests/EagerLoading/EagerLoadingDbContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ protected override void OnModelCreating(ModelBuilder builder)
3434
.HasOne(building => building.SecondaryDoor)
3535
.WithOne()
3636
.HasForeignKey<Building>("SecondaryDoorId");
37+
38+
base.OnModelCreating(builder);
3739
}
3840
}

test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/ModelStateDbContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ protected override void OnModelCreating(ModelBuilder builder)
3737
builder.Entity<SystemDirectory>()
3838
.HasOne(systemDirectory => systemDirectory.AlsoSelf)
3939
.WithOne();
40+
41+
base.OnModelCreating(builder);
4042
}
4143
}

test/JsonApiDotNetCoreTests/IntegrationTests/Links/LinksDbContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ protected override void OnModelCreating(ModelBuilder builder)
2424
.HasOne(photo => photo.Location)
2525
.WithOne(location => location.Photo)
2626
.HasForeignKey<Photo>("LocationId");
27+
28+
base.OnModelCreating(builder);
2729
}
2830
}

test/JsonApiDotNetCoreTests/IntegrationTests/MultiTenancy/MultiTenancyDbContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ protected override void OnModelCreating(ModelBuilder builder)
3131

3232
builder.Entity<WebProduct>()
3333
.HasQueryFilter(webProduct => webProduct.Shop.TenantId == _tenantProvider.TenantId);
34+
35+
base.OnModelCreating(builder);
3436
}
3537
}

0 commit comments

Comments
 (0)