Skip to content

Commit 1e53810

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

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

test/WebApi.IntegrationTests/Resources/HealthCheckResourceTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
namespace Devpro.TerraformBackend.WebApi.IntegrationTests.Resources
77
{
88
[Trait("Category", "IntegrationTests")]
9-
public class HealthCheckResourceTest(WebApplicationFactory<Program> factory) : IntegrationTestBase(factory)
9+
public class HealthCheckResourceTest(WebApplicationFactory<Program> factory)
10+
: IntegrationTestBase(factory)
1011
{
1112
[Fact]
1213
[Trait("Mode", "Readonly")]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Text;
4+
using System.Text.Json;
5+
using System.Threading.Tasks;
6+
using Bogus;
7+
using FluentAssertions;
8+
using Microsoft.AspNetCore.Mvc.Testing;
9+
using Xunit;
10+
11+
namespace Devpro.TerraformBackend.WebApi.IntegrationTests.Resources;
12+
13+
[Trait("Category", "IntegrationTests")]
14+
public class StateControllerResourceTest(WebApplicationFactory<Program> factory)
15+
: IntegrationTestBase(factory)
16+
{
17+
[Fact]
18+
public async Task HealthCheckResource_Create_ReturnsOk()
19+
{
20+
// Arrange
21+
var client = CreateClient();
22+
var authToken = Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "admin", "admin")));
23+
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", authToken);
24+
var name = Faker.Random.Word();
25+
var lockId = Faker.Random.Guid().ToString();
26+
var payload = new
27+
{
28+
Property1 = "Value1",
29+
Property2 = 123
30+
};
31+
var content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json");
32+
33+
// Act
34+
var response = await client.PostAsync($"/state/{name}?ID={lockId}", content);
35+
36+
// Assert
37+
response.StatusCode.Should().Be(System.Net.HttpStatusCode.Created);
38+
response.Content.Headers.ContentType.Should().BeNull();
39+
//TODO: test resource URL
40+
var result = await response.Content.ReadAsStringAsync();
41+
result.Should().NotBeNull();
42+
result.ToString().Should().BeEmpty();
43+
}
44+
}

0 commit comments

Comments
 (0)