-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from SeMuell/feature/add_mstestv2_capabilities
Add extensions for MSTest V2 framework.
- Loading branch information
Showing
8 changed files
with
194 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2019 Florian Gather <[email protected]> | ||
// Copyright 2019 Paula Ruiz <[email protected]> | ||
// Copyright 2019 Fritz Brandhuber <[email protected]> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using ArchUnitNET.Domain; | ||
using ArchUnitNET.Fluent; | ||
using ArchUnitNET.Fluent.Extensions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace ArchUnitNET.MSTestV2 | ||
{ | ||
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()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2019 Florian Gather <[email protected]> | ||
// Copyright 2019 Paula Ruiz <[email protected]> | ||
// Copyright 2019 Fritz Brandhuber <[email protected]> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using ArchUnitNET.Domain; | ||
using ArchUnitNET.Fluent; | ||
|
||
namespace ArchUnitNET.MSTestV2 | ||
{ | ||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> | ||
<IsPackable>true</IsPackable> | ||
<Title>ArchUnit C# MSTestV2 Extension</Title> | ||
<Authors>Florian Gather, Fritz Brandhuber</Authors> | ||
<Description>MSTestV2 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> | ||
<PackageReleaseNotes>Initial release</PackageReleaseNotes> | ||
<IncludeSource>False</IncludeSource> | ||
<Company>TNG Technology Consulting GmbH</Company> | ||
<PackageId>TngTech.ArchUnitNET.MSTestV2</PackageId> | ||
<IsTestProject>false</IsTestProject> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ArchUnitNET\ArchUnitNET.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
21 changes: 21 additions & 0 deletions
21
ArchUnitNET.MSTestV2Tests/ArchUnitNET.MSTestV2Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
|
||
<Company>TNG Technology Consulting GmbH</Company> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ArchUnitNET.MSTestV2\ArchUnitNET.MSTestV2.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2019 Florian Gather <[email protected]> | ||
// Copyright 2019 Paula Ruiz <[email protected]> | ||
// Copyright 2019 Fritz Brandhuber <[email protected]> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
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.MSTestV2Tests | ||
{ | ||
[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(typeof(RuleEvaluationTests).Assembly).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.ThrowsException<AssertFailedException>(() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)); | ||
Assert.AreEqual(_expectedErrorMessage, | ||
RemoveAssertionText(Assert.ThrowsException<AssertFailedException>(() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)).Message)); | ||
} | ||
|
||
[TestMethod] | ||
public void ArchRuleExtensionsTest() | ||
{ | ||
_architecture.CheckRule(_trueRule); | ||
_trueRule.Check(_architecture); | ||
Assert.ThrowsException<AssertFailedException>(() => _architecture.CheckRule(_falseRule)); | ||
Assert.ThrowsException<AssertFailedException>(() => _falseRule.Check(_architecture)); | ||
Assert.AreEqual(_expectedErrorMessage, | ||
RemoveAssertionText(Assert.ThrowsException<AssertFailedException>(() => _architecture.CheckRule(_falseRule)).Message)); | ||
Assert.AreEqual(_expectedErrorMessage, | ||
RemoveAssertionText(Assert.ThrowsException<AssertFailedException>(() => _falseRule.Check(_architecture)).Message)); | ||
} | ||
|
||
private static string RemoveAssertionText(string exceptionMessage) { | ||
return exceptionMessage.Replace("Assert.Fail failed. ", string.Empty); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters