Better debug date time error when creating a consumptions #11
@@ -41,5 +41,6 @@ public static class EndpointExtensions
|
|||||||
.RequireAuthorization(Constants.Authorization.RequireAuthenticatedUserPolicy);
|
.RequireAuthorization(Constants.Authorization.RequireAuthenticatedUserPolicy);
|
||||||
|
|
||||||
GetServerInfo.MapEndpoint(versionedApis);
|
GetServerInfo.MapEndpoint(versionedApis);
|
||||||
|
GetCurrentTime.MapEndpoint(versionedApis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/Vegasco.Server.Api/Info/GetCurrentTime.cs
Normal file
21
src/Vegasco.Server.Api/Info/GetCurrentTime.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
|
|
||||||
|
namespace Vegasco.Server.Api.Info;
|
||||||
|
|
||||||
|
public static class GetCurrentTime
|
||||||
|
{
|
||||||
|
public record Response(DateTimeOffset CurrentTime);
|
||||||
|
|
||||||
|
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
||||||
|
{
|
||||||
|
return builder
|
||||||
|
.MapGet("info/time", Endpoint)
|
||||||
|
.WithTags("Info");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Ok<Response> Endpoint(
|
||||||
|
TimeProvider timeProvider)
|
||||||
|
{
|
||||||
|
return TypedResults.Ok(new Response(timeProvider.GetUtcNow()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Vegasco.Server.Api.Info;
|
namespace Vegasco.Server.Api.Info;
|
||||||
|
|
||||||
public class GetServerInfo
|
public static class GetServerInfo
|
||||||
{
|
{
|
||||||
public record Response(
|
public record Response(
|
||||||
string FullVersion,
|
string FullVersion,
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using FluentAssertions;
|
||||||
|
using FluentAssertions.Extensions;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
using Vegasco.Server.Api.Info;
|
||||||
|
|
||||||
|
namespace Vegasco.Server.Api.Tests.Integration.Info;
|
||||||
|
|
||||||
|
[Collection(SharedTestCollection.Name)]
|
||||||
|
public sealed class GetCurrentTimeTests
|
||||||
|
{
|
||||||
|
private readonly WebAppFactory _factory;
|
||||||
|
|
||||||
|
public GetCurrentTimeTests(WebAppFactory factory)
|
||||||
|
{
|
||||||
|
_factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetServerInfo_ShouldReturnServerInfo_WhenCalled()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
|
||||||
|
// Act
|
||||||
|
using HttpResponseMessage response = await _factory.HttpClient.GetAsync("/v1/info/time");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
response.IsSuccessStatusCode.Should().BeTrue();
|
||||||
|
GetCurrentTime.Response? timeInfo = await response.Content.ReadFromJsonAsync<GetCurrentTime.Response>();
|
||||||
|
timeInfo.Should().NotBeNull();
|
||||||
|
timeInfo.CurrentTime.Should().BeCloseTo(DateTimeOffset.UtcNow, TimeSpan.FromSeconds(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user