-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathRuleEvaluationTests.cs
More file actions
81 lines (76 loc) · 2.9 KB
/
RuleEvaluationTests.cs
File metadata and controls
81 lines (76 loc) · 2.9 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
using ArchUnitNET.Domain;
using ArchUnitNET.Fluent;
using ArchUnitNET.Fluent.Extensions;
using ArchUnitNET.Loader;
using ArchUnitNET.MSTestV2;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static ArchUnitNET.Fluent.ArchRuleDefinition;
namespace ArchUnitNET.MSTestV3Tests
{
[TestClass]
public class RuleEvaluationTests
{
private static Architecture _architecture;
private static string _expectedErrorMessage;
private static IArchRule _falseRule;
private static IArchRule _trueRule;
[ClassInitialize]
public static void Setup(TestContext context)
{
_architecture = new ArchLoader()
.LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.MSTestV3Tests"))
.Build();
_trueRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().Exist();
_falseRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().NotExist();
_expectedErrorMessage = _falseRule.Evaluate(_architecture).ToErrorMessage();
}
[TestMethod]
public void ArchRuleAssertTest()
{
ArchRuleAssert.FulfilsRule(_architecture, _trueRule);
Assert.ThrowsExactly<AssertFailedException>(() =>
ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
);
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsExactly<AssertFailedException>(() =>
ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
)
.Message
)
);
}
[TestMethod]
public void ArchRuleExtensionsTest()
{
_architecture.CheckRule(_trueRule);
_trueRule.Check(_architecture);
Assert.ThrowsExactly<AssertFailedException>(() => _architecture.CheckRule(_falseRule));
Assert.ThrowsExactly<AssertFailedException>(() => _falseRule.Check(_architecture));
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsExactly<AssertFailedException>(() =>
_architecture.CheckRule(_falseRule)
)
.Message
)
);
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsExactly<AssertFailedException>(() => _falseRule.Check(_architecture))
.Message
)
);
}
private static string RemoveAssertionText(string exceptionMessage)
{
return exceptionMessage.Replace("Assert.Fail failed. ", string.Empty);
}
}
}