-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests for custom conditions and predicates
Signed-off-by: Fritz Brandhuber <[email protected]>
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
ArchUnitNETTests/Fluent/Syntax/Elements/CustomSyntaxElementsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2019 Florian Gather <[email protected]> | ||
// Copyright 2019 Fritz Brandhuber <[email protected]> | ||
// Copyright 2020 Pavel Fischer <[email protected]> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
using System.Linq; | ||
using ArchUnitNET.Domain; | ||
using ArchUnitNET.Domain.Extensions; | ||
using ArchUnitNET.Loader; | ||
using Xunit; | ||
using static ArchUnitNET.Fluent.ArchRuleDefinition; | ||
|
||
namespace ArchUnitNETTests.Fluent.Syntax.Elements | ||
{ | ||
public class CustomSyntaxElementsTests | ||
{ | ||
private static readonly Architecture Architecture = | ||
new ArchLoader().LoadAssemblies(typeof(CustomSyntaxElementsTests).Assembly).Build(); | ||
|
||
private readonly Class _testClass; | ||
|
||
public CustomSyntaxElementsTests() | ||
{ | ||
_testClass = Architecture.GetClassOfType(typeof(CustomRuleTestClass)); | ||
} | ||
|
||
[Fact] | ||
public void CustomConditionTest() | ||
{ | ||
var passingRule = Classes().That().Are(typeof(CustomRuleTestClass)).Should() | ||
.FollowCustomCondition(cls => cls.FullName.Contains(nameof(CustomRuleTestClass)), | ||
"passing custom condition", "failed custom condition which should have passed"); | ||
var failingRule = Classes().That().Are(typeof(CustomRuleTestClass)).Should() | ||
.FollowCustomCondition(cls => !cls.FullName.Contains(nameof(CustomRuleTestClass)), | ||
"failing custom condition", "failed custom condition which should have failed"); | ||
|
||
passingRule.Check(Architecture); | ||
Assert.False(failingRule.HasNoViolations(Architecture)); | ||
} | ||
|
||
[Fact] | ||
public void CustomPredicateTest() | ||
{ | ||
var predicateTestObjects = Classes().That() | ||
.FollowCustomPredicate(cls => cls.Name.Equals(nameof(CustomRuleTestClass)), "custom predicate") | ||
.GetObjects(Architecture); | ||
|
||
Assert.Single(predicateTestObjects); | ||
Assert.Equal(_testClass, predicateTestObjects.First()); | ||
} | ||
} | ||
|
||
internal class CustomRuleTestClass | ||
{ | ||
} | ||
} |