Skip to content

Commit

Permalink
Update Architectural tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Narek committed Apr 11, 2024
1 parent 2167266 commit bcde18a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 41 deletions.
2 changes: 2 additions & 0 deletions src/Pandatech.CleanArchitecture.Api/AssemblyReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
namespace Pandatech.CleanArchitecture.Api;
public class AssemblyReference;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
namespace Pandatech.CleanArchitecture.Application;
public class AssemblyReference;
3 changes: 3 additions & 0 deletions src/Pandatech.CleanArchitecture.Core/AssemblyReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Pandatech.CleanArchitecture.Core;

public class AssemblyReference;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
namespace Pandatech.CleanArchitecture.Infrastructure;
public class AssemblyReference;
69 changes: 28 additions & 41 deletions tests/Pandatech.CleanArchitecture.Test/ArchitectureTests.cs
Original file line number Diff line number Diff line change
@@ -1,109 +1,96 @@
using NetArchTest.Rules;
using Pandatech.CleanArchitecture.Core;
using Xunit;

namespace Architecture.Tests;

public class ArchitectureTests
{
private const string CoreNamespace = "Pandatech.CleanArchitecture.Core";
private const string ApplicationNamespace = "Pandatech.CleanArchitecture.Application";
private const string InfrastructureNamespace = "Pandatech.CleanArchitecture.Infrastructure";
private const string PresentationNamespace = "Presentation";
private const string WebApiNamespace = "Pandatech.CleanArchitecture.Api";
private readonly static string? CoreName =
typeof(Pandatech.CleanArchitecture.Core.AssemblyReference).Assembly.GetName().Name;
private readonly static string? ApplicationClientName =
typeof(Pandatech.CleanArchitecture.Application.AssemblyReference).Assembly.GetName().Name;
private readonly static string? InfrastructureName =
typeof(Pandatech.CleanArchitecture.Infrastructure.AssemblyReference).Assembly.GetName().Name;
private readonly static string? WebApiName =
typeof(Pandatech.CleanArchitecture.Api.AssemblyReference).Assembly.GetName().Name;

[Fact]
public void Domain_Should_Not_HaveDependencyOnOtherProjects()
public void Core_Should_Not_HaveDependency_On_OtherProjects()
{
// Arrange
var assembly = typeof(DependencyInjection).Assembly;
var assembly = typeof(Pandatech.CleanArchitecture.Core.AssemblyReference).Assembly;

var otherProjects = new[]
{
ApplicationNamespace, InfrastructureNamespace, PresentationNamespace, WebApiNamespace
WebApiName,
InfrastructureName,
ApplicationClientName,
};

// Act
var testResult = Types
.InAssembly(assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProjects)
.HaveDependencyOnAny(otherProjects)
.GetResult();

// Assert
Assert.True(testResult.IsSuccessful);
}

[Fact]
public void Application_Should_Not_HaveDependencyOnOtherProjects()
public void Application_Should_Not_HaveDependency_On_OtherProjects()
{
// Arrange
var assembly = typeof(Pandatech.CleanArchitecture.Application.DependencyInjection).Assembly;
var assembly = typeof(Pandatech.CleanArchitecture.Application.AssemblyReference).Assembly;

var otherProjects = new[] { InfrastructureNamespace, PresentationNamespace, WebApiNamespace };
var otherProjects = new[]
{
WebApiName,
InfrastructureName,
};

// Act
var testResult = Types
.InAssembly(assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProjects)
.HaveDependencyOnAny(otherProjects)
.GetResult();

// Assert
Assert.True(testResult.IsSuccessful);
}

[Fact]
public void Handlers_Should_Have_DependencyOnDomain()
public void Handlers_Should_Have_Dependency_On_Core()
{
// Arrange
var assembly = typeof(Pandatech.CleanArchitecture.Application.DependencyInjection).Assembly;
var assembly = typeof(Pandatech.CleanArchitecture.Application.AssemblyReference).Assembly;

// Act
var testResult = Types
.InAssembly(assembly)
.That()
.HaveNameEndingWith("Handler")
.Should()
.HaveDependencyOn(CoreNamespace)
.HaveDependencyOnAny(CoreName)
.GetResult();

// Assert
Assert.True(testResult.IsSuccessful);
}

[Fact]
public void Infrastructure_Should_Not_HaveDependencyOnOtherProjects()
public void Infrastructure_Should_Not_HaveDependency_On_OtherProjects()
{
// Arrange
var assembly = typeof(Pandatech.CleanArchitecture.Infrastructure.DependencyInjection).Assembly;

var otherProjects = new[] { PresentationNamespace, WebApiNamespace };

// Act
var testResult = Types
.InAssembly(assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProjects)
.GetResult();

// Assert
Assert.True(testResult.IsSuccessful);
}

[Fact]
public void Presentation_Should_Not_HaveDependencyOnOtherProjects()
{
// Arrange
var assembly = typeof(Pandatech.CleanArchitecture.Infrastructure.DependencyInjection).Assembly;

var otherProjects = new[] { InfrastructureNamespace, WebApiNamespace };
var assembly = typeof(Pandatech.CleanArchitecture.Infrastructure.AssemblyReference).Assembly;

// Act
var testResult = Types
.InAssembly(assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProjects)
.HaveDependencyOnAny(WebApiName)
.GetResult();

// Assert
Expand Down

0 comments on commit bcde18a

Please sign in to comment.