Skip to content

Commit 5e77638

Browse files
test(integration): add LoginFlow integration test for authenticate endpoint
1 parent 26234f8 commit 5e77638

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

CentralizedLoggingMonitoring.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CentralizedLogging.Contract
1919
EndProject
2020
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserManagementApi.Tests.Unit", "UserManagementApi.Tests.Unit\UserManagementApi.Tests.Unit.csproj", "{66616F9C-B71C-45BF-8962-BAA356215BE6}"
2121
EndProject
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserManagementApi.Tests.Integration", "UserManagementApi.Tests.Integration\UserManagementApi.Tests.Integration.csproj", "{DB6B7B64-C22D-474B-87B1-E48016C8633B}"
23+
EndProject
2224
Global
2325
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2426
Debug|Any CPU = Debug|Any CPU
@@ -57,6 +59,10 @@ Global
5759
{66616F9C-B71C-45BF-8962-BAA356215BE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
5860
{66616F9C-B71C-45BF-8962-BAA356215BE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
5961
{66616F9C-B71C-45BF-8962-BAA356215BE6}.Release|Any CPU.Build.0 = Release|Any CPU
62+
{DB6B7B64-C22D-474B-87B1-E48016C8633B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
63+
{DB6B7B64-C22D-474B-87B1-E48016C8633B}.Debug|Any CPU.Build.0 = Debug|Any CPU
64+
{DB6B7B64-C22D-474B-87B1-E48016C8633B}.Release|Any CPU.ActiveCfg = Release|Any CPU
65+
{DB6B7B64-C22D-474B-87B1-E48016C8633B}.Release|Any CPU.Build.0 = Release|Any CPU
6066
EndGlobalSection
6167
GlobalSection(SolutionProperties) = preSolution
6268
HideSolutionNode = FALSE
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using FluentAssertions;
2+
using Microsoft.AspNetCore.Mvc.Testing;
3+
using System.Net;
4+
using System.Net.Http.Json;
5+
using UserManagement.Contracts.Auth;
6+
7+
namespace UserManagementApi.Tests.Integration
8+
{
9+
public class LoginFlowTests : IClassFixture<WebApplicationFactory<Program>>
10+
{
11+
private readonly HttpClient _client;
12+
public LoginFlowTests(WebApplicationFactory<Program> factory)
13+
=> _client = factory.CreateClient();
14+
15+
[Fact]
16+
public async Task Login_ValidCredentials_Returns200AndToken()
17+
{
18+
var payload = new LoginRequest("bob","bob");
19+
var resp = await _client.PostAsJsonAsync("api/users/authenticate", payload);
20+
21+
resp.StatusCode.Should().Be(HttpStatusCode.OK);
22+
var body = await resp.Content.ReadFromJsonAsync<AuthResponse>();
23+
body.Should().NotBeNull();
24+
body.Token.Should().NotBeNullOrEmpty();
25+
}
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="coverlet.collector" Version="6.0.2" />
12+
<PackageReference Include="FluentAssertions" Version="8.7.1" />
13+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.9" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
15+
<PackageReference Include="xunit" Version="2.9.2" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\UserManagementApi\UserManagementApi.csproj" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<Using Include="Xunit" />
25+
</ItemGroup>
26+
27+
</Project>

UserManagementApi.Tests.Unit/LoginControllerTests.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88
using UserManagementApi.DTO;
99
using UserManagementApi.DTO.Auth;
1010

11-
12-
//using FluentAssertions;
13-
//using Microsoft.AspNetCore.Http;
14-
//using Microsoft.AspNetCore.Mvc;
15-
//using Microsoft.EntityFrameworkCore;
16-
using Xunit;
17-
1811
namespace UserManagementApi.Tests.Unit
1912
{
2013
public class LoginControllerTests

0 commit comments

Comments
 (0)