-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add ArchUnit test to assert the existance of empty default cons…
…tructors
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using ArchUnitNET.Domain.Extensions; | ||
using ArchUnitNET.Fluent.Conditions; | ||
using ArchUnitNET.xUnit; | ||
using Backbone.BuildingBlocks.Domain; | ||
using static ArchUnitNET.Fluent.ArchRuleDefinition; | ||
|
||
namespace Backbone.Backbone.Tests.ArchUnit; | ||
|
||
public class DomainDrivenDesign | ||
{ | ||
[Fact] | ||
public void EntitiesShouldHaveEmptyDefaultConstructors() | ||
{ | ||
Types() | ||
.That().AreAssignableTo(typeof(Entity)) | ||
.Should().FollowCustomCondition((type) => | ||
{ | ||
var constructors = type.GetConstructors(); | ||
|
||
if (constructors.All(c => c.Parameters.Count() != 0)) | ||
return new ConditionResult(type, false, "Entity should have a parameterless constructor"); | ||
|
||
return new ConditionResult(type, true); | ||
}, "") | ||
.Because("otherwise the real constructor would be called by EF Core, which would add a domain event to the collection") | ||
.Check(Backbone.ARCHITECTURE); | ||
} | ||
} |