Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ArchUnit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterfaceAssembly", "TestAs
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FilteredDirectoryUnavailableTypesAssembly", "TestAssemblies\FilteredDirectoryUnavailableTypesAssembly\FilteredDirectoryUnavailableTypesAssembly.csproj", "{AA695589-8CCC-4474-9A7F-01A6376C375A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.MSTestV3Tests", "ArchUnitNET.MSTestV3Tests\ArchUnitNET.MSTestV3Tests.csproj", "{F9856A37-C0E0-453C-888F-D794856D3404}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.MSTestV4Tests", "ArchUnitNET.MSTestV4Tests\ArchUnitNET.MSTestV4Tests.csproj", "{9858F5A1-356B-4CF0-8E50-62F2E881CC36}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.MSTestV4", "ArchUnitNET.MSTestV4\ArchUnitNET.MSTestV4.csproj", "{50F0F64A-F4A2-47E5-82E9-B66F07CE4198}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -142,6 +148,18 @@ Global
{AA695589-8CCC-4474-9A7F-01A6376C375A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA695589-8CCC-4474-9A7F-01A6376C375A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA695589-8CCC-4474-9A7F-01A6376C375A}.Release|Any CPU.Build.0 = Release|Any CPU
{F9856A37-C0E0-453C-888F-D794856D3404}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9856A37-C0E0-453C-888F-D794856D3404}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9856A37-C0E0-453C-888F-D794856D3404}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9856A37-C0E0-453C-888F-D794856D3404}.Release|Any CPU.Build.0 = Release|Any CPU
{9858F5A1-356B-4CF0-8E50-62F2E881CC36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9858F5A1-356B-4CF0-8E50-62F2E881CC36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9858F5A1-356B-4CF0-8E50-62F2E881CC36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9858F5A1-356B-4CF0-8E50-62F2E881CC36}.Release|Any CPU.Build.0 = Release|Any CPU
{50F0F64A-F4A2-47E5-82E9-B66F07CE4198}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50F0F64A-F4A2-47E5-82E9-B66F07CE4198}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50F0F64A-F4A2-47E5-82E9-B66F07CE4198}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50F0F64A-F4A2-47E5-82E9-B66F07CE4198}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 1 addition & 2 deletions ArchUnitNET.MSTestV2/ArchUnitNET.MSTestV2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<IsPackable>true</IsPackable>
<Title>ArchUnit C# MSTestV2 Extension</Title>
<Description>MSTestV2 Extension for the C# Version of ArchUnit (see: archunit.org)</Description>
<Description>MSTestV2 Extension (compatible with MSTestV3) for the C# Version of ArchUnit (see: archunit.org)</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/TNG/ArchUnitNET</RepositoryUrl>
<PackageTags>test;arch;archunit;mstest;mstestv2</PackageTags>
Expand All @@ -17,7 +17,6 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions ArchUnitNET.MSTestV2Tests/ArchUnitNET.MSTestV2Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.10.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.10.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ArchUnitNET.MSTestV2\ArchUnitNET.MSTestV2.csproj" />
Expand Down
12 changes: 6 additions & 6 deletions ArchUnitNET.MSTestV2Tests/RuleEvaluationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public static void Setup(TestContext context)
public void ArchRuleAssertTest()
{
ArchRuleAssert.FulfilsRule(_architecture, _trueRule);
Assert.ThrowsExactly<AssertFailedException>(() =>
Assert.ThrowsException<AssertFailedException>(() =>
ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
);
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsExactly<AssertFailedException>(() =>
.ThrowsException<AssertFailedException>(() =>
ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
)
.Message
Expand All @@ -51,13 +51,13 @@ public void ArchRuleExtensionsTest()
{
_architecture.CheckRule(_trueRule);
_trueRule.Check(_architecture);
Assert.ThrowsExactly<AssertFailedException>(() => _architecture.CheckRule(_falseRule));
Assert.ThrowsExactly<AssertFailedException>(() => _falseRule.Check(_architecture));
Assert.ThrowsException<AssertFailedException>(() => _architecture.CheckRule(_falseRule));
Assert.ThrowsException<AssertFailedException>(() => _falseRule.Check(_architecture));
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsExactly<AssertFailedException>(() =>
.ThrowsException<AssertFailedException>(() =>
_architecture.CheckRule(_falseRule)
)
.Message
Expand All @@ -67,7 +67,7 @@ public void ArchRuleExtensionsTest()
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsExactly<AssertFailedException>(() => _falseRule.Check(_architecture))
.ThrowsException<AssertFailedException>(() => _falseRule.Check(_architecture))
.Message
)
);
Expand Down
22 changes: 22 additions & 0 deletions ArchUnitNET.MSTestV3Tests/ArchUnitNET.MSTestV3Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<IsPackable>false</IsPackable>
<Company>TNG Technology Consulting GmbH</Company>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest" Version="3.10.4" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ArchUnitNET.MSTestV2\ArchUnitNET.MSTestV2.csproj" />
</ItemGroup>

</Project>
81 changes: 81 additions & 0 deletions ArchUnitNET.MSTestV3Tests/RuleEvaluationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using ArchUnitNET.Domain;
using ArchUnitNET.Fluent;
using ArchUnitNET.Fluent.Extensions;
using ArchUnitNET.Loader;
using ArchUnitNET.MSTestV2;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static ArchUnitNET.Fluent.ArchRuleDefinition;

namespace ArchUnitNET.MSTestV3Tests
{
[TestClass]
public class RuleEvaluationTests
{
private static Architecture _architecture;
private static string _expectedErrorMessage;
private static IArchRule _falseRule;
private static IArchRule _trueRule;

[ClassInitialize]
public static void Setup(TestContext context)
{
_architecture = new ArchLoader()
.LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.MSTestV3Tests"))
.Build();
_trueRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().Exist();
_falseRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().NotExist();
_expectedErrorMessage = _falseRule.Evaluate(_architecture).ToErrorMessage();
}

[TestMethod]
public void ArchRuleAssertTest()
{
ArchRuleAssert.FulfilsRule(_architecture, _trueRule);
Assert.ThrowsExactly<AssertFailedException>(() =>
ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
);
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsExactly<AssertFailedException>(() =>
ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
)
.Message
)
);
}

[TestMethod]
public void ArchRuleExtensionsTest()
{
_architecture.CheckRule(_trueRule);
_trueRule.Check(_architecture);
Assert.ThrowsExactly<AssertFailedException>(() => _architecture.CheckRule(_falseRule));
Assert.ThrowsExactly<AssertFailedException>(() => _falseRule.Check(_architecture));
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsExactly<AssertFailedException>(() =>
_architecture.CheckRule(_falseRule)
)
.Message
)
);
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsExactly<AssertFailedException>(() => _falseRule.Check(_architecture))
.Message
)
);
}

