Skip to content

Commit

Permalink
Merge pull request #28 from GeorgKreuzmayr/notdependon-errormessage
Browse files Browse the repository at this point in the history
Improve Error Messages
  • Loading branch information
fgather authored Oct 31, 2020
2 parents d4c4f7a + 2bd13ea commit 83da580
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ IEnumerable<ConditionResult> Condition(IEnumerable<TRuleType> 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;
Expand Down Expand Up @@ -1471,7 +1471,7 @@ IEnumerable<ConditionResult> Condition(IEnumerable<TRuleType> 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;
Expand Down Expand Up @@ -1516,7 +1516,7 @@ IEnumerable<ConditionResult> Condition(IEnumerable<TRuleType> 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;
Expand Down
77 changes: 77 additions & 0 deletions ArchUnitNETTests/Fluent/DependencyErrorMessageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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.Loader;
using Xunit;
using static ArchUnitNET.Fluent.ArchRuleDefinition;

namespace ArchUnitNETTests.Fluent
{
public class DependencyErrorMessageTests
{
private static readonly Architecture Architecture =
StaticTestArchitectures.ArchUnitNETTestArchitecture;

[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
{

}
}

0 comments on commit 83da580

Please sign in to comment.