From 825bdb00eecda377b84483412cfa1df70095d618 Mon Sep 17 00:00:00 2001 From: Fritz Brandhuber Date: Fri, 26 Feb 2021 16:54:46 +0100 Subject: [PATCH 1/3] rename xUnit Assert to ArchRuleAssert and move it to ArchUnitNET.xUnit namespace Signed-off-by: Fritz Brandhuber --- .../{Asserts => }/ArchRuleAsserts.cs | 6 +- ArchUnitNET.xUnit/ArchRuleExtensions.cs | 6 +- ArchUnitNET.xUnit/ArchUnitNET.xUnit.csproj | 6 +- .../FailedArchRuleException.cs | 3 +- ArchUnitNETTests/ArchUnitNETTests.csproj | 1 + .../ArchUnitArchitectureTests.cs | 1 + .../Fluent/RuleEvaluationTests.cs | 62 +++++++++---------- ArchUnitNETTests/Fluent/Slices/SlicesTests.cs | 2 +- .../Elements/CustomSyntaxElementsTests.cs | 1 + .../Elements/ObjectSyntaxElementsTests.cs | 1 + ArchUnitNETTests/StaticTestArchitectures.cs | 2 +- ExampleTest/ExampleArchUnitTest.cs | 1 + ExampleTest/ExampleTest.csproj | 1 + 13 files changed, 48 insertions(+), 45 deletions(-) rename ArchUnitNET.xUnit/{Asserts => }/ArchRuleAsserts.cs (94%) rename ArchUnitNET.xUnit/{Asserts/Sdk/Exceptions => }/FailedArchRuleException.cs (96%) diff --git a/ArchUnitNET.xUnit/Asserts/ArchRuleAsserts.cs b/ArchUnitNET.xUnit/ArchRuleAsserts.cs similarity index 94% rename from ArchUnitNET.xUnit/Asserts/ArchRuleAsserts.cs rename to ArchUnitNET.xUnit/ArchRuleAsserts.cs index 8769fa318..5fb4058e2 100644 --- a/ArchUnitNET.xUnit/Asserts/ArchRuleAsserts.cs +++ b/ArchUnitNET.xUnit/ArchRuleAsserts.cs @@ -6,13 +6,11 @@ using ArchUnitNET.Domain; using ArchUnitNET.Fluent; -using Xunit.Sdk; - // ReSharper disable once CheckNamespace -namespace Xunit +namespace ArchUnitNET.xUnit { - partial class Assert + public class ArchRuleAssert { /// /// Verifies that the architecture meets the criteria of the archrule. diff --git a/ArchUnitNET.xUnit/ArchRuleExtensions.cs b/ArchUnitNET.xUnit/ArchRuleExtensions.cs index f9f8e35bd..1c0ab0105 100644 --- a/ArchUnitNET.xUnit/ArchRuleExtensions.cs +++ b/ArchUnitNET.xUnit/ArchRuleExtensions.cs @@ -8,7 +8,7 @@ using ArchUnitNET.Fluent; // ReSharper disable once CheckNamespace -namespace Xunit +namespace ArchUnitNET.xUnit { public static class ArchRuleExtensions { @@ -19,7 +19,7 @@ public static class ArchRuleExtensions /// The architecture to be tested public static void Check(this IArchRule archRule, Architecture architecture) { - Assert.ArchRule(architecture, archRule); + ArchRuleAssert.ArchRule(architecture, archRule); } /// @@ -29,7 +29,7 @@ public static void Check(this IArchRule archRule, Architecture architecture) /// The rule to test the architecture with public static void CheckRule(this Architecture architecture, IArchRule archRule) { - Assert.ArchRule(architecture, archRule); + ArchRuleAssert.ArchRule(architecture, archRule); } } } \ No newline at end of file diff --git a/ArchUnitNET.xUnit/ArchUnitNET.xUnit.csproj b/ArchUnitNET.xUnit/ArchUnitNET.xUnit.csproj index 8a40c4000..2d50b6ec8 100644 --- a/ArchUnitNET.xUnit/ArchUnitNET.xUnit.csproj +++ b/ArchUnitNET.xUnit/ArchUnitNET.xUnit.csproj @@ -19,13 +19,11 @@ - - - + - + diff --git a/ArchUnitNET.xUnit/Asserts/Sdk/Exceptions/FailedArchRuleException.cs b/ArchUnitNET.xUnit/FailedArchRuleException.cs similarity index 96% rename from ArchUnitNET.xUnit/Asserts/Sdk/Exceptions/FailedArchRuleException.cs rename to ArchUnitNET.xUnit/FailedArchRuleException.cs index 02c4fca35..04141c0f4 100644 --- a/ArchUnitNET.xUnit/Asserts/Sdk/Exceptions/FailedArchRuleException.cs +++ b/ArchUnitNET.xUnit/FailedArchRuleException.cs @@ -8,9 +8,10 @@ using ArchUnitNET.Domain; using ArchUnitNET.Fluent; using ArchUnitNET.Fluent.Extensions; +using Xunit.Sdk; // ReSharper disable once CheckNamespace -namespace Xunit.Sdk +namespace ArchUnitNET.xUnit { public class FailedArchRuleException : XunitException { diff --git a/ArchUnitNETTests/ArchUnitNETTests.csproj b/ArchUnitNETTests/ArchUnitNETTests.csproj index 5254a454e..ff679dc18 100644 --- a/ArchUnitNETTests/ArchUnitNETTests.csproj +++ b/ArchUnitNETTests/ArchUnitNETTests.csproj @@ -13,6 +13,7 @@ + diff --git a/ArchUnitNETTests/ArchitectureTests/ArchUnitArchitectureTests.cs b/ArchUnitNETTests/ArchitectureTests/ArchUnitArchitectureTests.cs index 6a8f3b8ac..8acc3140c 100644 --- a/ArchUnitNETTests/ArchitectureTests/ArchUnitArchitectureTests.cs +++ b/ArchUnitNETTests/ArchitectureTests/ArchUnitArchitectureTests.cs @@ -8,6 +8,7 @@ using ArchUnitNET.Domain; using ArchUnitNET.Fluent; using ArchUnitNET.Loader; +using ArchUnitNET.xUnit; using Xunit; using static ArchUnitNET.Fluent.ArchRuleDefinition; diff --git a/ArchUnitNETTests/Fluent/RuleEvaluationTests.cs b/ArchUnitNETTests/Fluent/RuleEvaluationTests.cs index 40a4ab34f..6fc3f20a4 100644 --- a/ArchUnitNETTests/Fluent/RuleEvaluationTests.cs +++ b/ArchUnitNETTests/Fluent/RuleEvaluationTests.cs @@ -7,9 +7,9 @@ using ArchUnitNET.Domain; using ArchUnitNET.Fluent; using ArchUnitNET.Fluent.Extensions; +using ArchUnitNET.xUnit; using ArchUnitNETTests.Domain; using Xunit; -using Xunit.Sdk; using static System.Environment; using static ArchUnitNET.Fluent.ArchRuleDefinition; @@ -17,9 +17,11 @@ namespace ArchUnitNETTests.Fluent { public class RuleEvaluationTests { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; private const string NoClassName = "NotTheNameOfAnyClass_1592479214"; + private const string ExpectedTrueArchRuleErrorMessage = "All Evaluations passed"; + private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly IArchRule TrueArchRule1 = Classes().That().ArePrivate().Should().BePrivate(); private static readonly IArchRule TrueArchRule2 = Members().Should().Exist(); @@ -49,7 +51,13 @@ public class RuleEvaluationTests private static readonly IArchRule WrongArchRule1AndWrongArchRule3 = WrongArchRule1.And(WrongArchRule3); private static readonly IArchRule WrongArchRule4AndWrongArchRule8 = WrongArchRule4.And(WrongArchRule8); - private const string ExpectedTrueArchRuleErrorMessage = "All Evaluations passed"; + private readonly string _expectedWrongArchRule1AndWrongArchRule3ErrorMessage = + "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private\" failed:" + + NewLine + "\tArchUnitNETTests.Domain.PublicTestClass is public" + NewLine + + NewLine + + "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private and should be public or should be protected\" failed:" + + NewLine + "\tArchUnitNETTests.Domain.PublicTestClass is public" + + NewLine + NewLine; private readonly string _expectedWrongArchRule1ErrorMessage = "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private\" failed:" + @@ -67,6 +75,14 @@ public class RuleEvaluationTests NewLine + "\tArchUnitNETTests.Domain.PublicTestClass is public" + NewLine + NewLine; + private readonly string _expectedWrongArchRule4AndWrongArchRule8ErrorMessage = + "\"Classes that have name \"NotTheNameOfAnyClass_1592479214\" should exist\" failed:" + + NewLine + "\tThere are no objects matching the criteria" + NewLine + + NewLine + + "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should not exist or should be private\" failed:" + + NewLine + "\tArchUnitNETTests.Domain.PublicTestClass does exist and is public" + + NewLine + NewLine; + private readonly string _expectedWrongArchRule4ErrorMessage = "\"Classes that have name \"NotTheNameOfAnyClass_1592479214\" should exist\" failed:" + NewLine + "\tThere are no objects matching the criteria" + NewLine + @@ -92,47 +108,31 @@ public class RuleEvaluationTests NewLine + "\tArchUnitNETTests.Domain.PublicTestClass does exist and is public" + NewLine + NewLine; - private readonly string _expectedWrongArchRule1AndWrongArchRule3ErrorMessage = - "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private\" failed:" + - NewLine + "\tArchUnitNETTests.Domain.PublicTestClass is public" + NewLine + - NewLine + - "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private and should be public or should be protected\" failed:" + - NewLine + "\tArchUnitNETTests.Domain.PublicTestClass is public" + - NewLine + NewLine; - - private readonly string _expectedWrongArchRule4AndWrongArchRule8ErrorMessage = - "\"Classes that have name \"NotTheNameOfAnyClass_1592479214\" should exist\" failed:" + - NewLine + "\tThere are no objects matching the criteria" + NewLine + - NewLine + - "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should not exist or should be private\" failed:" + - NewLine + "\tArchUnitNETTests.Domain.PublicTestClass does exist and is public" + - NewLine + NewLine; - [Fact] public void AssertArchRuleTest() { - Assert.ArchRule(Architecture, TrueArchRule1); - Assert.ArchRule(Architecture, TrueArchRule2); + ArchRuleAssert.ArchRule(Architecture, TrueArchRule1); + ArchRuleAssert.ArchRule(Architecture, TrueArchRule2); var exception1 = - Assert.Throws(() => Assert.ArchRule(Architecture, WrongArchRule1)); + Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule1)); var exception2 = - Assert.Throws(() => Assert.ArchRule(Architecture, WrongArchRule2)); + Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule2)); var exception3 = - Assert.Throws(() => Assert.ArchRule(Architecture, WrongArchRule3)); + Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule3)); var exception4 = - Assert.Throws(() => Assert.ArchRule(Architecture, WrongArchRule4)); + Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule4)); var exception5 = - Assert.Throws(() => Assert.ArchRule(Architecture, WrongArchRule5)); + Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule5)); var exception6 = - Assert.Throws(() => Assert.ArchRule(Architecture, WrongArchRule6)); + Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule6)); var exception7 = - Assert.Throws(() => Assert.ArchRule(Architecture, WrongArchRule7)); + Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule7)); var exception8 = - Assert.Throws(() => Assert.ArchRule(Architecture, WrongArchRule8)); + Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule8)); var exception1And3 = Assert.Throws(() => - Assert.ArchRule(Architecture, WrongArchRule1AndWrongArchRule3)); + ArchRuleAssert.ArchRule(Architecture, WrongArchRule1AndWrongArchRule3)); var exception4And8 = Assert.Throws(() => - Assert.ArchRule(Architecture, WrongArchRule4AndWrongArchRule8)); + ArchRuleAssert.ArchRule(Architecture, WrongArchRule4AndWrongArchRule8)); Assert.Equal(_expectedWrongArchRule1ErrorMessage, exception1.Message); Assert.Equal(_expectedWrongArchRule2ErrorMessage, exception2.Message); diff --git a/ArchUnitNETTests/Fluent/Slices/SlicesTests.cs b/ArchUnitNETTests/Fluent/Slices/SlicesTests.cs index 8dc40a766..906ae1303 100644 --- a/ArchUnitNETTests/Fluent/Slices/SlicesTests.cs +++ b/ArchUnitNETTests/Fluent/Slices/SlicesTests.cs @@ -7,8 +7,8 @@ using System.Linq; using ArchUnitNET.Fluent.Slices; +using ArchUnitNET.xUnit; using Xunit; -using Xunit.Sdk; namespace ArchUnitNETTests.Fluent.Slices { diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/CustomSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/CustomSyntaxElementsTests.cs index 0b27ab08d..0477f526a 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/CustomSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/CustomSyntaxElementsTests.cs @@ -9,6 +9,7 @@ using ArchUnitNET.Domain; using ArchUnitNET.Domain.Extensions; using ArchUnitNET.Loader; +using ArchUnitNET.xUnit; using Xunit; using static ArchUnitNET.Fluent.ArchRuleDefinition; diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs index 64bb1860b..6a0abed0a 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs @@ -10,6 +10,7 @@ using ArchUnitNET.Domain; using ArchUnitNET.Domain.Extensions; using ArchUnitNET.Fluent; +using ArchUnitNET.xUnit; using ArchUnitNETTests.Domain; using Xunit; using static ArchUnitNETTests.Domain.StaticTestTypes; diff --git a/ArchUnitNETTests/StaticTestArchitectures.cs b/ArchUnitNETTests/StaticTestArchitectures.cs index 104e2ad7b..d3fc5bbf2 100644 --- a/ArchUnitNETTests/StaticTestArchitectures.cs +++ b/ArchUnitNETTests/StaticTestArchitectures.cs @@ -6,10 +6,10 @@ using ArchUnitNET.Domain; using ArchUnitNET.Loader; +using ArchUnitNET.xUnit; using ArchUnitNETTests.Domain.Dependencies.Attributes; using ArchUnitNETTests.Domain.Dependencies.Members; using TestAssembly; -using Xunit.Sdk; // ReSharper disable InconsistentNaming diff --git a/ExampleTest/ExampleArchUnitTest.cs b/ExampleTest/ExampleArchUnitTest.cs index d50d01dae..f94082a12 100644 --- a/ExampleTest/ExampleArchUnitTest.cs +++ b/ExampleTest/ExampleArchUnitTest.cs @@ -11,6 +11,7 @@ using ArchUnitNET.Domain; using ArchUnitNET.Fluent; using ArchUnitNET.Loader; +using ArchUnitNET.xUnit; using Xunit; using static ArchUnitNET.Fluent.ArchRuleDefinition; diff --git a/ExampleTest/ExampleTest.csproj b/ExampleTest/ExampleTest.csproj index 2e98c647b..2d2b2a4b4 100644 --- a/ExampleTest/ExampleTest.csproj +++ b/ExampleTest/ExampleTest.csproj @@ -12,6 +12,7 @@ + From 6cdc6199e932effdab427ee9c00921b816931bc8 Mon Sep 17 00:00:00 2001 From: Fritz Brandhuber Date: Fri, 26 Feb 2021 20:40:11 +0100 Subject: [PATCH 2/3] rename ArchRuleAssert.ArchRule() to ArchRuleAssert.CheckRule() Signed-off-by: Fritz Brandhuber --- .../{ArchRuleAsserts.cs => ArchRuleAssert.cs} | 2 +- ArchUnitNET.xUnit/ArchRuleExtensions.cs | 4 ++-- .../Fluent/RuleEvaluationTests.cs | 24 +++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) rename ArchUnitNET.xUnit/{ArchRuleAsserts.cs => ArchRuleAssert.cs} (91%) diff --git a/ArchUnitNET.xUnit/ArchRuleAsserts.cs b/ArchUnitNET.xUnit/ArchRuleAssert.cs similarity index 91% rename from ArchUnitNET.xUnit/ArchRuleAsserts.cs rename to ArchUnitNET.xUnit/ArchRuleAssert.cs index 5fb4058e2..76435bfc8 100644 --- a/ArchUnitNET.xUnit/ArchRuleAsserts.cs +++ b/ArchUnitNET.xUnit/ArchRuleAssert.cs @@ -18,7 +18,7 @@ public class ArchRuleAssert /// The architecture to be tested /// The rule to test the architecture with /// Thrown if the rule is violated - public static void ArchRule(Architecture architecture, IArchRule archRule) + public static void CheckRule(Architecture architecture, IArchRule archRule) { if (!archRule.HasNoViolations(architecture)) { diff --git a/ArchUnitNET.xUnit/ArchRuleExtensions.cs b/ArchUnitNET.xUnit/ArchRuleExtensions.cs index 1c0ab0105..8febf694e 100644 --- a/ArchUnitNET.xUnit/ArchRuleExtensions.cs +++ b/ArchUnitNET.xUnit/ArchRuleExtensions.cs @@ -19,7 +19,7 @@ public static class ArchRuleExtensions /// The architecture to be tested public static void Check(this IArchRule archRule, Architecture architecture) { - ArchRuleAssert.ArchRule(architecture, archRule); + ArchRuleAssert.CheckRule(architecture, archRule); } /// @@ -29,7 +29,7 @@ public static void Check(this IArchRule archRule, Architecture architecture) /// The rule to test the architecture with public static void CheckRule(this Architecture architecture, IArchRule archRule) { - ArchRuleAssert.ArchRule(architecture, archRule); + ArchRuleAssert.CheckRule(architecture, archRule); } } } \ No newline at end of file diff --git a/ArchUnitNETTests/Fluent/RuleEvaluationTests.cs b/ArchUnitNETTests/Fluent/RuleEvaluationTests.cs index 6fc3f20a4..3a77f05a4 100644 --- a/ArchUnitNETTests/Fluent/RuleEvaluationTests.cs +++ b/ArchUnitNETTests/Fluent/RuleEvaluationTests.cs @@ -111,28 +111,28 @@ public class RuleEvaluationTests [Fact] public void AssertArchRuleTest() { - ArchRuleAssert.ArchRule(Architecture, TrueArchRule1); - ArchRuleAssert.ArchRule(Architecture, TrueArchRule2); + ArchRuleAssert.CheckRule(Architecture, TrueArchRule1); + ArchRuleAssert.CheckRule(Architecture, TrueArchRule2); var exception1 = - Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule1)); + Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule1)); var exception2 = - Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule2)); + Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule2)); var exception3 = - Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule3)); + Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule3)); var exception4 = - Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule4)); + Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule4)); var exception5 = - Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule5)); + Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule5)); var exception6 = - Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule6)); + Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule6)); var exception7 = - Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule7)); + Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule7)); var exception8 = - Assert.Throws(() => ArchRuleAssert.ArchRule(Architecture, WrongArchRule8)); + Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule8)); var exception1And3 = Assert.Throws(() => - ArchRuleAssert.ArchRule(Architecture, WrongArchRule1AndWrongArchRule3)); + ArchRuleAssert.CheckRule(Architecture, WrongArchRule1AndWrongArchRule3)); var exception4And8 = Assert.Throws(() => - ArchRuleAssert.ArchRule(Architecture, WrongArchRule4AndWrongArchRule8)); + ArchRuleAssert.CheckRule(Architecture, WrongArchRule4AndWrongArchRule8)); Assert.Equal(_expectedWrongArchRule1ErrorMessage, exception1.Message); Assert.Equal(_expectedWrongArchRule2ErrorMessage, exception2.Message); From 744d02a587122e2d8ec6a4bc08551406dd8cd2b6 Mon Sep 17 00:00:00 2001 From: Fritz Brandhuber Date: Fri, 26 Feb 2021 20:41:36 +0100 Subject: [PATCH 3/3] make ArchRuleAssert static Signed-off-by: Fritz Brandhuber --- ArchUnitNET.xUnit/ArchRuleAssert.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ArchUnitNET.xUnit/ArchRuleAssert.cs b/ArchUnitNET.xUnit/ArchRuleAssert.cs index 76435bfc8..4119f00a7 100644 --- a/ArchUnitNET.xUnit/ArchRuleAssert.cs +++ b/ArchUnitNET.xUnit/ArchRuleAssert.cs @@ -10,7 +10,7 @@ // ReSharper disable once CheckNamespace namespace ArchUnitNET.xUnit { - public class ArchRuleAssert + public static class ArchRuleAssert { /// /// Verifies that the architecture meets the criteria of the archrule.