private static string RemoveAssertionText(string exceptionMessage)
{
return exceptionMessage.Replace("Assert.Fail failed. ", string.Empty);
}
}
}
23 changes: 23 additions & 0 deletions ArchUnitNET.MSTestV4/ArchRuleAssert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using ArchUnitNET.Domain;
using ArchUnitNET.Fluent;
using ArchUnitNET.Fluent.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ArchUnitNET.MSTestV4
{
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>
public static void FulfilsRule(Architecture architecture, IArchRule archRule)
{
if (!archRule.HasNoViolations(architecture))
{
Assert.Fail(archRule.Evaluate(architecture).ToErrorMessage());
}
}
}
}
28 changes: 28 additions & 0 deletions ArchUnitNET.MSTestV4/ArchRuleExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using ArchUnitNET.Domain;
using ArchUnitNET.Fluent;

namespace ArchUnitNET.MSTestV4
{
public static class ArchRuleExtensions
{
/// <summary>
/// Verifies that the architecture meets the criteria of the archrule.
/// </summary>
/// <param name="archRule">The rule to test the architecture with</param>
/// <param name="architecture">The architecture to be tested</param>
public static void Check(this IArchRule archRule, Architecture architecture)
{
ArchRuleAssert.FulfilsRule(architecture, archRule);
}

/// <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>
public static void CheckRule(this Architecture architecture, IArchRule archRule)
{
ArchRuleAssert.FulfilsRule(architecture, archRule);
}
}
}
29 changes: 29 additions & 0 deletions ArchUnitNET.MSTestV4/ArchUnitNET.MSTestV4.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<IsPackable>true</IsPackable>
<Title>ArchUnit C# MSTestV4 Extension</Title>
<Description>MSTestV4 Extension for the C# Version of ArchUnit (see: archunit.org)</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/TNG/ArchUnitNET</RepositoryUrl>
<PackageTags>test;arch;archunit;mstest;mstestv2</PackageTags>
<IncludeSource>False</IncludeSource>
<Company>TNG Technology Consulting GmbH</Company>
<PackageId>TngTech.ArchUnitNET.MSTestV4</PackageId>
<IsTestProject>false</IsTestProject>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageReadmeFile>README.md</PackageReadmeFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest.TestFramework" Version="4.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ArchUnitNET\ArchUnitNET.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="../README.md" Pack="true" PackagePath="" />
<None Include="../Logo/ArchUnitNET-Logo.png" Pack="true" PackagePath="/Logo/" />
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions ArchUnitNET.MSTestV4Tests/ArchUnitNET.MSTestV4Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<IsPackable>false</IsPackable>
<Company>TNG Technology Consulting GmbH</Company>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ArchUnitNET.MSTestV4\ArchUnitNET.MSTestV4.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions ArchUnitNET.MSTestV4Tests/MSTestSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[assembly: DoNotParallelize]
81 changes: 81 additions & 0 deletions ArchUnitNET.MSTestV4Tests/RuleEvaluationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using ArchUnitNET.Domain;
using ArchUnitNET.Fluent;
using ArchUnitNET.Fluent.Extensions;
using ArchUnitNET.Loader;
using ArchUnitNET.MSTestV4;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static ArchUnitNET.Fluent.ArchRuleDefinition;

