Skip to content

Commit 514025b

Browse files
committed
Add some sort of architecture tests
1 parent 090aca0 commit 514025b

File tree

6 files changed

+1905
-0
lines changed

6 files changed

+1905
-0
lines changed

app.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<Project Path="src/Services/Services.csproj" />
66
</Folder>
77
<Folder Name="/tests/">
8+
<Project Path="tests/ArchitectureTests/ArchitectureTests.csproj" />
89
<Project Path="tests/IntegrationTests/IntegrationTests.csproj" />
910
<Project Path="tests/UnitTests/UnitTests.csproj" />
1011
</Folder>

src/Api/AssemblyInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("ArchitectureTests")]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<IsPackable>false</IsPackable>
4+
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
5+
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
6+
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\Api\Api.csproj" />
10+
<ProjectReference Include="..\..\src\Common\Common.csproj" />
11+
</ItemGroup>
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
14+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />
15+
<PackageReference Include="xunit.v3" />
16+
<PackageReference Include="xunit.runner.visualstudio">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
<ItemGroup>
22+
<Content Include="..\xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
23+
</ItemGroup>
24+
</Project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Xunit;
2+
3+
namespace ArchitectureTests;
4+
5+
public class AssemblyReferenceTests
6+
{
7+
8+
[Fact]
9+
public void Common_HasNoUnexpectedAssemblyReferences()
10+
{
11+
var commonAssembly = typeof(Common.EnvVarKeys).Assembly;
12+
13+
var referencedAssemblies = commonAssembly
14+
.GetReferencedAssemblies()
15+
.Select(a => a.Name)
16+
.ToList();
17+
18+
var allowed = new[]
19+
{
20+
"System",
21+
"mscorlib",
22+
"netstandard",
23+
"System.Core",
24+
"Microsoft.CSharp",
25+
commonAssembly.GetName().Name!
26+
};
27+
28+
var forbidden = referencedAssemblies
29+
.Where(x => !allowed.Any(y => x?.StartsWith(y, StringComparison.InvariantCulture) ?? false))
30+
.ToList();
31+
32+
Assert.Empty(forbidden);
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Api.Setup;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Services;
5+
using Xunit;
6+
7+
namespace ArchitectureTests;
8+
9+
public class ServiceRegistrationTests
10+
{
11+
[Fact]
12+
public void ShouldHave_Scoped_MarketClient()
13+
{
14+
var builder = WebApplication.CreateBuilder();
15+
builder.Services.ConfigureServices();
16+
17+
var marketClient = builder.Services.SingleOrDefault(x => x.ServiceType == typeof(IMarketClient));
18+
19+
Assert.NotNull(marketClient);
20+
Assert.Equal(ServiceLifetime.Scoped, marketClient.Lifetime);
21+
}
22+
23+
[Fact]
24+
public void ShouldHave_Scoped_MarketService()
25+
{
26+
var builder = WebApplication.CreateBuilder();
27+
builder.Services.ConfigureServices();
28+
29+
var marketService = builder.Services.SingleOrDefault(x => x.ServiceType == typeof(IMarketService));
30+
31+
Assert.NotNull(marketService);
32+
Assert.Equal(ServiceLifetime.Scoped, marketService.Lifetime);
33+
}
34+
}

0 commit comments

Comments
 (0)