Skip to content

Commit 66f8a79

Browse files
committed
Something probably, at least it's fixed, unit tests are discoverable.
1 parent 1cf5f7e commit 66f8a79

16 files changed

Lines changed: 356 additions & 366 deletions

Cookbook.API.IntegrationTests/Cookbook.API.IntegrationTests.csproj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<ProjectReference Include="..\Cookbook.API\Cookbook.API.csproj" />
11-
<ProjectReference Include="..\Cookbook.Core\Cookbook.Core.csproj" />
12-
<ProjectReference Include="..\Cookbook.Infrastructure\Cookbook.Infrastructure.csproj" />
13-
<ProjectReference Include="..\Cookbook.SharedData\Cookbook.SharedData.csproj" />
10+
<ProjectReference Include="..\Cookbook.API\Cookbook.API.csproj"/>
11+
<ProjectReference Include="..\Cookbook.Core\Cookbook.Core.csproj"/>
12+
<ProjectReference Include="..\Cookbook.Infrastructure\Cookbook.Infrastructure.csproj"/>
13+
<ProjectReference Include="..\Cookbook.SharedData\Cookbook.SharedData.csproj"/>
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0-rc.2.25502.107" />
18-
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.14.28" />
19-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
20-
<PackageReference Include="Moq" Version="4.20.72" />
21-
<PackageReference Include="Testcontainers" Version="4.8.0" />
22-
<PackageReference Include="Testcontainers.PostgreSql" Version="4.8.0" />
23-
<PackageReference Include="xunit" Version="2.9.3" />
17+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0-rc.2.25502.107"/>
18+
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.14.28"/>
19+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0"/>
20+
<PackageReference Include="Moq" Version="4.20.72"/>
21+
<PackageReference Include="Testcontainers" Version="4.8.0"/>
22+
<PackageReference Include="Testcontainers.PostgreSql" Version="4.8.0"/>
23+
<PackageReference Include="xunit" Version="2.9.3"/>
2424
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
2525
<PrivateAssets>all</PrivateAssets>
2626
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

Cookbook.API.IntegrationTests/Fixtures/APiWebApplicationFactory.cs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,54 @@ namespace Cookbook.API.IntegrationTests.Fixtures;
1313

1414
public class APiWebApplicationFactory : WebApplicationFactory<Program>, IAsyncLifetime
1515
{
16-
private readonly PostgreSqlContainer _dbContainer = new PostgreSqlBuilder()
17-
.WithImage("postgres")
18-
.WithDatabase("cookbooktest")
19-
.WithUsername("postgres")
20-
.WithPassword("password")
21-
.WithCleanUp(true)
22-
.Build();
16+
private readonly PostgreSqlContainer _dbContainer = new PostgreSqlBuilder()
17+
.WithImage("postgres")
18+
.WithDatabase("cookbooktest")
19+
.WithUsername("postgres")
20+
.WithPassword("password")
21+
.WithCleanUp(true)
22+
.Build();
2323

24-
public IConfiguration Configuration { get; private set; } = null!;
24+
public IConfiguration Configuration { get; private set; } = null!;
2525

26-
public async Task InitializeAsync()
27-
{
28-
await _dbContainer.StartAsync();
26+
public async Task InitializeAsync()
27+
{
28+
await _dbContainer.StartAsync();
2929

30-
using var scope = Services.CreateScope();
31-
var context = scope.ServiceProvider.GetRequiredService<CookbookContext>();
32-
await context.Database.EnsureDeletedAsync();
33-
await context.Database.EnsureCreatedAsync();
34-
}
30+
using var scope = Services.CreateScope();
31+
var context = scope.ServiceProvider.GetRequiredService<CookbookContext>();
32+
await context.Database.EnsureDeletedAsync();
33+
await context.Database.EnsureCreatedAsync();
34+
}
3535

36-
public new async Task DisposeAsync()
37-
{
38-
await _dbContainer.DisposeAsync();
39-
await base.DisposeAsync();
40-
}
36+
public new async Task DisposeAsync()
37+
{
38+
await _dbContainer.DisposeAsync();
39+
await base.DisposeAsync();
40+
}
4141

42-
protected override void ConfigureWebHost(IWebHostBuilder builder)
43-
{
44-
builder.ConfigureAppConfiguration(config =>
45-
{
46-
Configuration = new ConfigurationBuilder()
47-
.AddJsonFile("appsettings.Integration.json")
48-
.Build();
49-
config.AddConfiguration(Configuration);
50-
});
42+
protected override void ConfigureWebHost(IWebHostBuilder builder)
43+
{
44+
builder.ConfigureAppConfiguration(config =>
45+
{
46+
Configuration = new ConfigurationBuilder()
47+
.AddJsonFile("appsettings.Integration.json")
48+
.Build();
49+
config.AddConfiguration(Configuration);
50+
});
5151

52-
builder.ConfigureTestServices(services =>
53-
{
54-
services.RemoveAll<DbContextOptions<CookbookContext>>();
55-
services.RemoveAll<CookbookContext>();
52+
builder.ConfigureTestServices(services =>
53+
{
54+
services.RemoveAll<DbContextOptions<CookbookContext>>();
55+
services.RemoveAll<CookbookContext>();
5656

57-
services.AddDbContext<CookbookContext>(options => options
58-
.UseNpgsql(_dbContainer.GetConnectionString() + ";Include Error Detail=true")
59-
.UseAsyncSeeding(async (dbContext, _, cancellationToken) =>
60-
{
61-
var context = (CookbookContext)dbContext;
62-
await context.SeedAsync(context, cancellationToken);
63-
}));
64-
});
65-
}
57+
services.AddDbContext<CookbookContext>(options => options
58+
.UseNpgsql(_dbContainer.GetConnectionString() + ";Include Error Detail=true")
59+
.UseAsyncSeeding(async (dbContext, _, cancellationToken) =>
60+
{
61+
var context = (CookbookContext)dbContext;
62+
await context.SeedAsync(context, cancellationToken);
63+
}));
64+
});
65+
}
6666
}

