-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathArchitectureTest.cs
More file actions
109 lines (95 loc) · 3.5 KB
/
Copy pathArchitectureTest.cs
File metadata and controls
109 lines (95 loc) · 3.5 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
using ArchUnitNET.Domain;
using ArchUnitNET.Loader;
using ArchUnitNET.xUnit;
using MainCore.Constraints;
using MainCore.Entities;
using MainCore.Infrasturecture.Persistence;
using MainCore.Services;
using static ArchUnitNET.Fluent.ArchRuleDefinition;
namespace MainCore.Test
{
[Trait("Mode", "Debug")]
public class ArchitectureTest
{
private static readonly Architecture Architecture = new ArchLoader()
.LoadAssemblies(
System.Reflection.Assembly.Load("MainCore")
).Build();
private readonly IObjectProvider<MethodMember> Handler =
MethodMembers().That().HaveNameContaining("HandleAsync").And().AreStatic().As("Handler");
private readonly IObjectProvider<Class> Request =
Classes().That().AreAssignableTo(typeof(IConstraint)).As("Request");
[Theory]
[InlineData(typeof(ICommand), "Command", true)]
[InlineData(typeof(ITask), "Task", false)]
public void RequestShouldHaveCorrectName(System.Type interfaceType, string nameSuffix, bool shouldBeRecord)
{
var rule = Classes().That()
.AreAssignableTo(interfaceType)
.And()
.AreNotAbstract();
var shouldRule = rule
.Should().BeSealed()
.AndShould().HaveNameEndingWith(nameSuffix);
if (shouldBeRecord)
{
shouldRule = shouldRule.AndShould().BeRecord();
}
shouldRule.Check(Architecture);
}
[Fact]
public void HandlerAccessDatabaseShouldNotContainOtherHandler()
{
var otherhandler = Classes().That()
.AreAssignableTo(typeof(Immediate.Handlers.Shared.IHandler<,>))
.As("other handler");
var rule = MethodMembers().That()
.Are(Handler)
.And()
.DependOnAny(typeof(AppDbContext))
.Should()
.NotDependOnAny(otherhandler);
rule.Check(Architecture);
}
[Fact]
public void HandlerShouldNotDependOnDialogService()
{
var rule = MethodMembers().That()
.Are(Handler)
.Should()
.NotDependOnAny(typeof(IDialogService));
rule.Check(Architecture);
}
[Fact]
public void RequestShouldHaveCorrectConstraint()
{
var accountVillageRule = Classes().That()
.Are(Request)
.And()
.DependOnAny(typeof(AccountId))
.And()
.DependOnAny(typeof(VillageId))
.Should()
.BeAssignableTo(typeof(IAccountVillageConstraint));
accountVillageRule.Check(Architecture);
var accountOnlyRule = Classes().That()
.Are(Request)
.And()
.DependOnAny(typeof(AccountId))
.And()
.DoNotDependOnAny(typeof(VillageId))
.Should()
.BeAssignableTo(typeof(IAccountConstraint));
accountOnlyRule.Check(Architecture);
var villageOnlyRule = Classes().That()
.Are(Request)
.And()
.DependOnAny(typeof(VillageId))
.And()
.DoNotDependOnAny(typeof(AccountId))
.Should()
.BeAssignableTo(typeof(IVillageConstraint));
villageOnlyRule.Check(Architecture);
}
}
}