Created
November 15, 2011 09:02
-
-
Save ToJans/1366502 to your computer and use it in GitHub Desktop.
Uniqueness in CQRS
This file contains hidden or 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
When a user registers with a unique username | |
Then that registration should be approved | |
Given a user registration with a certain username was approved | |
When a new user registers with the same username | |
Then that registration should be rejected |
This file contains hidden or 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
When a user registers with a certain username | |
Then that registration should be pending | |
Given a user registration with a certain username was approved | |
When a new user registers with the same username | |
Then that registration should be pending |
This file contains hidden or 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
Given a user registration with a certain username is pending | |
When the information is processed | |
Then it will approve the registration with that username | |
Given a user registration with a certain username has been approved | |
Given a user registration with the same username is pending | |
When the information is processed | |
Then it will reject the registration with that username |
This file contains hidden or 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
Given [something happened] | |
When [all the sagas have processed the events] | |
Then [a command should be issued] |
This file contains hidden or 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
public class UserRegistrationSaga | |
{ | |
IIndexStore indexstore; | |
IRunCommand bus; | |
public UserRegistrationSaga(IRunCommand bus,IIndexStore indexstore ) | |
{ | |
this.indexstore= indexstore; | |
this.bus = bus; | |
} | |
public void OnUserRegistrationPending(string UserRegistrationId,string Username) | |
{ | |
if (indexstore.ContainsValue<string>("RegistrationUsername",Username)) | |
{ | |
bus.RunCommand(new RejectUserRegistration { UserRegistrationId = UserRegistrationId,Reason = "Username "+Username+" is allready in use"}); | |
} | |
else | |
{ | |
indexstore.Add<string>("RegistrationUsername",Username); | |
bus.RunCommand(new ApproveUserRegistration { UserRegistrationId = UserRegistrationId, Username=Username }); | |
} | |
} | |
public void OnUserRegistrationApproved(string UserRegistrationId,string Username) | |
{ | |
if (!indexstore.ContainsValue<string>("RegistrationUsername",Username)) | |
{ | |
indexstore.Add<string>("RegistrationUsername",Username); | |
} | |
} | |
public void OnUserRegistrationRejected(string UserRegistrationId,string Username) | |
{ | |
if (indexstore.ContainsValue<string>("RegistrationUsername",Username)) | |
{ | |
indexstore.Remove<string>("RegistrationUsername",Username); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment