-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: update unit test for domain layer (#5)
- Loading branch information
1 parent
bd670cb
commit e9a7718
Showing
28 changed files
with
1,688 additions
and
53 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
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
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
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
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
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
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,130 @@ | ||
using BuildingBlock.Core.Domain; | ||
using FluentAssertions; | ||
|
||
namespace Tests.Core.Domain; | ||
|
||
public class EntityTest | ||
{ | ||
public class TestEntity : Entity | ||
{ | ||
public TestEntity() | ||
{ | ||
UpdatedAt = DateTime.Now; | ||
UpdatedBy = "Test"; | ||
} | ||
|
||
public List<TestEntity> TestEntities { get; set; } = []; | ||
public List<int> TestInts { get; set; } = [1, 2, 3]; | ||
public List<string> TestStrings { get; set; } = []; | ||
public TestEntity ChildEntity { get; set; } = null!; | ||
} | ||
|
||
public class ResetUpdatedTimeStamp | ||
{ | ||
public class ShouldResetUpdatedTimeStamp | ||
{ | ||
[Fact] | ||
public void WhenInvoke() | ||
{ | ||
// Arrange | ||
var entity = new TestEntity(); | ||
|
||
// Act | ||
entity.ResetUpdatedTimeStamp(); | ||
|
||
// Assert | ||
entity.UpdatedAt.Should().BeNull(); | ||
entity.UpdatedBy.Should().BeNull(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class AggregateRootTest | ||
{ | ||
public class AddDomainEvent | ||
{ | ||
public class ShouldAddDomainEvent | ||
{ | ||
[Fact] | ||
public void WhenInvoke() | ||
{ | ||
// Arrange | ||
var aggregateRoot = new TestAggregateRoot(); | ||
var domainEvent = new TestDomainEvent(); | ||
|
||
// Act | ||
aggregateRoot.AddDomainEvent(domainEvent); | ||
|
||
// Assert | ||
aggregateRoot.DomainEvents.Should().Contain(domainEvent); | ||
aggregateRoot.DomainEvents.Should().HaveCount(1); | ||
} | ||
} | ||
} | ||
|
||
public class RemoveDomainEvent | ||
{ | ||
public class ShouldRemoveDomainEvent | ||
{ | ||
[Fact] | ||
public void WhenThatDomainEventIsExist() | ||
{ | ||
// Arrange | ||
var aggregateRoot = new TestAggregateRoot(); | ||
var domainEvent = new TestDomainEvent(); | ||
aggregateRoot.AddDomainEvent(domainEvent); | ||
|
||
// Act | ||
aggregateRoot.RemoveDomainEvent(domainEvent); | ||
|
||
// Assert | ||
aggregateRoot.DomainEvents.Should().NotContain(domainEvent); | ||
aggregateRoot.DomainEvents.Should().HaveCount(0); | ||
} | ||
} | ||
|
||
public class ShouldDoNothing | ||
{ | ||
[Fact] | ||
public void WhenThatDomainEventIsNotExist() | ||
{ | ||
// Arrange | ||
var aggregateRoot = new TestAggregateRoot(); | ||
var domainEvent = new TestDomainEvent(); | ||
|
||
// Act | ||
aggregateRoot.RemoveDomainEvent(domainEvent); | ||
|
||
// Assert | ||
aggregateRoot.DomainEvents.Should().NotContain(domainEvent); | ||
aggregateRoot.DomainEvents.Should().HaveCount(0); | ||
} | ||
} | ||
} | ||
|
||
public class ClearDomainEvent | ||
{ | ||
public class ShouldRemoveAllDomainEvents | ||
{ | ||
[Fact] | ||
public void WhenInvoke() | ||
{ | ||
// Arrange | ||
var aggregateRoot = new TestAggregateRoot(); | ||
var domainEvent = new TestDomainEvent(); | ||
aggregateRoot.AddDomainEvent(domainEvent); | ||
aggregateRoot.AddDomainEvent(domainEvent); | ||
aggregateRoot.AddDomainEvent(domainEvent); | ||
aggregateRoot.AddDomainEvent(domainEvent); | ||
|
||
// Act | ||
aggregateRoot.ClearDomainEvents(); | ||
|
||
// Assert | ||
aggregateRoot.DomainEvents.Should().NotContain(domainEvent); | ||
aggregateRoot.DomainEvents.Should().HaveCount(0); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.