Issue #1: scaffold gateway solution and projects
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
using MxGateway.Contracts;
|
||||
|
||||
namespace MxGateway.Tests.Contracts;
|
||||
|
||||
public sealed class GatewayContractInfoTests
|
||||
{
|
||||
[Fact]
|
||||
public void DefaultBackendName_IsMxAccessWorker()
|
||||
{
|
||||
Assert.Equal("mxaccess-worker", GatewayContractInfo.DefaultBackendName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WorkerProtocolVersion_StartsAtVersionOne()
|
||||
{
|
||||
Assert.Equal(1u, GatewayContractInfo.WorkerProtocolVersion);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using MxGateway.Server;
|
||||
|
||||
namespace MxGateway.Tests.Gateway;
|
||||
|
||||
public sealed class GatewayApplicationTests
|
||||
{
|
||||
[Fact]
|
||||
public void Build_MapsLiveHealthEndpoint()
|
||||
{
|
||||
WebApplication app = GatewayApplication.Build([]);
|
||||
|
||||
RouteEndpoint endpoint = Assert.Single(
|
||||
((IEndpointRouteBuilder)app).DataSources
|
||||
.SelectMany(dataSource => dataSource.Endpoints)
|
||||
.OfType<RouteEndpoint>(),
|
||||
candidate => candidate.RoutePattern.RawText == "/health/live");
|
||||
|
||||
Assert.Equal("LiveHealth", endpoint.Metadata.GetMetadata<IEndpointNameMetadata>()?.EndpointName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MxGateway.Contracts\MxGateway.Contracts.csproj" />
|
||||
<ProjectReference Include="..\MxGateway.Server\MxGateway.Server.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace MxGateway.Tests.ProjectStructure;
|
||||
|
||||
public sealed class GatewayProjectReferenceTests
|
||||
{
|
||||
[Fact]
|
||||
public void GatewayProject_TargetsNet10()
|
||||
{
|
||||
XDocument project = LoadProject("MxGateway.Server");
|
||||
|
||||
Assert.Equal("net10.0", ElementValue(project, "TargetFramework"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GatewayProject_DoesNotReferenceMxAccessCom()
|
||||
{
|
||||
XDocument project = LoadProject("MxGateway.Server");
|
||||
|
||||
IReadOnlyList<string> referenceNames = project
|
||||
.Descendants()
|
||||
.Where(element => element.Name.LocalName is "Reference" or "COMReference" or "COMFileReference" or "PackageReference")
|
||||
.Select(element => (string?)element.Attribute("Include") ?? string.Empty)
|
||||
.ToArray();
|
||||
|
||||
Assert.DoesNotContain(referenceNames, reference =>
|
||||
reference.Contains("MxAccess", StringComparison.OrdinalIgnoreCase)
|
||||
|| reference.Contains("ArchestrA.MXAccess", StringComparison.OrdinalIgnoreCase)
|
||||
|| reference.Contains("LMXProxy", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static XDocument LoadProject(string projectName)
|
||||
{
|
||||
DirectoryInfo repositoryRoot = FindRepositoryRoot();
|
||||
string projectPath = Path.Combine(repositoryRoot.FullName, projectName, $"{projectName}.csproj");
|
||||
|
||||
return XDocument.Load(projectPath);
|
||||
}
|
||||
|
||||
private static string ElementValue(XDocument project, string elementName)
|
||||
{
|
||||
return project
|
||||
.Descendants()
|
||||
.Single(element => element.Name.LocalName == elementName)
|
||||
.Value;
|
||||
}
|
||||
|
||||
private static DirectoryInfo FindRepositoryRoot()
|
||||
{
|
||||
DirectoryInfo? current = new(AppContext.BaseDirectory);
|
||||
|
||||
while (current is not null)
|
||||
{
|
||||
if (File.Exists(Path.Combine(current.FullName, "MxGateway.sln")))
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
current = current.Parent;
|
||||
}
|
||||
|
||||
throw new DirectoryNotFoundException("Could not locate src/MxGateway.sln from the test output directory.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user