Cookbook.API.UnitTests/AuthenticationControllerTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using FluentValidation;
88
using Microsoft.AspNetCore.Mvc;
99
using Moq;
10-
using Xunit;
1110

1211
namespace Cookbook.API.UnitTests;
1312

Cookbook.API.UnitTests/Cookbook.API.UnitTests.csproj

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,23 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.14.28" />
11-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.0-rc.2.25502.107" />
12-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.0-rc.2.25502.107" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
14-
<PackageReference Include="Moq" Version="4.20.72" />
15-
<PackageReference Include="xunit" Version="2.9.3" />
10+
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.14.28"/>
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.0-rc.2.25502.107"/>
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.0-rc.2.25502.107"/>
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0"/>
14+
<PackageReference Include="Moq" Version="4.20.72"/>
15+
<PackageReference Include="xunit" Version="2.9.3"/>
16+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5"/>
1617
</ItemGroup>
1718

1819
<ItemGroup>
19-
<ProjectReference Include="..\Cookbook.API\Cookbook.API.csproj" />
20-
<ProjectReference Include="..\Cookbook.Core\Cookbook.Core.csproj" />
21-
<ProjectReference Include="..\Cookbook.SharedData\Cookbook.SharedData.csproj" />
20+
<ProjectReference Include="..\Cookbook.API\Cookbook.API.csproj"/>
21+
<ProjectReference Include="..\Cookbook.Core\Cookbook.Core.csproj"/>
22+
<ProjectReference Include="..\Cookbook.SharedData\Cookbook.SharedData.csproj"/>
2223
</ItemGroup>
23-
24+
2425
<ItemGroup>
25-
<Using Include="Xunit" />
26+
<Using Include="Xunit"/>
2627
</ItemGroup>
2728

2829
</Project>

Cookbook.API.UnitTests/CookbookServiceTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Microsoft.AspNetCore.Http;
77
using Microsoft.EntityFrameworkCore;
88
using Moq;
9-
using Xunit;
109

1110
namespace Cookbook.API.UnitTests;
1211

Cookbook.API.UnitTests/PasswordHasherTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Cookbook.Core;
2-
using Xunit;
32

43
namespace Cookbook.API.UnitTests;
54

Cookbook.API/Controllers/RecipesController.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace Cookbook.API.Controllers;
1111
[ApiController]
1212
public class RecipesController(ICookbookService cookbookService) : ControllerBase
1313
{
14-
[Authorize]
15-
[HttpGet]
14+
[Authorize]
15+
[HttpGet]
1616
[ProducesResponseType(StatusCodes.Status200OK)]
1717
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
1818
public async Task<IActionResult> GetAll()
@@ -24,8 +24,8 @@ public async Task<IActionResult> GetAll()
2424
return Ok(response);
2525
}
2626

27-
[Authorize]
28-
[HttpGet("{id}")]
27+
[Authorize]
28+
[HttpGet("{id}")]
2929
[ProducesResponseType(StatusCodes.Status200OK)]
3030
[ProducesResponseType(StatusCodes.Status404NotFound)]
3131
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
@@ -38,8 +38,8 @@ public async Task<IActionResult> GetBy(int id)
3838
return Ok(response);
3939
}
4040

41-
[Authorize]
42-
[HttpGet("{id}/full")]
41+
[Authorize]
42+
[HttpGet("{id}/full")]
4343
[ProducesResponseType(StatusCodes.Status200OK)]
4444
[ProducesResponseType(StatusCodes.Status404NotFound)]
4545
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
@@ -52,8 +52,8 @@ public async Task<IActionResult> GetFullBy(int id)
5252
return Ok(response);
5353
}
5454

55-
[Authorize(Roles = "admin")]
56-
[HttpPost]
55+
[Authorize(Roles = "admin")]
56+
[HttpPost]
5757
[ProducesResponseType(StatusCodes.Status201Created)]
5858
[ProducesResponseType(StatusCodes.Status400BadRequest)]
5959
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
@@ -69,8 +69,8 @@ public async Task<IActionResult> Create(IValidator<CreateRecipeRequest> validato
6969
return CreatedAtAction(nameof(GetBy), new { id = response.RecipeId }, response);
7070
}
7171

72-
[Authorize(Roles = "admin")]
73-
[HttpPut("{id}")]
72+
[Authorize(Roles = "admin")]
73+
[HttpPut("{id}")]
7474
[ProducesResponseType(StatusCodes.Status200OK)]
7575
[ProducesResponseType(StatusCodes.Status400BadRequest)]
7676
[ProducesResponseType(StatusCodes.Status404NotFound)]
@@ -85,8 +85,8 @@ public async Task<IActionResult> Modify(IValidator<UpdateRecipeRequest> validato
8585
return Ok(updatedRecipe.ToRecipeResponse());
8686
}
8787

88-
[Authorize(Roles = "admin")]
89-
[HttpDelete("{id}")]
88+
[Authorize(Roles = "admin")]
89+
[HttpDelete("{id}")]
9090
[ProducesResponseType(StatusCodes.Status204NoContent)]
9191
[ProducesResponseType(StatusCodes.Status404NotFound)]
9292
[ProducesResponseType(StatusCodes.Status500InternalServerError)]

0 commit comments

Comments
 (0)