Skip to content

Commit

Permalink
Merge pull request #57 from brandhuf/xunit-assert-fix
Browse files Browse the repository at this point in the history
Xunit assert fix
  • Loading branch information
fgather authored Feb 26, 2021
2 parents 57ac8c0 + 744d02a commit 11a80e4
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@

using ArchUnitNET.Domain;
using ArchUnitNET.Fluent;
using Xunit.Sdk;


// ReSharper disable once CheckNamespace
namespace Xunit
namespace ArchUnitNET.xUnit
{
partial class Assert
public static class ArchRuleAssert
{
/// <summary>
/// Verifies that the architecture meets the criteria of the archrule.
/// </summary>
/// <param name="architecture">The architecture to be tested</param>
/// <param name="archRule">The rule to test the architecture with</param>
/// <exception cref="FailedArchRuleException">Thrown if the rule is violated</exception>
public static void ArchRule(Architecture architecture, IArchRule archRule)
public static void CheckRule(Architecture architecture, IArchRule archRule)
{
if (!archRule.HasNoViolations(architecture))
{
Expand Down
6 changes: 3 additions & 3 deletions ArchUnitNET.xUnit/ArchRuleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using ArchUnitNET.Fluent;

// ReSharper disable once CheckNamespace
namespace Xunit
namespace ArchUnitNET.xUnit
{
public static class ArchRuleExtensions
{
Expand All @@ -19,7 +19,7 @@ public static class ArchRuleExtensions
/// <param name="architecture">The architecture to be tested</param>
public static void Check(this IArchRule archRule, Architecture architecture)
{
Assert.ArchRule(architecture, archRule);
ArchRuleAssert.CheckRule(architecture, archRule);
}

/// <summary>
Expand All @@ -29,7 +29,7 @@ public static void Check(this IArchRule archRule, Architecture architecture)
/// <param name="archRule">The rule to test the architecture with</param>
public static void CheckRule(this Architecture architecture, IArchRule archRule)
{
Assert.ArchRule(architecture, archRule);
ArchRuleAssert.CheckRule(architecture, archRule);
}
}
}
6 changes: 2 additions & 4 deletions ArchUnitNET.xUnit/ArchUnitNET.xUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.assert.source" Version="2.4.1" />
<PackageReference Include="xunit.core" Version="2.4.1" />
<ProjectReference Include="..\ArchUnitNET\ArchUnitNET.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ArchUnitNET\ArchUnitNET.csproj" />
<PackageReference Include="xunit.assert" Version="2.4.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions ArchUnitNETTests/ArchUnitNETTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using ArchUnitNET.Domain;
using ArchUnitNET.Fluent;
using ArchUnitNET.Loader;
using ArchUnitNET.xUnit;
using Xunit;
using static ArchUnitNET.Fluent.ArchRuleDefinition;

Expand Down
62 changes: 31 additions & 31 deletions ArchUnitNETTests/Fluent/RuleEvaluationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
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;

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();

Expand Down Expand Up @@ -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:" +
Expand All @@ -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 +
Expand All @@ -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.CheckRule(Architecture, TrueArchRule1);
ArchRuleAssert.CheckRule(Architecture, TrueArchRule2);
var exception1 =
Assert.Throws<FailedArchRuleException>(() => Assert.ArchRule(Architecture, WrongArchRule1));
Assert.Throws<FailedArchRuleException>(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule1));
var exception2 =
Assert.Throws<FailedArchRuleException>(() => Assert.ArchRule(Architecture, WrongArchRule2));
Assert.Throws<FailedArchRuleException>(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule2));
var exception3 =
Assert.Throws<FailedArchRuleException>(() => Assert.ArchRule(Architecture, WrongArchRule3));
Assert.Throws<FailedArchRuleException>(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule3));
var exception4 =
Assert.Throws<FailedArchRuleException>(() => Assert.ArchRule(Architecture, WrongArchRule4));
Assert.Throws<FailedArchRuleException>(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule4));
var exception5 =
Assert.Throws<FailedArchRuleException>(() => Assert.ArchRule(Architecture, WrongArchRule5));
Assert.Throws<FailedArchRuleException>(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule5));
var exception6 =
Assert.Throws<FailedArchRuleException>(() => Assert.ArchRule(Architecture, WrongArchRule6));
Assert.Throws<FailedArchRuleException>(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule6));
var exception7 =
Assert.Throws<FailedArchRuleException>(() => Assert.ArchRule(Architecture, WrongArchRule7));
Assert.Throws<FailedArchRuleException>(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule7));
var exception8 =
Assert.Throws<FailedArchRuleException>(() => Assert.ArchRule(Architecture, WrongArchRule8));
Assert.Throws<FailedArchRuleException>(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule8));
var exception1And3 = Assert.Throws<FailedArchRuleException>(() =>
Assert.ArchRule(Architecture, WrongArchRule1AndWrongArchRule3));
ArchRuleAssert.CheckRule(Architecture, WrongArchRule1AndWrongArchRule3));
var exception4And8 = Assert.Throws<FailedArchRuleException>(() =>
Assert.ArchRule(Architecture, WrongArchRule4AndWrongArchRule8));
ArchRuleAssert.CheckRule(Architecture, WrongArchRule4AndWrongArchRule8));

Assert.Equal(_expectedWrongArchRule1ErrorMessage, exception1.Message);
Assert.Equal(_expectedWrongArchRule2ErrorMessage, exception2.Message);
Expand Down
2 changes: 1 addition & 1 deletion ArchUnitNETTests/Fluent/Slices/SlicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

using System.Linq;
using ArchUnitNET.Fluent.Slices;
using ArchUnitNET.xUnit;
using Xunit;
using Xunit.Sdk;

namespace ArchUnitNETTests.Fluent.Slices
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using ArchUnitNET.Domain;
using ArchUnitNET.Domain.Extensions;
using ArchUnitNET.Loader;
using ArchUnitNET.xUnit;
using Xunit;
using static ArchUnitNET.Fluent.ArchRuleDefinition;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ArchUnitNETTests/StaticTestArchitectures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions ExampleTest/ExampleArchUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using ArchUnitNET.Domain;
using ArchUnitNET.Fluent;
using ArchUnitNET.Loader;
using ArchUnitNET.xUnit;
using Xunit;
using static ArchUnitNET.Fluent.ArchRuleDefinition;

Expand Down
1 change: 1 addition & 0 deletions ExampleTest/ExampleTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
</ItemGroup>

Expand Down

0 comments on commit 11a80e4

Please sign in to comment.