-
-
Save dcomartin/6e4cb5877aac1acac419e44d06630743 to your computer and use it in GitHub Desktop.
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
public class UserRegistration | |
{ | |
private static int _testCount = 0; | |
private readonly UsernameReservationSync _reservation; | |
private readonly IUserRepository _repository; | |
public UserRegistration(UsernameReservationSync reservation, IUserRepository repository) | |
{ | |
_reservation = reservation; | |
_repository = repository; | |
} | |
public bool Register(string username) | |
{ | |
if (_reservation.Reserve(username) == false) | |
{ | |
return false; | |
} | |
// For testing to show the expiry | |
if (username == "test" && _testCount == 0) | |
{ | |
_testCount++; | |
return false; | |
} | |
var account = new Account(username); | |
_repository.Add(account); | |
_repository.Save(); | |
if (_reservation.Complete(username) == false) | |
{ | |
_repository.Remove(account); | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment