-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathFreezeTests.cs
More file actions
106 lines (93 loc) · 3.63 KB
/
FreezeTests.cs
File metadata and controls
106 lines (93 loc) · 3.63 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
using ArchUnitNET.Domain;
using ArchUnitNET.Fluent;
using ArchUnitNET.Fluent.Freeze;
using ArchUnitNET.Fluent.Slices;
using ArchUnitNET.Loader;
using ArchUnitNET.xUnitV3;
using Xunit;
using static ArchUnitNET.Fluent.ArchRuleDefinition;
using static ArchUnitNET.Fluent.Freeze.FreezingArchRule;
namespace ArchUnitNETTests.Fluent
{
public class FreezeTests
{
private static readonly Architecture Architecture = new ArchLoader()
.LoadAssembly(typeof(FreezeTests).Assembly)
.Build();
private readonly IArchRule _frozenRule = Types()
.That()
.Are(typeof(Violation), typeof(Violation2))
.Should()
.NotBePrivate();
private readonly IArchRule _frozenRule2 = Types()
.That()
.Are(typeof(Violation))
.Should()
.BeProtected();
private readonly IArchRule _failingFrozenRule = Types()
.That()
.Are(typeof(Violation), typeof(Violation2))
.Should()
.BePublic();
private readonly IArchRule _frozenSliceRule = SliceRuleDefinition
.Slices()
.Matching("TestAssembly.Slices.(**)")
.Should()
.NotDependOnEachOther();
private readonly IArchRule _failingFrozenSliceRule = SliceRuleDefinition
.Slices()
.Matching("TestAssembly.Slices.(*)..")
.Should()
.NotDependOnEachOther();
[Fact]
public void PassFrozenRules()
{
Freeze(_frozenRule).Check(Architecture);
Freeze(_frozenRule2).Check(Architecture);
Freeze(_frozenSliceRule)
.Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture);
}
[Fact]
public void PassFrozenRulesUsingXmlViolationStore()
{
Freeze(_frozenRule, new XmlViolationStore()).Check(Architecture);
Freeze(_frozenRule2, new XmlViolationStore()).Check(Architecture);
Freeze(_frozenSliceRule, new XmlViolationStore())
.Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture);
}
[Fact]
public void FailFrozenRule()
{
Assert.Throws<FailedArchRuleException>(() =>
Freeze(_failingFrozenRule).Check(Architecture)
);
Assert.Throws<FailedArchRuleException>(() =>
Freeze(_failingFrozenSliceRule)
.Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture)
);
}
[Fact]
public void FailFrozenRuleUsingXmlViolationStore()
{
Assert.Throws<FailedArchRuleException>(() =>
Freeze(_failingFrozenRule, new XmlViolationStore()).Check(Architecture)
);
Assert.Throws<FailedArchRuleException>(() =>
Freeze(_failingFrozenSliceRule, new XmlViolationStore())
.Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture)
);
}
[Fact]
public void PassFrozenRulesWithCustomViolationStorePath()
{
Freeze(_frozenRule, "../../../ArchUnitNET/Storage/CustomPathFrozenRules.json")
.Check(Architecture);
Freeze(_frozenRule2, "../../../ArchUnitNET/Storage/CustomPathFrozenRules.json")
.Check(Architecture);
Freeze(_frozenSliceRule, "../../../ArchUnitNET/Storage/CustomPathFrozenRules.json")
.Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture);
}
private class Violation { }
private class Violation2 { }
}
}