-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduction of architecture tests for stabilization and standardizat…
…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
Showing
5 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/Nager.Date.ArchitectureTest/IHolidayProviderArchitectureTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
src/Nager.Date.ArchitectureTest/Internals/NagerDateArchitecture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
src/Nager.Date.ArchitectureTest/Nager.Date.ArchitectureTest.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters