From 9917fe074f9c09a585f795826cd2ac75144f0bb1 Mon Sep 17 00:00:00 2001 From: GeorgKreuzmayr Date: Thu, 15 Oct 2020 10:23:58 +0200 Subject: [PATCH 1/3] Enhance NotDependOnAny Error Message Signed-off-by: GeorgKreuzmayr --- .../Fluent/Syntax/Elements/ObjectConditionsDefinition.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs index f60ba30af..7de8b78c1 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs @@ -1439,7 +1439,7 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite { var dynamicFailDescription = "does depend on"; var first = true; - foreach (var type in failedObject.GetTypeDependencies().Union(typeList)) + foreach (var type in failedObject.GetTypeDependencies().Intersect(typeList)) { dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; first = false; @@ -1471,7 +1471,7 @@ IEnumerable Condition(IEnumerable ruleTypes) { var dynamicFailDescription = "does depend on"; var first = true; - foreach (var type in failedObject.GetTypeDependencies().Union(typeList)) + foreach (var type in failedObject.GetTypeDependencies().Intersect(typeList)) { dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; first = false; @@ -1516,7 +1516,7 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite { var dynamicFailDescription = "does depend on"; var first = true; - foreach (var type in failedObject.GetTypeDependencies().Union(iTypeList)) + foreach (var type in failedObject.GetTypeDependencies().Intersect(iTypeList)) { dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; first = false; From 4530f52d7c48a9cdd4be54a22ce776101aae9f2a Mon Sep 17 00:00:00 2001 From: GeorgKreuzmayr Date: Thu, 15 Oct 2020 10:24:14 +0200 Subject: [PATCH 2/3] Implement Tests for NotDependOnAny Error Message Signed-off-by: GeorgKreuzmayr --- .../Fluent/DependencyErrorMessageTests.cs | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 ArchUnitNETTests/Fluent/DependencyErrorMessageTests.cs diff --git a/ArchUnitNETTests/Fluent/DependencyErrorMessageTests.cs b/ArchUnitNETTests/Fluent/DependencyErrorMessageTests.cs new file mode 100644 index 000000000..bf3f9b93b --- /dev/null +++ b/ArchUnitNETTests/Fluent/DependencyErrorMessageTests.cs @@ -0,0 +1,77 @@ +// Copyright 2019 Florian Gather +// Copyright 2019 Fritz Brandhuber +// Copyright 2020 Pavel Fischer +// +// SPDX-License-Identifier: Apache-2.0 +// + +using System.Linq; +using ArchUnitNET.Domain; +using ArchUnitNET.Loader; +using Xunit; +using static ArchUnitNET.Fluent.ArchRuleDefinition; + +namespace ArchUnitNETTests.Fluent +{ + public class DependencyErrorMessageTests + { + private static readonly Architecture Architecture = + new ArchLoader().LoadAssembly(typeof(DependencyErrorMessageTests).Assembly).Build(); + + [Fact] + public void ErrorMessageType() + { + var rule = Classes().That() + .HaveFullNameMatching(typeof(DependencyErrorMessageTestClass).FullName) + .Should().NotDependOnAny(typeof(ErrorMessageClass1), typeof(ErrorMessageClass2)); + var failDescription = rule.Evaluate(Architecture).ToList().First().Description; + Assert.DoesNotContain(typeof(string).FullName, failDescription); + Assert.DoesNotContain(typeof(ErrorMessageClass2).FullName, failDescription); + Assert.Contains(typeof(ErrorMessageClass1).FullName, failDescription); + } + + [Fact] + public void ErrorMessageIType() + { + var dependencyClass = Classes().That().HaveFullNameMatching(typeof(ErrorMessageClass1).FullName).Or().HaveFullNameMatching(typeof(ErrorMessageClass2).FullName) + .GetObjects(Architecture).ToList(); + var rule = Classes().That() + .HaveFullNameMatching(typeof(DependencyErrorMessageTestClass).FullName) + .Should().NotDependOnAny(dependencyClass); + var failDescription = rule.Evaluate(Architecture).ToList().First().Description; + Assert.DoesNotContain(typeof(string).FullName, failDescription); + Assert.DoesNotContain(typeof(ErrorMessageClass2).FullName, failDescription); + Assert.Contains(typeof(ErrorMessageClass1).FullName, failDescription); + } + + [Fact] + public void ErrorMessageIObjectProvider() + { + var dependencyClass = Classes().That().HaveFullNameMatching(typeof(ErrorMessageClass1).FullName).Or() + .HaveFullNameMatching(typeof(ErrorMessageClass2).FullName); + var rule = Classes().That() + .HaveFullNameMatching(typeof(DependencyErrorMessageTestClass).FullName) + .Should().NotDependOnAny(dependencyClass); + var failDescription = rule.Evaluate(Architecture).ToList().First().Description; + Assert.DoesNotContain(typeof(string).FullName, failDescription); + Assert.DoesNotContain(typeof(ErrorMessageClass2).FullName, failDescription); + Assert.Contains(typeof(ErrorMessageClass1).FullName, failDescription); + } + } + + public class DependencyErrorMessageTestClass + { + ErrorMessageClass1 testData = new ErrorMessageClass1(); + private string testString = ""; + } + + public class ErrorMessageClass1 + { + + } + + public class ErrorMessageClass2 + { + + } +} From 2bd13ea9a286257446b2c7cdd186a339d6390f43 Mon Sep 17 00:00:00 2001 From: GeorgKreuzmayr Date: Fri, 16 Oct 2020 11:04:07 +0200 Subject: [PATCH 3/3] Use static Test Architecture Signed-off-by: GeorgKreuzmayr --- ArchUnitNETTests/Fluent/DependencyErrorMessageTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ArchUnitNETTests/Fluent/DependencyErrorMessageTests.cs b/ArchUnitNETTests/Fluent/DependencyErrorMessageTests.cs index bf3f9b93b..95af9e9db 100644 --- a/ArchUnitNETTests/Fluent/DependencyErrorMessageTests.cs +++ b/ArchUnitNETTests/Fluent/DependencyErrorMessageTests.cs @@ -16,7 +16,7 @@ namespace ArchUnitNETTests.Fluent public class DependencyErrorMessageTests { private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(DependencyErrorMessageTests).Assembly).Build(); + StaticTestArchitectures.ArchUnitNETTestArchitecture; [Fact] public void ErrorMessageType()