Skip to content

Commit d3ba159

Browse files
Merge branch 'main' into ci/given-objects-that-tests
2 parents 0905114 + b87dee6 commit d3ba159

File tree

14 files changed

+214
-16
lines changed

14 files changed

+214
-16
lines changed

.github/workflows/build.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Checkout
20-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2121
- name: Setup .NET
2222
uses: actions/setup-dotnet@3951f0dfe7a07e2313ec93c75700083e2005cbab # v4.3.0
2323
with:
24-
dotnet-version: 9.0.200
24+
dotnet-version: 9.0.304
2525
- name: Install tools
2626
run: dotnet tool restore
2727
- name: Check formatting
@@ -31,11 +31,11 @@ jobs:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- name: Checkout
34-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
34+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3535
- name: Setup .NET
3636
uses: actions/setup-dotnet@3951f0dfe7a07e2313ec93c75700083e2005cbab # v4.3.0
3737
with:
38-
dotnet-version: 9.0.200
38+
dotnet-version: 9.0.304
3939
- name: Run tests
4040
run: dotnet test -c Debug --collect:"XPlat Code Coverage" --settings coverlet.runsettings ArchUnitNETTests/
4141
- name: Upload coverage reports to Codecov
@@ -50,11 +50,11 @@ jobs:
5050
runs-on: ${{ matrix.os }}
5151
steps:
5252
- name: Checkout
53-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
53+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
5454
- name: Setup .NET
5555
uses: actions/setup-dotnet@3951f0dfe7a07e2313ec93c75700083e2005cbab # v4.3.0
5656
with:
57-
dotnet-version: 9.0.200
57+
dotnet-version: 9.0.304
5858
- name: Run tests
5959
run: dotnet test -c Debug
6060
publish-docs:
@@ -68,7 +68,7 @@ jobs:
6868
contents: write
6969
steps:
7070
- name: Checkout
71-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
71+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
7272
- name: Setup doxygen
7373
run: sudo apt-get install doxygen graphviz
7474
- name: Create temporary directory
@@ -88,7 +88,7 @@ jobs:
8888
fi
8989
fi
9090
- name: Checkout gh-pages branch
91-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
91+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
9292
with:
9393
ref: gh-pages
9494
path: ${{ env.DOCS_TEMP_DIR }}
@@ -136,11 +136,11 @@ jobs:
136136
- run-tests
137137
steps:
138138
- name: Checkout
139-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
139+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
140140
- name: Setup .NET
141141
uses: actions/setup-dotnet@3951f0dfe7a07e2313ec93c75700083e2005cbab # v4.3.0
142142
with:
143-
dotnet-version: 9.0.200
143+
dotnet-version: 9.0.304
144144
- name: Build
145145
run: dotnet build -c Release
146146
- name: Pack

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
language: ["csharp"]
2222
steps:
2323
- name: Checkout repository
24-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2525
- name: Initialize CodeQL
2626
uses: github/codeql-action/init@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # v3.28.9
2727
with:

