Skip to content

Commit

Permalink
tests for custom conditions and predicates
Browse files Browse the repository at this point in the history
Signed-off-by: Fritz Brandhuber <[email protected]>
  • Loading branch information
brandhuf committed Feb 22, 2021
1 parent 8b96326 commit 4b9d23d
Showing 1 changed file with 58 additions and 0 deletions.
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
{
}
}

0 comments on commit 4b9d23d

Please sign in to comment.