Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Fritz Brandhuber <fritz.brandhuber@tngtech.com>
- Loading branch information
Fritz Brandhuber
committed
Apr 4, 2022
1 parent
272c420
commit ba31790
Showing
2 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
182 changes: 182 additions & 0 deletions
182
ArchUnitNETTests/Fluent/NoErrorReferencingOfTypesOutsideOfArchitectureTests.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,182 @@ | ||
// Copyright 2019 Florian Gather <florian.gather@tngtech.com> | ||
// Copyright 2019 Fritz Brandhuber <fritz.brandhuber@tngtech.com> | ||
// Copyright 2020 Pavel Fischer <rubbiroid@gmail.com> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
using System; | ||
using System.Linq; | ||
using ArchUnitNET.Domain; | ||
using ArchUnitNET.Domain.Exceptions; | ||
using ArchUnitNET.Domain.Extensions; | ||
using ArchUnitNET.Loader; | ||
using ArchUnitNET.xUnit; | ||
using TestAssembly; | ||
using Xunit; | ||
using static ArchUnitNET.Fluent.ArchRuleDefinition; | ||
|
||
namespace ArchUnitNETTests.Fluent | ||
{ | ||
public class NoErrorReferencingOfTypesOutsideOfArchitectureTests | ||
{ | ||
private static readonly Architecture Architecture = | ||
new ArchLoader().LoadAssemblies(typeof(EmptyTestClass).Assembly).Build(); | ||
|
||
private readonly System.Type _classNotInArchitecture = typeof(NoErrorReferencingOfTypesOutsideOfArchitectureTests); | ||
|
||
public NoErrorReferencingOfTypesOutsideOfArchitectureTests() | ||
{ | ||
Assert.Throws<TypeDoesNotExistInArchitecture>(() => Architecture.GetClassOfType(_classNotInArchitecture)); | ||
} | ||
|
||
private static void AssertNoException(Action action) | ||
{ | ||
var exception = Record.Exception(action); | ||
Assert.Null(exception); | ||
} | ||
|
||
[Fact] | ||
public void DependOnAnyTest() | ||
{ | ||
var rule = Classes().That().Are(typeof(EmptyTestClass)).Should().DependOnAny(_classNotInArchitecture); | ||
var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.NotDependOnAny(_classNotInArchitecture); | ||
Assert.Throws<FailedArchRuleException>(() => rule.Check(Architecture)); | ||
negation.Check(Architecture); | ||
|
||
AssertNoException(() => Classes().That().DependOnAny(_classNotInArchitecture).GetObjects(Architecture)); | ||
AssertNoException(() => | ||
Classes().That().DoNotDependOnAny(_classNotInArchitecture).GetObjects(Architecture)); | ||
} | ||
|
||
[Fact] | ||
public void OnlyDependOnTest() | ||
{ | ||
var rule = Classes().That().Are(typeof(EmptyTestClass)).Should().OnlyDependOn(_classNotInArchitecture); | ||
rule.Check(Architecture); | ||
|
||
AssertNoException(() => Classes().That().OnlyDependOn(_classNotInArchitecture).GetObjects(Architecture)); | ||
} | ||
|
||
[Fact] | ||
public void OnlyHaveAttributesTest() | ||
{ | ||
var rule = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.OnlyHaveAttributes(_classNotInArchitecture); | ||
var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.NotHaveAnyAttributes(_classNotInArchitecture); | ||
rule.Check(Architecture); | ||
negation.Check(Architecture); | ||
|
||
AssertNoException(() => | ||
Classes().That().OnlyHaveAttributes(_classNotInArchitecture).GetObjects(Architecture)); | ||
AssertNoException(() => | ||
Classes().That().DoNotHaveAnyAttributes(_classNotInArchitecture).GetObjects(Architecture)); | ||
} | ||
|
||
[Fact] | ||
public void HaveAttributeWithArgumentsTest() | ||
{ | ||
var rule = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.HaveAttributeWithArguments(_classNotInArchitecture, Enumerable.Empty<object>()); | ||
var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.NotHaveAttributeWithArguments(_classNotInArchitecture, Enumerable.Empty<object>()); | ||
Assert.Throws<FailedArchRuleException>(() => rule.Check(Architecture)); | ||
negation.Check(Architecture); | ||
|
||
AssertNoException(() => | ||
Classes().That().HaveAttributeWithArguments(_classNotInArchitecture, Enumerable.Empty<object>()) | ||
.GetObjects(Architecture)); | ||
AssertNoException(() => | ||
Classes().That().DoNotHaveAttributeWithArguments(_classNotInArchitecture, Enumerable.Empty<object>()) | ||
.GetObjects(Architecture)); | ||
} | ||
|
||
[Fact] | ||
public void HaveAttributeWithNamedArgumentsTest() | ||
{ | ||
var rule = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.HaveAttributeWithNamedArguments(_classNotInArchitecture, Enumerable.Empty<(string, object)>()); | ||
var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.NotHaveAttributeWithNamedArguments(_classNotInArchitecture, Enumerable.Empty<(string, object)>()); | ||
Assert.Throws<FailedArchRuleException>(() => rule.Check(Architecture)); | ||
negation.Check(Architecture); | ||
|
||
AssertNoException(() => | ||
Classes().That() | ||
.HaveAttributeWithNamedArguments(_classNotInArchitecture, Enumerable.Empty<(string, object)>()) | ||
.GetObjects(Architecture)); | ||
AssertNoException(() => | ||
Classes().That() | ||
.DoNotHaveAttributeWithNamedArguments(_classNotInArchitecture, Enumerable.Empty<(string, object)>()) | ||
.GetObjects(Architecture)); | ||
} | ||
|
||
[Fact] | ||
public void AreBeTest() | ||
{ | ||
var rule = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.Be(_classNotInArchitecture); | ||
var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.NotBe(_classNotInArchitecture); | ||
Assert.Throws<FailedArchRuleException>(() => rule.Check(Architecture)); | ||
negation.Check(Architecture); | ||
|
||
AssertNoException(() => Classes().That().Are(_classNotInArchitecture).GetObjects(Architecture)); | ||
AssertNoException(() => Classes().That().AreNot(_classNotInArchitecture).GetObjects(Architecture)); | ||
} | ||
|
||
[Fact] | ||
public void AreAssignableTest() | ||
{ | ||
var rule = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.BeAssignableTo(_classNotInArchitecture); | ||
var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.NotBeAssignableTo(_classNotInArchitecture); | ||
Assert.Throws<FailedArchRuleException>(() => rule.Check(Architecture)); | ||
negation.Check(Architecture); | ||
|
||
AssertNoException(() => Classes().That().AreAssignableTo(_classNotInArchitecture).GetObjects(Architecture)); | ||
AssertNoException(() => Classes().That().AreNotAssignableTo(_classNotInArchitecture).GetObjects(Architecture)); | ||
} | ||
|
||
[Fact] | ||
public void ImplementInterfaceTest() | ||
{ | ||
var rule = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.ImplementInterface(_classNotInArchitecture); | ||
var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() | ||
.NotImplementInterface(_classNotInArchitecture); | ||
Assert.Throws<FailedArchRuleException>(() => rule.Check(Architecture)); | ||
negation.Check(Architecture); | ||
|
||
AssertNoException(() => Classes().That().ImplementInterface(_classNotInArchitecture).GetObjects(Architecture)); | ||
AssertNoException(() => Classes().That().DoNotImplementInterface(_classNotInArchitecture).GetObjects(Architecture)); | ||
} | ||
|
||
[Fact] | ||
public void DeclaredInTest() | ||
{ | ||
var rule = Members().Should().BeDeclaredIn(_classNotInArchitecture); | ||
var negation = Members().Should().NotBeDeclaredIn(_classNotInArchitecture); | ||
Assert.Throws<FailedArchRuleException>(() => rule.Check(Architecture)); | ||
negation.Check(Architecture); | ||
|
||
AssertNoException(() => Members().That().AreDeclaredIn(_classNotInArchitecture).GetObjects(Architecture)); | ||
AssertNoException(() => Members().That().AreNotDeclaredIn(_classNotInArchitecture).GetObjects(Architecture)); | ||
} | ||
|
||
[Fact] | ||
public void CalledByTest() | ||
{ | ||
var rule = MethodMembers().Should().BeCalledBy(_classNotInArchitecture); | ||
var negation = MethodMembers().Should().NotBeCalledBy(_classNotInArchitecture); | ||
Assert.Throws<FailedArchRuleException>(() => rule.Check(Architecture)); | ||
negation.Check(Architecture); | ||
|
||
AssertNoException(() => MethodMembers().That().AreCalledBy(_classNotInArchitecture).GetObjects(Architecture)); | ||
AssertNoException(() => MethodMembers().That().AreNotCalledBy(_classNotInArchitecture).GetObjects(Architecture)); | ||
} | ||
} | ||
} |
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,14 @@ | ||
// Copyright 2019 Florian Gather <florian.gather@tngtech.com> | ||
// Copyright 2019 Fritz Brandhuber <fritz.brandhuber@tngtech.com> | ||
// Copyright 2020 Pavel Fischer <rubbiroid@gmail.com> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
namespace TestAssembly | ||
{ | ||
public class EmptyTestClass | ||
{ | ||
|
||
} | ||
} |