namespace ArchUnitNET.MSTestV4Tests
{
[TestClass]
public class RuleEvaluationTests
{
private static Architecture _architecture;
private static string _expectedErrorMessage;
private static IArchRule _falseRule;
private static IArchRule _trueRule;

[ClassInitialize]
public static void Setup(TestContext context)
{
_architecture = new ArchLoader()
.LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.MSTestV4Tests"))
.Build();
_trueRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().Exist();
_falseRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().NotExist();
_expectedErrorMessage = _falseRule.Evaluate(_architecture).ToErrorMessage();
}

[TestMethod]
public void ArchRuleAssertTest()
{
ArchRuleAssert.FulfilsRule(_architecture, _trueRule);
Assert.ThrowsExactly<AssertFailedException>(() =>
ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
);
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsExactly<AssertFailedException>(() =>
ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
)
.Message
)
);
}

[TestMethod]
public void ArchRuleExtensionsTest()
{
_architecture.CheckRule(_trueRule);
_trueRule.Check(_architecture);
Assert.ThrowsExactly<AssertFailedException>(() => _architecture.CheckRule(_falseRule));
Assert.ThrowsExactly<AssertFailedException>(() => _falseRule.Check(_architecture));
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsExactly<AssertFailedException>(() =>
_architecture.CheckRule(_falseRule)
)
.Message
)
);
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsExactly<AssertFailedException>(() => _falseRule.Check(_architecture))
.Message
)
);
}

private static string RemoveAssertionText(string exceptionMessage)
{
return exceptionMessage.Replace("Assert.Fail failed. ", string.Empty);
}
}
}