Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created Mar 30, 2022
Embed
What would you like to do?
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