-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathDependenciesToOtherAssembliesTests.cs
More file actions
145 lines (134 loc) · 5.11 KB
/
DependenciesToOtherAssembliesTests.cs
File metadata and controls
145 lines (134 loc) · 5.11 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using ArchUnitNET.Domain;
using ArchUnitNET.Domain.Extensions;
using ArchUnitNET.Loader;
using ArchUnitNET.xUnitV3;
using TestAssembly.DependencyTargets;
using Xunit;
using static ArchUnitNET.Fluent.ArchRuleDefinition;
namespace ArchUnitNETTests.Fluent.Syntax
{
public class DependenciesToOtherAssembliesTests
{
public class TestDependencyIssue
{
private static readonly Architecture Architecture = new ArchLoader()
.LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests"))
.Build();
[Fact]
public void DependOnAnyTypesThatTest()
{
Types()
.That()
.Are(typeof(DependingClass))
.Should()
.DependOnAnyTypesThat()
.Are(typeof(ClassInTestAssembly))
.Check(Architecture);
Assert.Throws<FailedArchRuleException>(() =>
Types()
.That()
.Are(typeof(DependingClass))
.Should()
.NotDependOnAnyTypesThat()
.Are(typeof(ClassInTestAssembly))
.Check(Architecture)
);
}
[Fact]
public void BeAssignableToTypesThatTest()
{
Types()
.That()
.Are(typeof(DependingClass))
.Should()
.BeAssignableToTypesThat()
.Are(typeof(IInterfaceInTestAssembly))
.Check(Architecture);
Assert.Throws<FailedArchRuleException>(() =>
Types()
.That()
.Are(typeof(DependingClass))
.Should()
.NotBeAssignableToTypesThat()
.Are(typeof(IInterfaceInTestAssembly))
.Check(Architecture)
);
}
[Fact]
public void OnlyDependOnTypesThatTest()
{
Types()
.That()
.Are(typeof(DependingClass))
.Should()
.OnlyDependOnTypesThat()
.Are(
typeof(object),
typeof(AttributeInTestAssembly),
typeof(IInterfaceInTestAssembly),
typeof(ClassInTestAssembly),
typeof(DependingClass)
)
.Check(Architecture);
}
[Fact]
public void HaveAnyAttributesThatTest()
{
Types()
.That()
.Are(typeof(DependingClass))
.Should()
.HaveAnyAttributesThat()
.Are(typeof(AttributeInTestAssembly))
.Check(Architecture);
Assert.Throws<FailedArchRuleException>(() =>
Types()
.That()
.Are(typeof(DependingClass))
.Should()
.NotHaveAnyAttributesThat()
.Are(typeof(AttributeInTestAssembly))
.Check(Architecture)
);
}
[Fact]
public void OnlyHaveAttributesThatTest()
{
Types()
.That()
.Are(typeof(DependingClass))
.Should()
.OnlyHaveAttributesThat()
.Are(typeof(AttributeInTestAssembly))
.Check(Architecture);
}
[Fact]
public void IncludeReferencedTypesTest()
{
var classInTestAssembly = Architecture.GetClassOfType(typeof(ClassInTestAssembly));
Assert.Contains(classInTestAssembly, Types(true).GetObjects(Architecture));
Assert.Contains(classInTestAssembly, Classes(true).GetObjects(Architecture));
var attributeInTestAssembly = Architecture.GetAttributeOfType(
typeof(AttributeInTestAssembly)
);
Assert.Contains(attributeInTestAssembly, Types(true).GetObjects(Architecture));
Assert.Contains(attributeInTestAssembly, Attributes(true).GetObjects(Architecture));
var interfaceInTestAssembly = Architecture.GetInterfaceOfType(
typeof(IInterfaceInTestAssembly)
);
Assert.Contains(interfaceInTestAssembly, Types(true).GetObjects(Architecture));
Assert.Contains(interfaceInTestAssembly, Interfaces(true).GetObjects(Architecture));
}
}
}
[AttributeInTestAssembly]
public class DependingClass : IInterfaceInTestAssembly
{
private ClassInTestAssembly dep;
public DependingClass()
{
dep = new ClassInTestAssembly();
dep.MethodInTestAssembly();
}
}
}