public void RegisteringExistingUserPendingDeletionIsValid(bool activated)
        {
            const string username = "******";
            var          userId   = Guid.NewGuid();

            var user = new UserBuilder(username, userId).Activated(activated).WithStatus(UserStatuses.PendingDeletion).Build();

            var userReadRepository = new Mock <IUserReadRepository>();

            userReadRepository.Setup(r => r.Get(username, false)).Returns(user);
            var strategy = new RegisterUserStrategyBuilder().With(userReadRepository).Build();

            Action register = () => strategy.Register(username, userId, "ABC123", UserRoles.Candidate);

            register.ShouldNotThrow <CustomException>();
        }
        public void CannotRegisterExistingActivatedUser()
        {
            const string username = "******";
            var          userId   = Guid.NewGuid();

            var user = new UserBuilder(username, userId).Activated(true).Build();

            var userReadRepository = new Mock <IUserReadRepository>();

            userReadRepository.Setup(r => r.Get(username, false)).Returns(user);
            var strategy = new RegisterUserStrategyBuilder().With(userReadRepository).Build();

            Action register = () => strategy.Register(username, userId, "ABC123", UserRoles.Candidate);

            register.ShouldThrow <CustomException>();
        }
        public void RegisteringExistingUserPendingDeletionRecreatesUser(bool activated)
        {
            const string username       = "******";
            var          userId         = Guid.NewGuid();
            const string activationCode = "321CBA";

            var user = new UserBuilder(username, userId).Activated(activated).WithStatus(UserStatuses.PendingDeletion).Build();

            var userReadRepository = new Mock <IUserReadRepository>();

            userReadRepository.Setup(r => r.Get(username, false)).Returns(user);
            var  userWriteRepository = new Mock <IUserWriteRepository>();
            User savedUser           = null;

            userWriteRepository.Setup(r => r.Save(It.IsAny <User>())).Callback <User>(u => savedUser = u);
            var strategy = new RegisterUserStrategyBuilder().With(userReadRepository).With(userWriteRepository).Build();

            strategy.Register(username, userId, activationCode, UserRoles.Candidate);

            savedUser.Should().NotBeNull();
            savedUser.Should().NotBeSameAs(user);
            savedUser.ActivationCode.Should().NotBe(user.ActivationCode);
            savedUser.ActivationCode.Should().Be(activationCode);
        }