Add nbgv and add server info endpoint
Some checks failed
Build Vegasco Server / build (push) Failing after 59s

This commit is contained in:
2024-08-23 18:55:05 +02:00
parent d19d68f5a2
commit dcb82414b9
6 changed files with 84 additions and 0 deletions

9
Directory.Build.props Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Condition="!Exists('packages.config')">
<PrivateAssets>all</PrivateAssets>
<Version>3.6.141</Version>
</PackageReference>
</ItemGroup>
</Project>

View File

@@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
using Vegasco.WebApi.Cars;
using Vegasco.WebApi.Common;
using Vegasco.WebApi.Consumptions;
using Vegasco.WebApi.Info;
namespace Vegasco.WebApi.Endpoints;
@@ -46,5 +47,7 @@ public static class EndpointExtensions
CreateConsumption.MapEndpoint(versionedApis);
UpdateConsumption.MapEndpoint(versionedApis);
DeleteConsumption.MapEndpoint(versionedApis);
GetServerInfo.MapEndpoint(versionedApis);
}
}

View File

@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Http.HttpResults;
namespace Vegasco.WebApi.Info;
public class GetServerInfo
{
public record Response(
string FullVersion,
string CommitId,
DateTime CommitDate,
string Environment);
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
{
return builder
.MapGet("info/server", Endpoint)
.WithTags("Info");
}
private static Ok<Response> Endpoint(
IHostEnvironment environment)
{
return TypedResults.Ok(new Response(
ThisAssembly.AssemblyInformationalVersion,
ThisAssembly.GitCommitId,
ThisAssembly.GitCommitDate,
environment.EnvironmentName));
}
}

View File

@@ -0,0 +1,35 @@
using System.Net.Http.Json;
using FluentAssertions;
using FluentAssertions.Extensions;
using Vegasco.WebApi.Info;
namespace WebApi.Tests.Integration.Info;
[Collection(SharedTestCollection.Name)]
public class GetServerInfoTests
{
private readonly WebAppFactory _factory;
public GetServerInfoTests(WebAppFactory factory)
{
_factory = factory;
}
[Fact]
public async Task GetServerInfo_ShouldReturnServerInfo_WhenCalled()
{
// Arrange
// Act
using HttpResponseMessage response = await _factory.HttpClient.GetAsync("/v1/info/server");
// Assert
response.IsSuccessStatusCode.Should().BeTrue();
var serverInfo = await response.Content.ReadFromJsonAsync<GetServerInfo.Response>();
serverInfo!.Environment.Should().NotBeEmpty();
serverInfo.CommitDate.Should().BeAfter(23.August(2024))
.And.NotBeAfter(DateTime.Now);
serverInfo.CommitId.Should().MatchRegex(@"[0-9a-f]{40}");
serverInfo.FullVersion.Should().MatchRegex(@"\d\.\d\.\d(-[0-9a-zA-Z]+)?(\+g?[0-9a-f]{10})?");
}
}

View File

@@ -10,6 +10,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A16251C2-47DB-4017-812B-CA18B280E049}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
version.json = version.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{437DE053-1DAB-4EEF-BEA6-E3B5179692F8}"

7
version.json Normal file
View File

@@ -0,0 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
"version": "0.3",
"release": {
"firstUnstableTag": "alpha"
}
}