-
Notifications
You must be signed in to change notification settings - Fork 62
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 #1 from brandhuf/121_FixDuplicationsInPumlErrormes…
…sages improvements to 121 fix duplications in puml errormessages
- Loading branch information
Showing
16 changed files
with
255 additions
and
196 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
94 changes: 94 additions & 0 deletions
94
ArchUnitNETTests/Domain/PlantUml/PlantUmlErrorMessagesCheck.cs
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,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; | ||
} | ||
} | ||
} |
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
20 changes: 0 additions & 20 deletions
20
ArchUnitNet.MSTest.CheckErrormessages/ArchUnitNet.MSTest.CheckErrormessages.csproj
This file was deleted.
Oops, something went wrong.
151 changes: 0 additions & 151 deletions
151
ArchUnitNet.MSTest.CheckErrormessages/PlantUMLErrormessagesCheck.cs
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
using TestAssembly.PlantUml.Catalog; | ||
|
||
namespace TestAssembly.PlantUml.Addresses | ||
{ | ||
public class Address | ||
{ | ||
#pragma warning disable CS0169 | ||
private ProductCatalog productCatalog; | ||
#pragma warning restore CS0169 | ||
} | ||
} |
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,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); | ||
} | ||
} | ||
} |
Oops, something went wrong.