Commit beead90c authored by Almouhannad's avatar Almouhannad

(B) Add architecture tests

parent 03d7bc2d
using FluentAssertions;
using NetArchTest.Rules;
using Xunit;
namespace ArchitectureTests;
public class ArchitectureTests
{
private const string DomainNamespace = "Domain";
private const string ApplicationNamespace = "Application";
private const string InfrastructureNamespace = "Infrastructure";
private const string PersistenceNamespace = "Persistence";
private const string PresentationNamespace = "Presenttation";
private const string APINamespace = "API";
// Use this naming convension
// .._Should_[Not]_...()
[Fact]
public void Domain_Should_Not_HaveDependencyOnOtherProjects()
{
#region Arrange
var assembly = Domain.AssemblyReference.Assembly;
var otherProjects = new[]
{
ApplicationNamespace,
InfrastructureNamespace,
PersistenceNamespace,
PresentationNamespace,
APINamespace
};
#endregion
#region Act
var testResult = Types
.InAssembly(assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProjects)
.GetResult();
#endregion
#region Assert
testResult.IsSuccessful.Should().BeTrue();
#endregion
}
[Fact]
public void Application_Should_Not_HaveDependencyOnOtherProjects()
{
#region Arrange
var assembly = Application.AssemblyReference.Assembly;
var otherProjects = new[]
{
InfrastructureNamespace,
PersistenceNamespace,
PresentationNamespace,
APINamespace
};
#endregion
#region Act
var testResult = Types
.InAssembly(assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProjects)
.GetResult();
#endregion
#region Assert
testResult.IsSuccessful.Should().BeTrue();
#endregion
}
[Fact]
public void Infrastructure_Should_Not_HaveDependencyOnPresentation()
{
#region Arrange
var assembly = Infrastructure.AssemblyReference.Assembly;
var otherProjects = new[]
{
PersistenceNamespace,
PresentationNamespace,
APINamespace
};
#endregion
#region Act
var testResult = Types
.InAssembly(assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProjects)
.GetResult();
#endregion
#region Assert
testResult.IsSuccessful.Should().BeTrue();
#endregion
}
[Fact]
public void Persistence_Should_Not_HaveDependencyOnPresentation()
{
#region Arrange
var assembly = Persistence.AssemblyReference.Assembly;
var otherProjects = new[]
{
InfrastructureNamespace,
PresentationNamespace,
APINamespace
};
#endregion
#region Act
var testResult = Types
.InAssembly(assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProjects)
.GetResult();
#endregion
#region Assert
testResult.IsSuccessful.Should().BeTrue();
#endregion
}
[Fact]
public void Presentation_Should_Not_HaveDependencyOnInfrastructure()
{
#region Arrange
var assembly = Presentation.AssemblyReference.Assembly;
var otherProjects = new[]
{
InfrastructureNamespace,
PersistenceNamespace,
APINamespace
};
#endregion
#region Act
var testResult = Types
.InAssembly(assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProjects)
.GetResult();
#endregion
#region Assert
testResult.IsSuccessful.Should().BeTrue();
#endregion
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="NetArchTest.Rules" Version="1.3.2" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit.extensibility.core" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\API\API.csproj" />
<ProjectReference Include="..\Application\Application.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" />
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
<ProjectReference Include="..\Persistence\Persistence.csproj" />
<ProjectReference Include="..\Presentation\Presentation.csproj" />
</ItemGroup>
</Project>
...@@ -21,7 +21,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistence", "Persistence\ ...@@ -21,7 +21,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistence", "Persistence\
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "API\API.csproj", "{15B2AA13-EBBD-408B-A4B3-4BAB43D74267}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "API\API.csproj", "{15B2AA13-EBBD-408B-A4B3-4BAB43D74267}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "Infrastructure\Infrastructure.csproj", "{4EB41743-695F-4822-87F6-E6F9B48A8E6B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure", "Infrastructure\Infrastructure.csproj", "{4EB41743-695F-4822-87F6-E6F9B48A8E6B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{05E390C6-AFE5-42FB-A3E2-CEEE1E6A75EE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchitectureTests", "ArchitectureTests\ArchitectureTests.csproj", "{07C6D0DB-7181-4E6F-9BC1-863FCDAD9490}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -53,6 +57,10 @@ Global ...@@ -53,6 +57,10 @@ Global
{4EB41743-695F-4822-87F6-E6F9B48A8E6B}.Debug|Any CPU.Build.0 = Debug|Any CPU {4EB41743-695F-4822-87F6-E6F9B48A8E6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4EB41743-695F-4822-87F6-E6F9B48A8E6B}.Release|Any CPU.ActiveCfg = Release|Any CPU {4EB41743-695F-4822-87F6-E6F9B48A8E6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4EB41743-695F-4822-87F6-E6F9B48A8E6B}.Release|Any CPU.Build.0 = Release|Any CPU {4EB41743-695F-4822-87F6-E6F9B48A8E6B}.Release|Any CPU.Build.0 = Release|Any CPU
{07C6D0DB-7181-4E6F-9BC1-863FCDAD9490}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07C6D0DB-7181-4E6F-9BC1-863FCDAD9490}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07C6D0DB-7181-4E6F-9BC1-863FCDAD9490}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07C6D0DB-7181-4E6F-9BC1-863FCDAD9490}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
...@@ -66,6 +74,7 @@ Global ...@@ -66,6 +74,7 @@ Global
{D04C0D6C-3FC9-4359-A017-DFCFA1475639} = {878AE2C9-3E34-4332-ACC0-E6B601085710} {D04C0D6C-3FC9-4359-A017-DFCFA1475639} = {878AE2C9-3E34-4332-ACC0-E6B601085710}
{2B5111ED-7AB8-46E2-90F8-AF0C70265618} = {FDA56BCD-A53D-4BA1-A59D-3F44FA32DDD7} {2B5111ED-7AB8-46E2-90F8-AF0C70265618} = {FDA56BCD-A53D-4BA1-A59D-3F44FA32DDD7}
{4EB41743-695F-4822-87F6-E6F9B48A8E6B} = {FDA56BCD-A53D-4BA1-A59D-3F44FA32DDD7} {4EB41743-695F-4822-87F6-E6F9B48A8E6B} = {FDA56BCD-A53D-4BA1-A59D-3F44FA32DDD7}
{07C6D0DB-7181-4E6F-9BC1-863FCDAD9490} = {05E390C6-AFE5-42FB-A3E2-CEEE1E6A75EE}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E9FC9252-1283-485F-8F84-3574CFA12633} SolutionGuid = {E9FC9252-1283-485F-8F84-3574CFA12633}
......
using System.Reflection;
namespace Domain;
public class AssemblyReference
{
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment