File tree Expand file tree Collapse file tree
src/Clean.Architecture.Core/ContributorAggregate
tests/Clean.Architecture.UnitTests/Core/ContributorAggregate Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ public Contributor UpdatePhoneNumber(PhoneNumber newPhoneNumber)
1616
1717 public Contributor UpdateName ( ContributorName newName )
1818 {
19+ if ( Name == newName ) return this ;
1920 Name = newName ;
2021 RegisterDomainEvent ( new ContributorNameUpdatedEvent ( this ) ) ;
2122 return this ;
Original file line number Diff line number Diff line change 1+ using Clean . Architecture . Core . ContributorAggregate . Events ;
2+
3+ namespace Clean . Architecture . UnitTests . Core . ContributorAggregate ;
4+
5+ public class ContributorUpdateName
6+ {
7+ private readonly ContributorName _initialName = ContributorName . From ( "initial name" ) ;
8+ private readonly ContributorName _newName = ContributorName . From ( "new name" ) ;
9+ private Contributor ? _testContributor ;
10+ private Contributor CreateContributor ( )
11+ {
12+ return new Contributor ( _initialName ) ;
13+ }
14+
15+ [ Fact ]
16+ public void UpdatesName ( )
17+ {
18+ _testContributor = CreateContributor ( ) ;
19+ _testContributor . UpdateName ( _newName ) ;
20+ _testContributor . Name . ShouldBe ( _newName ) ;
21+ }
22+
23+ [ Fact ]
24+ public void RegistersDomainEvent ( )
25+ {
26+ _testContributor = CreateContributor ( ) ;
27+ _testContributor . UpdateName ( _newName ) ;
28+ _testContributor . DomainEvents . Count . ShouldBe ( 1 ) ;
29+ _testContributor . DomainEvents . First ( ) . ShouldBeOfType < ContributorNameUpdatedEvent > ( ) ;
30+ }
31+
32+ [ Fact ]
33+ public void DoesNotRegisterDomainEventGivenCurrentName ( )
34+ {
35+ _testContributor = CreateContributor ( ) ;
36+ _testContributor . UpdateName ( _initialName ) ;
37+ _testContributor . DomainEvents . Count . ShouldBe ( 0 ) ;
38+ }
39+
40+ }
You can’t perform that action at this time.
0 commit comments