Skip to content

Commit

Permalink
Merge pull request #1 from brandhuf/121_FixDuplicationsInPumlErrormes…
Browse files Browse the repository at this point in the history
…sages

improvements to 121 fix duplications in puml errormessages
  • Loading branch information
ZDI-StephanJoneleit authored Oct 5, 2021
2 parents 6594878 + fea565c commit 895269c
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 196 deletions.
15 changes: 3 additions & 12 deletions ArchUnit.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 15
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAssembly", "TestAssembly\TestAssembly.csproj", "{7DEF5F34-AB86-457B-819D-5E7387B3FF87}"
Expand All @@ -17,11 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArchUnitNET.NUnit", "ArchUn
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArchUnitNET.NUnitTests", "ArchUnitNET.NUnitTests\ArchUnitNET.NUnitTests.csproj", "{D2AB683F-0A64-491E-9C56-EE98588C493C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArchUnitNET.MSTestV2", "ArchUnitNET.MSTestV2\ArchUnitNET.MSTestV2.csproj", "{3D057987-358A-41C6-AF55-6490FCA5875F}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.MSTestV2", "ArchUnitNET.MSTestV2\ArchUnitNET.MSTestV2.csproj", "{3D057987-358A-41C6-AF55-6490FCA5875F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArchUnitNET.MSTestV2Tests", "ArchUnitNET.MSTestV2Tests\ArchUnitNET.MSTestV2Tests.csproj", "{6D6B6EFE-DA0B-4C4D-B710-FA658F0C68CF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNet.MSTest.CheckErrormessages", "ArchUnitNet.MSTest.CheckErrormessages\ArchUnitNet.MSTest.CheckErrormessages.csproj", "{1AB84ED6-92CD-4B03-ACB1-BD04E6CABAED}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.MSTestV2Tests", "ArchUnitNET.MSTestV2Tests\ArchUnitNET.MSTestV2Tests.csproj", "{6D6B6EFE-DA0B-4C4D-B710-FA658F0C68CF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -65,15 +63,8 @@ Global
{6D6B6EFE-DA0B-4C4D-B710-FA658F0C68CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D6B6EFE-DA0B-4C4D-B710-FA658F0C68CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D6B6EFE-DA0B-4C4D-B710-FA658F0C68CF}.Release|Any CPU.Build.0 = Release|Any CPU
{1AB84ED6-92CD-4B03-ACB1-BD04E6CABAED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1AB84ED6-92CD-4B03-ACB1-BD04E6CABAED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AB84ED6-92CD-4B03-ACB1-BD04E6CABAED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1AB84ED6-92CD-4B03-ACB1-BD04E6CABAED}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D8045DD-06E3-4ACF-BB1F-54AED4F124E0}
EndGlobalSection
EndGlobal
16 changes: 11 additions & 5 deletions ArchUnitNETTests/ArchUnitNETTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@
</PropertyGroup>

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

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

<ItemGroup>
<None Update="Domain\PlantUml\zzz_test_version_with_errors.puml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
94 changes: 94 additions & 0 deletions ArchUnitNETTests/Domain/PlantUml/PlantUmlErrorMessagesCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ArchUnitNET.Domain;
using ArchUnitNET.Fluent;
using ArchUnitNET.xUnit;
using Xunit;
using static ArchUnitNET.Fluent.ArchRuleDefinition;

namespace ArchUnitNETTests.Domain.PlantUml
{
public class PlantUmlErrorMessagesCheck
{
private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture;
private readonly string _umlFile;

public PlantUmlErrorMessagesCheck()
{
_umlFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Domain", "PlantUml",
"zzz_test_version_with_errors.puml");
}

[Fact]
public void NoDuplicatesInErrorMessageTest()
{
var testPassed = CheckByPuml(out var rawErrormessage);
Assert.False(testPassed);

//CheckForDuplicates returns false when errormessage contains duplicates or is empty
var containsNoDuplicates = ContainsNoDuplicates(rawErrormessage, out var explainErrormessage);

var errormessage = "\nOriginal (ArchUnitNet) Exception:\n" + rawErrormessage +
"\n\nAssert Error:\n" + explainErrormessage + "\n";

Assert.True(containsNoDuplicates, errormessage);
}

private bool CheckByPuml(out string errormessage)
{
errormessage = null;

try
{
IArchRule adhereToPlantUmlDiagram = Types().Should().AdhereToPlantUmlDiagram(_umlFile);
adhereToPlantUmlDiagram.Check(Architecture);
}
//xUnit
catch (FailedArchRuleException exception)
{
errormessage = exception.Message;

return false;
}

return true;
}

private static bool ContainsNoDuplicates(string uncutMessage, out string errormessage)
{
if (string.IsNullOrWhiteSpace(uncutMessage))
{
errormessage = "Error message is empty.";
return false;
}

var sources = new List<string>();

var errors = uncutMessage.Split('\n').Skip(1);

foreach (var error in errors.Where(e => !string.IsNullOrWhiteSpace(e)))
{
var splitError = error.Split(" does depend on ");
var source = splitError[0].Trim();
var targets = splitError[1].Trim().Split(" and ");
if (sources.Contains(source))
{
errormessage = $"Two errors with {source} as source found.";
return false;
}

sources.Add(source);
if (targets.Distinct().Count() < targets.Length)
{
errormessage = $"The error \"{error}\" contains duplicate targets.";
return false;
}
}

errormessage = "No duplicates found.";
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ skinparam component {
BackgroundColor #white
}

[Addresses] <<ExampleTest.PlantUml.Addresses.*>>
[Customers] <<ExampleTest.PlantUml.Customers.*>>
[Orders] <<ExampleTest.PlantUml.Orders.*>>
[Products] <<ExampleTest.PlantUml.Product.*>>
[Product Catalog] <<ExampleTest.PlantUml.Catalog.*>> as catalog
[Product Import] <<ExampleTest.PlantUml.Importer.*>> as import
[Addresses] <<TestAssembly.PlantUml.Addresses.*>>
[Customers] <<TestAssembly.PlantUml.Customers.*>>
[Orders] <<TestAssembly.PlantUml.Orders.*>>
[Products] <<TestAssembly.PlantUml.Product.*>>
[Product Catalog] <<TestAssembly.PlantUml.Catalog.*>> as catalog
[Product Import] <<TestAssembly.PlantUml.Importer.*>> as import

' Could be some random comment
[XML] <<ExampleTest.PlantUml.XML.Processor.*>> <<xampleTest.PlantUml.XML.Types.*>> as xml
[XML] <<TestAssembly.PlantUml.XML.Processor.*>> <<TestAssembly.PlantUml.XML.Types.*>> as xml

'Causes Error
[Addresses] <-[#blue]- catalog
Expand Down

This file was deleted.

151 changes: 0 additions & 151 deletions ArchUnitNet.MSTest.CheckErrormessages/PlantUMLErrormessagesCheck.cs

This file was deleted.

11 changes: 11 additions & 0 deletions TestAssembly/PlantUml/Addresses/Address.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using TestAssembly.PlantUml.Catalog;

namespace TestAssembly.PlantUml.Addresses
{
public class Address
{
#pragma warning disable CS0169
private ProductCatalog productCatalog;
#pragma warning restore CS0169
}
}
22 changes: 22 additions & 0 deletions TestAssembly/PlantUml/Catalog/ProductCatalog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using TestAssembly.PlantUml.Orders;
using TestAssembly.PlantUml.Products;

namespace TestAssembly.PlantUml.Catalog
{
public class ProductCatalog
{
private readonly List<Product> _allProducts = new List<Product>();

internal void GonnaDoSomethingIllegalWithOrder()
{
var order = new Order();
foreach (var product in _allProducts)
{
product.Register();
}

order.AddProducts(_allProducts);
}
}
}
Loading

0 comments on commit 895269c

Please sign in to comment.