Skip to content

Commit db55093

Browse files
committed
Add MSTestV4 Support and add Proper Test Projects
Signed-off-by: SeMuell <s.mueller@gmx.org>
1 parent 4006980 commit db55093

File tree

12 files changed

+314
-10
lines changed

12 files changed

+314
-10
lines changed

ArchUnit.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterfaceAssembly", "TestAs
4848
EndProject
4949
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FilteredDirectoryUnavailableTypesAssembly", "TestAssemblies\FilteredDirectoryUnavailableTypesAssembly\FilteredDirectoryUnavailableTypesAssembly.csproj", "{AA695589-8CCC-4474-9A7F-01A6376C375A}"
5050
EndProject
51+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.MSTestV3Tests", "ArchUnitNET.MSTestV3Tests\ArchUnitNET.MSTestV3Tests.csproj", "{F9856A37-C0E0-453C-888F-D794856D3404}"
52+
EndProject
53+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.MSTestV4Tests", "ArchUnitNET.MSTestV4Tests\ArchUnitNET.MSTestV4Tests.csproj", "{9858F5A1-356B-4CF0-8E50-62F2E881CC36}"
54+
EndProject
55+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.MSTestV4", "ArchUnitNET.MSTestV4\ArchUnitNET.MSTestV4.csproj", "{50F0F64A-F4A2-47E5-82E9-B66F07CE4198}"
56+
EndProject
5157
Global
5258
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5359
Debug|Any CPU = Debug|Any CPU
@@ -142,6 +148,18 @@ Global
142148
{AA695589-8CCC-4474-9A7F-01A6376C375A}.Debug|Any CPU.Build.0 = Debug|Any CPU
143149
{AA695589-8CCC-4474-9A7F-01A6376C375A}.Release|Any CPU.ActiveCfg = Release|Any CPU
144150
{AA695589-8CCC-4474-9A7F-01A6376C375A}.Release|Any CPU.Build.0 = Release|Any CPU
151+
{F9856A37-C0E0-453C-888F-D794856D3404}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
152+
{F9856A37-C0E0-453C-888F-D794856D3404}.Debug|Any CPU.Build.0 = Debug|Any CPU
153+
{F9856A37-C0E0-453C-888F-D794856D3404}.Release|Any CPU.ActiveCfg = Release|Any CPU
154+
{F9856A37-C0E0-453C-888F-D794856D3404}.Release|Any CPU.Build.0 = Release|Any CPU
155+
{9858F5A1-356B-4CF0-8E50-62F2E881CC36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
156+
{9858F5A1-356B-4CF0-8E50-62F2E881CC36}.Debug|Any CPU.Build.0 = Debug|Any CPU
157+
{9858F5A1-356B-4CF0-8E50-62F2E881CC36}.Release|Any CPU.ActiveCfg = Release|Any CPU
158+
{9858F5A1-356B-4CF0-8E50-62F2E881CC36}.Release|Any CPU.Build.0 = Release|Any CPU
159+
{50F0F64A-F4A2-47E5-82E9-B66F07CE4198}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
160+
{50F0F64A-F4A2-47E5-82E9-B66F07CE4198}.Debug|Any CPU.Build.0 = Debug|Any CPU
161+
{50F0F64A-F4A2-47E5-82E9-B66F07CE4198}.Release|Any CPU.ActiveCfg = Release|Any CPU
162+
{50F0F64A-F4A2-47E5-82E9-B66F07CE4198}.Release|Any CPU.Build.0 = Release|Any CPU
145163
EndGlobalSection
146164
GlobalSection(SolutionProperties) = preSolution
147165
HideSolutionNode = FALSE

ArchUnitNET.MSTestV2/ArchUnitNET.MSTestV2.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
44
<IsPackable>true</IsPackable>
55
<Title>ArchUnit C# MSTestV2 Extension</Title>
6-
<Description>MSTestV2 Extension for the C# Version of ArchUnit (see: archunit.org)</Description>
6+
<Description>MSTestV2 Extension (compatible with MSTestV3) for the C# Version of ArchUnit (see: archunit.org)</Description>
77
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
88
<RepositoryUrl>https://github.com/TNG/ArchUnitNET</RepositoryUrl>
99
<PackageTags>test;arch;archunit;mstest;mstestv2</PackageTags>
@@ -17,7 +17,6 @@
1717
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1818
</PropertyGroup>
1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
2120
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
2221
</ItemGroup>
2322
<ItemGroup>

ArchUnitNET.MSTestV2Tests/ArchUnitNET.MSTestV2Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88
<ItemGroup>
99
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
10-
<PackageReference Include="MSTest.TestAdapter" Version="3.10.4" />
11-
<PackageReference Include="MSTest.TestFramework" Version="3.10.4" />
10+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
11+
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
1212
</ItemGroup>
1313
<ItemGroup>
1414
<ProjectReference Include="..\ArchUnitNET.MSTestV2\ArchUnitNET.MSTestV2.csproj" />

ArchUnitNET.MSTestV2Tests/RuleEvaluationTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public static void Setup(TestContext context)
3131
public void ArchRuleAssertTest()
3232
{
3333
ArchRuleAssert.FulfilsRule(_architecture, _trueRule);
34-
Assert.ThrowsExactly<AssertFailedException>(() =>
34+
Assert.ThrowsException<AssertFailedException>(() =>
3535
ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
3636
);
3737
Assert.AreEqual(
3838
_expectedErrorMessage,
3939
RemoveAssertionText(
4040
Assert
41-
.ThrowsExactly<AssertFailedException>(() =>
41+
.ThrowsException<AssertFailedException>(() =>
4242
ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
4343
)
4444
.Message
@@ -51,13 +51,13 @@ public void ArchRuleExtensionsTest()
5151
{
5252
_architecture.CheckRule(_trueRule);
5353
_trueRule.Check(_architecture);
54-
Assert.ThrowsExactly<AssertFailedException>(() => _architecture.CheckRule(_falseRule));
55-
Assert.ThrowsExactly<AssertFailedException>(() => _falseRule.Check(_architecture));
54+
Assert.ThrowsException<AssertFailedException>(() => _architecture.CheckRule(_falseRule));
55+
Assert.ThrowsException<AssertFailedException>(() => _falseRule.Check(_architecture));
5656
Assert.AreEqual(
5757
_expectedErrorMessage,
5858
RemoveAssertionText(
5959
Assert
60-
.ThrowsExactly<AssertFailedException>(() =>
60+
.ThrowsException<AssertFailedException>(() =>
6161
_architecture.CheckRule(_falseRule)
6262
)
6363
.Message
@@ -67,7 +67,7 @@ public void ArchRuleExtensionsTest()
6767
_expectedErrorMessage,
6868
RemoveAssertionText(
6969
Assert
70-
.ThrowsExactly<AssertFailedException>(() => _falseRule.Check(_architecture))
70+
.ThrowsException<AssertFailedException>(() => _falseRule.Check(_architecture))
7171
.Message
7272
)
7373
);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
<Company>TNG Technology Consulting GmbH</Company>
7+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="MSTest" Version="3.10.4" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\ArchUnitNET.MSTestV2\ArchUnitNET.MSTestV2.csproj" />
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using ArchUnitNET.Domain;
2+
using ArchUnitNET.Fluent;
3+
using ArchUnitNET.Fluent.Extensions;
4+
using ArchUnitNET.Loader;
5+
using ArchUnitNET.MSTestV2;
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
using static ArchUnitNET.Fluent.ArchRuleDefinition;
8+
9+
namespace ArchUnitNET.MSTestV3Tests
10+
{
11+
[TestClass]
12+
public class RuleEvaluationTests
13+
{
14+
private static Architecture _architecture;
15+
private static string _expectedErrorMessage;
16+
private static IArchRule _falseRule;
17+
private static IArchRule _trueRule;
18+
19+
[ClassInitialize]
20+
public static void Setup(TestContext context)
21+
{
22+
_architecture = new ArchLoader()
23+
.LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.MSTestV3Tests"))
24+
.Build();
25+
_trueRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().Exist();
26+
_falseRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().NotExist();
27+
_expectedErrorMessage = _falseRule.Evaluate(_architecture).ToErrorMessage();
28+
}
29+
30+
[TestMethod]
31+
public void ArchRuleAssertTest()
32+
{
33+
ArchRuleAssert.FulfilsRule(_architecture, _trueRule);
34+
Assert.ThrowsExactly<AssertFailedException>(() =>
35+
ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
36+
);
37+
Assert.AreEqual(
38+
_expectedErrorMessage,
39+
RemoveAssertionText(
40+
Assert
41+
.ThrowsExactly<AssertFailedException>(() =>
42+
ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
43+
)
44+
.Message
45+
)
46+
);
47+
}
48+
49+
[TestMethod]
50+
public void ArchRuleExtensionsTest()
51+
{
52+
_architecture.CheckRule(_trueRule);
53+
_trueRule.Check(_architecture);
54+
Assert.ThrowsExactly<AssertFailedException>(() => _architecture.CheckRule(_falseRule));
55+
Assert.ThrowsExactly<AssertFailedException>(() => _falseRule.Check(_architecture));
56+
Assert.AreEqual(
57+
_expectedErrorMessage,
58+
RemoveAssertionText(
59+
Assert
60+
.ThrowsExactly<AssertFailedException>(() =>
61+
_architecture.CheckRule(_falseRule)
62+
)
63+
.Message
64+
)
65+
);
66+
Assert.AreEqual(
67+
_expectedErrorMessage,
68+
RemoveAssertionText(
69+
Assert
70+
.ThrowsExactly<AssertFailedException>(() => _falseRule.Check(_architecture))
71+
.Message
72+
)
73+
);
74+
}
75+
76+
private static string RemoveAssertionText(string exceptionMessage)
77+
{
78+
return exceptionMessage.Replace("Assert.Fail failed. ", string.Empty);
79+
}
80+
}
81+
}
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+
using ArchUnitNET.Fluent.Extensions;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
6+
namespace ArchUnitNET.MSTestV4
7+
{
8+
public static class ArchRuleAssert
9+
{
10+
/// <summary>
11+
/// Verifies that the architecture meets the criteria of the archrule.
12+
/// </summary>
13+
/// <param name="architecture">The architecture to be tested</param>
14+
/// <param name="archRule">The rule to test the architecture with</param>
15+
public static void FulfilsRule(Architecture architecture, IArchRule archRule)
16+
{
17+
if (!archRule.HasNoViolations(architecture))
18+
{
19+
Assert.Fail(archRule.Evaluate(architecture).ToErrorMessage());
20+
}
21+
}
22+
}
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using ArchUnitNET.Domain;
2+
using ArchUnitNET.Fluent;
3+
4+
namespace ArchUnitNET.MSTestV4
5+
{
6+
public static class ArchRuleExtensions
7+
{
8+
/// <summary>
9+
/// Verifies that the architecture meets the criteria of the archrule.
10+
/// </summary>
11+
/// <param name="archRule">The rule to test the architecture with</param>
12+
/// <param name="architecture">The architecture to be tested</param>
13+
public static void Check(this IArchRule archRule, Architecture architecture)
14+
{
15+
ArchRuleAssert.FulfilsRule(architecture, archRule);
16+
}
17+
18+
/// <summary>
19+
/// Verifies that the architecture meets the criteria of the archrule.
20+
/// </summary>
21+
/// <param name="architecture">The architecture to be tested</param>
22+
/// <param name="archRule">The rule to test the architecture with</param>
23+
public static void CheckRule(this Architecture architecture, IArchRule archRule)
24+
{
25+
ArchRuleAssert.FulfilsRule(architecture, archRule);
26+
}
27+
}
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
4+
<IsPackable>true</IsPackable>
5+
<Title>ArchUnit C# MSTestV4 Extension</Title>
6+
<Description>MSTestV4 Extension for the C# Version of ArchUnit (see: archunit.org)</Description>
7+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
8+
<RepositoryUrl>https://github.com/TNG/ArchUnitNET</RepositoryUrl>
9+
<PackageTags>test;arch;archunit;mstest;mstestv2</PackageTags>
10+
<IncludeSource>False</IncludeSource>
11+
<Company>TNG Technology Consulting GmbH</Company>
12+
<PackageId>TngTech.ArchUnitNET.MSTestV4</PackageId>
13+
<IsTestProject>false</IsTestProject>
14+
<IncludeSymbols>true</IncludeSymbols>
15+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
16+
<PackageReadmeFile>README.md</PackageReadmeFile>
17+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
18+
</PropertyGroup>
19+
<ItemGroup>
20+
<PackageReference Include="MSTest.TestFramework" Version="4.0.0" />
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ProjectReference Include="..\ArchUnitNET\ArchUnitNET.csproj" />
24+
</ItemGroup>
25+
<ItemGroup>
26+
<None Include="../README.md" Pack="true" PackagePath="" />
27+
<None Include="../Logo/ArchUnitNET-Logo.png" Pack="true" PackagePath="/Logo/" />
28+
</ItemGroup>
29+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
<Company>TNG Technology Consulting GmbH</Company>
7+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="MSTest" Version="4.0.0" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\ArchUnitNET.MSTestV4\ArchUnitNET.MSTestV4.csproj" />
20+
</ItemGroup>
21+
22+
</Project>

0 commit comments

Comments
 (0)