Skip to content

Commit

Permalink
test: add ArchUnit test to assert the existance of empty default cons…
Browse files Browse the repository at this point in the history
…tructors
  • Loading branch information
tnotheis committed Jun 18, 2024
1 parent 36f0cb7 commit eba6852
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Backbone.Tests.ArchUnit/DomainDrivenDesign.cs
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);
}
}

0 comments on commit eba6852

Please sign in to comment.