ArchUnit.sln

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.xUnitTests", "A
4040
EndProject
4141
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.xUnitV3Tests", "ArchUnitNET.xUnitV3Tests\ArchUnitNET.xUnitV3Tests.csproj", "{439E00CE-5CB8-4474-9A27-3FFC5770DB7C}"
4242
EndProject
43+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.TUnit", "ArchUnitNET.TUnit\ArchUnitNET.TUnit.csproj", "{AD4D9490-F6F1-47DC-9F52-FD15497CDE55}"
44+
EndProject
45+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.TUnitTests", "ArchUnitNET.TUnitTests\ArchUnitNET.TUnitTests.csproj", "{C54143CE-3256-4313-B991-0706705EEA1D}"
46+
EndProject
4347
Global
4448
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4549
Debug|Any CPU = Debug|Any CPU
@@ -118,6 +122,14 @@ Global
118122
{439E00CE-5CB8-4474-9A27-3FFC5770DB7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
119123
{439E00CE-5CB8-4474-9A27-3FFC5770DB7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
120124
{439E00CE-5CB8-4474-9A27-3FFC5770DB7C}.Release|Any CPU.Build.0 = Release|Any CPU
125+
{AD4D9490-F6F1-47DC-9F52-FD15497CDE55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
126+
{AD4D9490-F6F1-47DC-9F52-FD15497CDE55}.Debug|Any CPU.Build.0 = Debug|Any CPU
127+
{AD4D9490-F6F1-47DC-9F52-FD15497CDE55}.Release|Any CPU.ActiveCfg = Release|Any CPU
128+
{AD4D9490-F6F1-47DC-9F52-FD15497CDE55}.Release|Any CPU.Build.0 = Release|Any CPU
129+
{C54143CE-3256-4313-B991-0706705EEA1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
130+
{C54143CE-3256-4313-B991-0706705EEA1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
131+
{C54143CE-3256-4313-B991-0706705EEA1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
132+
{C54143CE-3256-4313-B991-0706705EEA1D}.Release|Any CPU.Build.0 = Release|Any CPU
121133
EndGlobalSection
122134
GlobalSection(SolutionProperties) = preSolution
123135
HideSolutionNode = FALSE
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using ArchUnitNET.Domain;
2+
using ArchUnitNET.Fluent;
3+
4+
// ReSharper disable once CheckNamespace
5+
namespace ArchUnitNET.TUnit
6+
{
7+
public static class ArchRuleAssert
8+
{
9+
/// <summary>
10+
/// Verifies that the architecture meets the criteria of the archrule.
11+
/// </summary>
12+
/// <param name="architecture">The architecture to be tested</param>
13+
/// <param name="archRule">The rule to test the architecture with</param>
14+
public static void CheckRule(Architecture architecture, IArchRule archRule)
15+
{
16+
if (!archRule.HasNoViolations(architecture))
17+
{
18+
var results = archRule.Evaluate(architecture);
19+
throw new FailedArchRuleException(architecture, archRule);
20+
}
21+
}
22+
}
23+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using ArchUnitNET.Domain;
2+
using ArchUnitNET.Fluent;
3+
4+
// ReSharper disable once CheckNamespace
5+
namespace ArchUnitNET.TUnit
6+
{
7+
public static class ArchRuleExtensions
8+
{
9+
/// <summary>
10+
/// Verifies that the architecture meets the criteria of the archrule.
11+
/// </summary>
12+
/// <param name="archRule">The rule to test the architecture with</param>
13+
/// <param name="architecture">The architecture to be tested</param>
14+
public static void Check(this IArchRule archRule, Architecture architecture)
15+
{
16+
ArchRuleAssert.CheckRule(architecture, archRule);
17+
}
18+
19+
/// <summary>
20+
/// Verifies that the architecture meets the criteria of the archrule.
21+
/// </summary>
22+
/// <param name="architecture">The architecture to be tested</param>
23+
/// <param name="archRule">The rule to test the architecture with</param>
24+
public static void CheckRule(this Architecture architecture, IArchRule archRule)
25+
{
26+
ArchRuleAssert.CheckRule(architecture, archRule);
27+
}
28+
}
29+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
4+
<LangVersion>latest</LangVersion>
5+
<IsPackable>true</IsPackable>
6+
<Title>ArchUnit C# TUnit Extension</Title>
7+
<Description>TUnit Extension for the C# Version of ArchUnit (see: archunit.org)</Description>
8+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
9+
<RepositoryUrl>https://github.com/TNG/ArchUnitNET</RepositoryUrl>
10+
<PackageTags>test;arch;archunit;tunit</PackageTags>
11+
<IncludeSource>False</IncludeSource>
12+
<Company>TNG Technology Consulting GmbH</Company>
13+
<PackageId>TngTech.ArchUnitNET.TUnit</PackageId>
14+
<IsTestProject>false</IsTestProject>
15+
<IncludeSymbols>true</IncludeSymbols>
16+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
17+
<PackageReadmeFile>README.md</PackageReadmeFile>
18+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
19+
<RootNamespace>ArchUnitNET.TUnit</RootNamespace>
20+
</PropertyGroup>
21+
<ItemGroup>
22+
<ProjectReference Include="..\ArchUnitNET\ArchUnitNET.csproj" />
23+
</ItemGroup>
24+
<ItemGroup>
25+
<PackageReference Include="System.Net.Http" Version="4.3.4" />
26+
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
27+
<PackageReference Include="TUnit.Assertions" Version="0.52.51" />
28+
</ItemGroup>
29+
<ItemGroup>
30+
<None Include="..\Logo\ArchUnitNET-Logo.png">
31+
<Pack>true</Pack>
32+
<PackagePath>/Logo/</PackagePath>
33+
<Link>ArchUnitNET-Logo.png</Link>
34+
</None>
35+
<None Include="..\README.md">
36+
<Pack>true</Pack>
37+
<PackagePath></PackagePath>
38+
<Link>README.md</Link>
39+
</None>
40+
</ItemGroup>
41+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Generic;
2+
using ArchUnitNET.Domain;
3+
using ArchUnitNET.Fluent;
4+
using ArchUnitNET.Fluent.Extensions;
5+
using TUnit.Assertions.Exceptions;
6+
7+
// ReSharper disable once CheckNamespace
8+
namespace ArchUnitNET.TUnit
9+
{
10+
public class FailedArchRuleException : BaseAssertionException
11+
{
12+
/// <summary>
13+
/// Creates a new instance of the <see href="FailedArchRuleException" /> class.
14+
/// </summary>
15+
/// <param name="architecture">The architecture which was tested</param>
16+
/// <param name="archRule">The archrule that failed</param>
17+
public FailedArchRuleException(Architecture architecture, IArchRule archRule)
18+
: this(archRule.Evaluate(architecture)) { }
19+
20+
/// <summary>
21+
/// Creates a new instance of the <see href="FailedArchRuleException" /> class.
22+
/// </summary>
23+
/// <param name="evaluationResults">The results of the evaluation of the archrule</param>
24+
public FailedArchRuleException(IEnumerable<EvaluationResult> evaluationResults)
25+
: base(evaluationResults.ToErrorMessage()) { }
26+
}
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net9.0</TargetFramework>
4+
<IsPackable>false</IsPackable>
5+
<Company>TNG Technology Consulting GmbH</Company>
6+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
10+
<PackageReference Include="TUnit" Version="0.52.51" />
11+
</ItemGroup>
12+
<ItemGroup>
13+
<ProjectReference Include="..\ArchUnitNET.TUnit\ArchUnitNET.TUnit.csproj" />
14+
</ItemGroup>
15+
</Project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System.Threading.Tasks;
2+
using ArchUnitNET.Domain;
3+
using ArchUnitNET.Fluent;
4+
using ArchUnitNET.Fluent.Extensions;
5+
using ArchUnitNET.Loader;
6+
using ArchUnitNET.TUnit;
7+
using static ArchUnitNET.Fluent.ArchRuleDefinition;
8+
9+
namespace ArchUnitNET.TUnitTests
10+
{
11+
public class RuleEvaluationTests
12+
{
13+
private readonly Architecture _architecture;
14+
private readonly string _expectedErrorMessage;
15+
private readonly IArchRule _falseRule;
16+
private readonly IArchRule _trueRule;
17+
18+
public RuleEvaluationTests()
19+
{
20+
_architecture = new ArchLoader()
21+
.LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.TUnitTests"))
22+
.Build();
23+
_trueRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().Exist();
24+
_falseRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().NotExist();
25+
_expectedErrorMessage = _falseRule.Evaluate(_architecture).ToErrorMessage();
26+
}
27+
28+
[Test]
29+
public async Task ArchRuleAssertTest()
30+
{
31+
ArchRuleAssert.CheckRule(_architecture, _trueRule);
32+
var ex = Assert.Throws<FailedArchRuleException>(() =>
33+
ArchRuleAssert.CheckRule(_architecture, _falseRule)
34+
);
35+
await Assert.That(ex.Message).IsEqualTo(_expectedErrorMessage);
36+
}
37+
38+
[Test]
39+
public async Task ArchRuleExtensionsTest()
40+
{
41+
_architecture.CheckRule(_trueRule);
42+
_trueRule.Check(_architecture);
43+
var ex1 = Assert.Throws<FailedArchRuleException>(() =>
44+
_architecture.CheckRule(_falseRule)
45+
);
46+
var ex2 = Assert.Throws<FailedArchRuleException>(() => _falseRule.Check(_architecture));
47+
await Assert.That(ex1.Message).IsEqualTo(_expectedErrorMessage);
48+
await Assert.That(ex2.Message).IsEqualTo(_expectedErrorMessage);
49+
}
50+
}
51+
}

ArchUnitNET.xUnitTests/ArchUnitNET.xUnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77
</PropertyGroup>
88
<ItemGroup>
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
1010
<PackageReference Include="xunit" Version="2.9.3" />
1111
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2" />
1212
</ItemGroup>

0 commit comments

Comments
 (0)