Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created March 30, 2022 21:24
Show Gist options
  • Save dcomartin/6e4cb5877aac1acac419e44d06630743 to your computer and use it in GitHub Desktop.
Save dcomartin/6e4cb5877aac1acac419e44d06630743 to your computer and use it in GitHub Desktop.
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