forked from TNG/ArchUnitNET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRuleEvaluationTests.cs
55 lines (50 loc) · 2.17 KB
/
RuleEvaluationTests.cs
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
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Paula Ruiz <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
//
// SPDX-License-Identifier: Apache-2.0
using ArchUnitNET.Domain;
using ArchUnitNET.Fluent;
using ArchUnitNET.Fluent.Extensions;
using ArchUnitNET.Loader;
using ArchUnitNET.NUnit;
using NUnit.Framework;
using static ArchUnitNET.Fluent.ArchRuleDefinition;
namespace ArchUnitNET.NUnitTests
{
public class RuleEvaluationTests
{
private Architecture _architecture;
private string _expectedErrorMessage;
private IArchRule _falseRule;
private IArchRule _trueRule;
[SetUp]
public void Setup()
{
_architecture = new ArchLoader().LoadAssemblies(typeof(RuleEvaluationTests).Assembly).Build();
_trueRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().Exist();
_falseRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().NotExist();
_expectedErrorMessage = _falseRule.Evaluate(_architecture).ToErrorMessage();
}
[Test]
public void ArchRuleAssertTest()
{
ArchRuleAssert.FulfilsRule(_architecture, _trueRule);
Assert.Throws<AssertionException>(() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule));
Assert.AreEqual(_expectedErrorMessage,
Assert.Catch<AssertionException>(() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)).Message);
}
[Test]
public void ArchRuleExtensionsTest()
{
_architecture.CheckRule(_trueRule);
_trueRule.Check(_architecture);
Assert.Throws<AssertionException>(() => _architecture.CheckRule(_falseRule));
Assert.Throws<AssertionException>(() => _falseRule.Check(_architecture));
Assert.AreEqual(_expectedErrorMessage,
Assert.Catch<AssertionException>(() => _architecture.CheckRule(_falseRule)).Message);
Assert.AreEqual(_expectedErrorMessage,
Assert.Catch<AssertionException>(() => _falseRule.Check(_architecture)).Message);
}
}
}