Skip to content

Commit 11ed03a

Browse files
committed
Add HealthCheckResource_Create_ReturnsOk integration test
1 parent 0db3475 commit 11ed03a

File tree

5 files changed

+8
-3
lines changed

5 files changed

+8
-3
lines changed

src/WebApi/Authentication/BasicAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected override Task<AuthenticateResult> HandleAuthenticateAsync()
4747
return Task.FromResult(AuthenticateResult.Fail(string.Format("The secret is incorrect for the client '{0}'", clientId)));
4848
}
4949

50-
// authenicates the client using basic authentication
50+
// authenticates the client using basic authentication
5151
var client = new BasicAuthenticationClient
5252
{
5353
AuthenticationType = BasicAuthenticationDefaults.AuthenticationScheme,

src/WebApi/Controllers/StateController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ public async Task<string> FindOne(string name, [FromQuery(Name = "ID")] string?
3434
[HttpPost("{name}", Name = "CreateState")]
3535
[ProducesResponseType(201)]
3636
[Consumes("application/json", "text/json")]
37-
public async Task Create(string name, [FromBody] object input, [FromQuery(Name = "ID")] string? lockId = "")
37+
public async Task<IActionResult> Create(string name, [FromBody] object input, [FromQuery(Name = "ID")] string? lockId = "")
3838
{
3939
//TODO: check lock
4040
var jsonInput = JsonSerializer.Serialize(input);
4141
await stateRepository.CreateAsync(name, jsonInput);
42+
return CreatedAtRoute("GetState", new { name }, null);
4243
}
4344

4445
[HttpGet("/locks", Name = "GetStateLocks")]

src/WebApi/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
app.UseAuthentication();
1919
app.UseAuthorization();
2020
app.MapControllers();
21-
app.MapHealthChecks(WebApiConfiguration.HealthCheckEndpoint);
21+
app.MapHealthChecks(WebApiConfiguration.HealthCheckEndpoint).AllowAnonymous();
2222

2323
// runs the application
2424
app.Run();

test/WebApi.IntegrationTests/IntegrationTestBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Net.Http;
2+
using Bogus;
23
using Microsoft.AspNetCore.Mvc.Testing;
34
using Xunit;
45

@@ -9,6 +10,8 @@ namespace Devpro.TerraformBackend.WebApi.IntegrationTests
910
/// </summary>
1011
public abstract class IntegrationTestBase(WebApplicationFactory<Program> factory) : IClassFixture<WebApplicationFactory<Program>>
1112
{
13+
protected Faker Faker { get; } = new("en");
14+
1215
protected HttpClient CreateClient()
1316
{
1417
return factory.CreateClient();

test/WebApi.IntegrationTests/WebApi.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13+
<PackageReference Include="Bogus" Version="35.6.3" />
1314
<PackageReference Include="coverlet.collector" Version="6.0.4">
1415
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1516
<PrivateAssets>all</PrivateAssets>

0 commit comments

Comments
 (0)