-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathCleanArchitectureTests.cs
More file actions
126 lines (109 loc) · 4.56 KB
/
Copy pathCleanArchitectureTests.cs
File metadata and controls
126 lines (109 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using ArchUnitNET.Domain;
using ArchUnitNET.Loader;
using ArchUnitNET.xUnit;
using static ArchUnitNET.Fluent.ArchRuleDefinition;
namespace AAS.TwinEngine.DataEngine.UnitTests;
/// <summary>
/// This Validates that the Onion Architecture as described in the SAD is not broken.
/// https://dev.azure.com/mm-products/AAS.TwinEngine/_wiki/wikis/Wiki/163/5-Solution-Strategy
/// </summary>
public class CleanArchitectureTests
{
private const string BaseNamespace = "AAS.TwinEngine.DataEngine";
private readonly Architecture _architecture = new ArchLoader().LoadAssemblies(System.Reflection.Assembly.Load(BaseNamespace)).Build();
private readonly IObjectProvider<IType> _apiLayer = Types().That().ResideInNamespaceMatching($"{BaseNamespace}.Api.*").As("Api");
private readonly IObjectProvider<IType> _applicationLogicLayer = Types().That().ResideInNamespaceMatching($"{BaseNamespace}.ApplicationLogic.*").As("ApplicationLogic");
private readonly IObjectProvider<IType> _domainModelLayer = Types().That().ResideInNamespaceMatching($"{BaseNamespace}.DomainModel*").As("DomainModel");
private readonly IObjectProvider<IType> _infrastructureLayer = Types().That().ResideInNamespaceMatching($"{BaseNamespace}.Infrastructure.*").As("Infrastructure");
[Fact]
public void DomainModelShallNotHaveExternalDependencies()
{
var forbiddenTypes = new List<IType>();
forbiddenTypes.AddRange(_infrastructureLayer.GetObjects(_architecture));
forbiddenTypes.AddRange(_apiLayer.GetObjects(_architecture));
forbiddenTypes.AddRange(_applicationLogicLayer.GetObjects(_architecture));
Types().That().Are(_domainModelLayer)
.Should()
.NotDependOnAny(Types().That().Are(forbiddenTypes))
.WithoutRequiringPositiveResults()
.Check(_architecture);
}
[Fact]
public void ApplicationLogicShallNotHaveDependenciesToInfrastructure()
{
Types().That().Are(_applicationLogicLayer)
.Should()
.NotDependOnAny(Types().That().Are(_infrastructureLayer))
.WithoutRequiringPositiveResults()
.Check(_architecture);
}
[Fact]
public void ApplicationLogicShallNotHaveDependenciesToApi()
{
Types().That().Are(_applicationLogicLayer)
.Should()
.NotDependOnAny(Types().That().Are(_apiLayer))
.WithoutRequiringPositiveResults()
.Check(_architecture);
}
[Fact]
public void InfrastructureShallNotHaveDependenciesToApi()
{
Types().That().Are(_infrastructureLayer)
.Should()
.NotDependOnAny(Types().That().Are(_apiLayer))
.WithoutRequiringPositiveResults()
.Check(_architecture);
}
[Fact]
public void ApiShallNotHaveDependenciesToInfrastructure()
{
Types().That().Are(_apiLayer)
.Should()
.NotDependOnAny(Types().That().Are(_infrastructureLayer))
.WithoutRequiringPositiveResults()
.Check(_architecture);
}
[Fact]
public void RepositoryClassesShallBeInCorrectNamespace()
{
Classes().That().HaveNameEndingWith("Repository").Should()
.ResideInNamespaceMatching($"{BaseNamespace}.Infrastructure.Providers*")
.WithoutRequiringPositiveResults()
.Check(_architecture);
}
[Fact]
public void RepositoryInterfacesShallBeInCorrectNamespace()
{
Interfaces().That()
.HaveNameEndingWith("Repository")
.And()
.DoNotHaveFullName($"{BaseNamespace}.Infrastructure.DataAccess.GenericRepository.IMongoDbRepository")
.Should()
.ResideInNamespaceMatching($"{BaseNamespace}.ApplicationLogic.*")
.WithoutRequiringPositiveResults()
.Check(_architecture);
}
[Fact]
public void ServicesShallBeInCorrectNamespace()
{
Classes().That().HaveNameEndingWith("Service").Should()
.ResideInNamespaceMatching($"{BaseNamespace}.ApplicationLogic.Service.*")
.Check(_architecture);
}
[Fact]
public void ServiceInterfacesShallBeInCorrectNamespace()
{
Interfaces().That().HaveNameEndingWith("Service")
.Should()
.ResideInNamespaceMatching($"{BaseNamespace}.ApplicationLogic.Service.*")
.Check(_architecture);
}
[Fact]
public void ControllerShallBeInCorrectNamespace()
{
Classes().That().HaveNameEndingWith("Controller").Should()
.ResideInNamespaceMatching($"{BaseNamespace}.Api.*")
.Check(_architecture);
}
}