feat: wip on login endpoint
- added basic REPR pattern - added basic vert architecture - implemented basica validation for single test case
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
namespace FiscalOS.API.Login;
|
||||||
|
|
||||||
|
internal static class Endpoint
|
||||||
|
{
|
||||||
|
private const string Route = "/login";
|
||||||
|
|
||||||
|
public static RouteHandlerBuilder MapLoginEndpoint(this WebApplication app)
|
||||||
|
{
|
||||||
|
return app.MapPost(Route, HandleAsync);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<IResult> HandleAsync([FromBody] LoginRequest loginRequest)
|
||||||
|
{
|
||||||
|
Console.WriteLine(loginRequest.Username);
|
||||||
|
Console.WriteLine(loginRequest.Password);
|
||||||
|
return Results.Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace FiscalOS.API.Login;
|
||||||
|
|
||||||
|
public record LoginRequest(
|
||||||
|
[Required]
|
||||||
|
string Username,
|
||||||
|
[Required]
|
||||||
|
string Password
|
||||||
|
);
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
builder.Services.AddValidation();
|
||||||
builder.Services.AddOpenApi();
|
builder.Services.AddOpenApi();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
@@ -11,4 +12,6 @@ if (app.Environment.IsDevelopment())
|
|||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
app.MapLoginEndpoint();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace FiscalOS.API.Tests.Infra;
|
||||||
|
|
||||||
|
public class TestApi : WebApplicationFactory<Program>
|
||||||
|
{
|
||||||
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||||
|
{
|
||||||
|
base.ConfigureWebHost(builder);
|
||||||
|
|
||||||
|
builder.ConfigureLogging(static c => c.ClearProviders());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using System.Net.Http.Json;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace FiscalOS.API.Tests.Integration;
|
||||||
|
|
||||||
|
public class LoginTests(TestApi testApi) : IClassFixture<TestApi>
|
||||||
|
{
|
||||||
|
private readonly TestApi _testApi = testApi;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Login_WhenUserSubmitsWithoutUsernameOrPassword_ItShouldReturn400WithProblemDetails()
|
||||||
|
{
|
||||||
|
var client = _testApi.CreateClient();
|
||||||
|
|
||||||
|
var res = await client.PostAsJsonAsync("/login", new { }, TestContext.Current.CancellationToken);
|
||||||
|
|
||||||
|
res.StatusCode.Should().Be(System.Net.HttpStatusCode.BadRequest);
|
||||||
|
|
||||||
|
var problem = await res.Content.ReadFromJsonAsync<ValidationProblemDetails>(TestContext.Current.CancellationToken);
|
||||||
|
|
||||||
|
problem!.Errors.Should().BeEquivalentTo(new Dictionary<string, string[]>()
|
||||||
|
{
|
||||||
|
["Username"] = ["The Username field is required."],
|
||||||
|
["Password"] = ["The Password field is required."]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user