Skip to content

Commit f36b92b

Browse files
authored
refactor testing (#34)
1 parent a23e77a commit f36b92b

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

src/WarehouseEngine.Api/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ [new OpenApiSecuritySchemeReference("Bearer", document)] = []
149149
app.UseDeveloperExceptionPage();
150150
}
151151

152-
await SeedData(app.Services);
152+
if (env.EnvironmentName != "Integration")
153+
{
154+
await SeedData(app.Services);
155+
}
153156

154157
// Configure the HTTP request pipeline.
155158
if (app.Environment.IsDevelopment() || app.Environment.EnvironmentName == "Integration")

tests/WarehouseEngine.Api.Integration.Tests/CustomerEndpointTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
using WarehouseEngine.Api.Integration.Tests.Factories;
77
using WarehouseEngine.Application.Dtos;
88
using WarehouseEngine.Application.Implementations;
9-
using WarehouseEngine.Domain.Entities;
109
using WarehouseEngine.Domain.Models.Auth;
1110
using Xunit;
1211

1312
namespace WarehouseEngine.Api.Integration.Tests;
1413

15-
[Collection(nameof(DatabaseCollection))]
1614
public class CustomerEndpointTests
1715
{
1816
private readonly WarehouseEngineFactory _factory;

tests/WarehouseEngine.Api.Integration.Tests/Factories/WarehouseEngineFactory.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
using Microsoft.AspNetCore.Hosting;
22
using Microsoft.AspNetCore.Mvc.Testing;
33
using Microsoft.Extensions.Configuration;
4+
using WarehouseEngine.Api.Integration.Tests.Factories;
45
using WarehouseEngine.Domain.Entities;
56
using WarehouseEngine.Domain.ValueObjects;
67
using WarehouseEngine.Infrastructure.DataContext;
78
using Xunit;
89

9-
namespace WarehouseEngine.Api.Integration.Tests.Factories;
10-
11-
[CollectionDefinition(nameof(DatabaseCollection))]
12-
public sealed class DatabaseCollection : ICollectionFixture<WarehouseEngineFactory>
13-
{
14-
// Per https://xunit.net/docs/shared-context#collection-fixture
10+
[assembly: AssemblyFixture(typeof(WarehouseEngineFactory))]
1511

16-
// This class has no code, and is never created. Its purpose is simply
17-
// to be the place to apply [CollectionDefinition] and all the
18-
// ICollectionFixture<> interfaces.
19-
}
12+
namespace WarehouseEngine.Api.Integration.Tests.Factories;
2013

2114
public sealed class WarehouseEngineFactory : WebApplicationFactory<Program>, IAsyncLifetime
2215
{

tests/WarehouseEngine.Api.Integration.Tests/VendorEndpointTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace WarehouseEngine.Api.Integration.Tests;
1515

16-
[Collection(nameof(DatabaseCollection))]
1716
public class VendorEndpointTests
1817
{
1918
private readonly WarehouseEngineFactory _factory;
@@ -308,6 +307,6 @@ public async Task OpenApi_V1Json_Success()
308307

309308
// Verify it's valid JSON by deserializing
310309
var openApiDoc = JsonSerializer.Deserialize<JsonElement>(responseContent);
311-
Assert.True(openApiDoc.ValueKind == JsonValueKind.Object);
310+
Assert.Equal(JsonValueKind.Object, openApiDoc.ValueKind);
312311
}
313312
}

0 commit comments

Comments
 (0)