Skip to content

Commit

Permalink
Introduction of architecture tests for stabilization and standardizat…
Browse files Browse the repository at this point in the history
…ion of implementation.

With this particular form of unit tests, it is possible to normalize the architecture of the application and establish standards, thereby fundamentally improving the quality of the application.
  • Loading branch information
samtrion committed Mar 5, 2024
1 parent bba4542 commit 0758f64
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using ArchUnitNET.Domain;
using ArchUnitNET.MSTestV2;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nager.Date.ArchitectureTest.Internals;
using Nager.Date.HolidayProviders;
using static ArchUnitNET.Fluent.ArchRuleDefinition;

namespace Nager.Date.ArchitectureTest
{
[TestClass]
public class IHolidayProviderArchitectureTests
{
private static readonly IObjectProvider<Class> _holidayProviders = Classes()
.That()
.AreAssignableTo(typeof(IHolidayProvider))
.As("Nager.Date HolidayProvider");

[TestMethod]
public void HolidayProvider_Should_Be_Internal()
{
var rule = Classes()
.That()
.Are(_holidayProviders)
.Should()
.BeInternal();

rule.Check(NagerDateArchitecture.Instance);
}

[TestMethod]
public void HolidayProvider_Should_Be_Sealed()
{
var rule = Classes()
.That()
.Are(_holidayProviders)
.Should()
.BeSealed();

rule.Check(NagerDateArchitecture.Instance);
}

[TestMethod]
public void HolidayProvider_Should_Reside_In_Namespace()
{
var rule = Classes()
.That()
.Are(_holidayProviders)
.Should()
.ResideInNamespace("Nager.Date.HolidayProviders");

rule.Check(NagerDateArchitecture.Instance);
}
}
}
24 changes: 24 additions & 0 deletions src/Nager.Date.ArchitectureTest/Internals/NagerDateArchitecture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Threading;
using System;
using ArchUnitNET.Domain;
using ArchUnitNET.Loader;

namespace Nager.Date.ArchitectureTest.Internals
{
internal static class NagerDateArchitecture
{
// TIP: load your architecture once at the start to maximize performance of your tests
private static readonly Lazy<Architecture> _instance = new Lazy<Architecture>(
() => LoadArchitecture(),
LazyThreadSafetyMode.PublicationOnly
);

public static Architecture Instance => _instance.Value;

private static Architecture LoadArchitecture()
{
var architecture = new ArchLoader().LoadAssembly(typeof(HolidaySystem).Assembly).Build();
return architecture;
}
}
}
22 changes: 22 additions & 0 deletions src/Nager.Date.ArchitectureTest/Nager.Date.ArchitectureTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>

<IsPackable>false</IsPackable>

<AssemblyName>Nager.Date.ArchitectureTest</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
<PackageReference Include="TngTech.ArchUnitNET.MSTestV2" Version="0.10.6" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Nager.Date\Nager.Date.csproj" />
</ItemGroup>

</Project>
16 changes: 15 additions & 1 deletion src/Nager.Date.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nager.Date.Console", "Nager.Date.Console\Nager.Date.Console.csproj", "{AD762462-D24B-4EA7-B4D6-B8057917D3DD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nager.Date.Console", "Nager.Date.Console\Nager.Date.Console.csproj", "{AD762462-D24B-4EA7-B4D6-B8057917D3DD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nager.Date.ArchitectureTest", "Nager.Date.ArchitectureTest\Nager.Date.ArchitectureTest.csproj", "{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -66,6 +68,18 @@ Global
{AD762462-D24B-4EA7-B4D6-B8057917D3DD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{AD762462-D24B-4EA7-B4D6-B8057917D3DD}.Release|x86.ActiveCfg = Release|Any CPU
{AD762462-D24B-4EA7-B4D6-B8057917D3DD}.Release|x86.Build.0 = Release|Any CPU
{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}.Debug|x86.ActiveCfg = Debug|Any CPU
{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}.Debug|x86.Build.0 = Debug|Any CPU
{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}.Release|Any CPU.Build.0 = Release|Any CPU
{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}.Release|x86.ActiveCfg = Release|Any CPU
{83724CD7-3F4B-4B45-95B9-E1DA7D8DC8A9}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
11 changes: 8 additions & 3 deletions src/Nager.Date/Nager.Date.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<PackageReleaseNotes>A changelog is available at https://github.com/nager/Nager.Date/blob/master/CHANGELOG.md</PackageReleaseNotes>
<PackageProjectUrl>https://date.nager.at</PackageProjectUrl>
<PackageTags>Holiday Public-Holiday PublicHoliday Bank-Holiday BankHoliday FederalHoliday NationalHoliday</PackageTags>

<RepositoryUrl>https://github.com/nager/Nager.Date</RepositoryUrl>

<TargetFrameworks>net472;netstandard2.0;net6.0;net8.0</TargetFrameworks>

<Version>2.0.0-alpha</Version>
Expand All @@ -34,5 +34,10 @@
<None Include="..\..\doc\README.md" Pack="true" PackagePath="\" />
<None Include="..\..\doc\Icons\calendar.png" Pack="true" PackagePath="\" Visible="false" />
</ItemGroup>


<ItemGroup>
<!-- This makes it possible for the architecture tests themselves to be performed internally. -->
<InternalsVisibleTo Include="Nager.Date.ArchitectureTest"/>
</ItemGroup>

</Project>

0 comments on commit 0758f64

Please sign in to comment.