I am using the NetArchTest.Rules package by Ben Morris to enforce layered architecture. In my code I am checking that the assets project does not reference any other (have a dependency) on any other projects in the access layer, however the result always returns false, regardless of whether the code says Should or ShouldNot. I am sure that the Assets projects does not have any project dependencies on those that are being checked in the test AssetsShouldNotReferenceOtherAccess.
Access Layer Assets Dependencies
private const string AssetsNamespace = "Flux.Access.Assets";
private const string BlobNamespace = "Flux.Access.Blob";
private const string ConfigurationsNamespace = "Flux.Access.Configurations";
private const string MembersNamespace = "Flux.Access.Members";
private const string CommonNamespace = "Flux.Access.Common";
[Test]
public void AssetsShouldNotReferenceOtherAccess()
{
var otherProjects = new[]
{
BlobNamespace, ConfigurationsNamespace, MembersNamespace
};
var result = Types
.InCurrentDomain()
.That()
.ResideInNamespace(AssetsNamespace)
.ShouldNot()
.HaveDependencyOnAny(otherProjects)
.GetResult()
.IsSuccessful;
Assert.True(result);
}
[Test]
public void AssetsShouldReferenceCommon()
{
var result = Types
.InCurrentDomain()
.That()
.ResideInNamespace(AssetsNamespace)
.Should()
.HaveDependencyOn(CommonNamespace)
.GetResult()
.IsSuccessful;
Assert.True(result);
}
I expected the result in AssetsShouldNotReferenceOtherAccess to change if I changed the code to read Should instead of ShouldNot, however in both scenarios the code return False. In the documentation I've read on the package online this seems like the correct way to test the code but I can't get it to work. Any insight will help :)
You first test is correct, but you should write it this way:
[Test]
public void AssetsShouldNotReferenceOtherAccess()
{
var otherProjects = new[]
{
BlobNamespace, ConfigurationsNamespace, MembersNamespace
};
var result = Types
.InCurrentDomain()
.That()
.ResideInNamespace(AssetsNamespace)
.ShouldNot()
.HaveDependencyOnAny(otherProjects)
.GetResult();
Assert.True(result.IsSuccessful);
}
Now you can put a breakpoint on Assert, and check property result.FailingTypes
to see what types do not pass test. You should inspect the code of failing types, and if indeed they do not have any dependency on AssetsNamespace, then this is a bug in library that should be reported on github.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With