public void ShouldReplaceEmailVariables() { var email = EmailFaker.GenerateEmail().Generate(); var message = email.GetMessage(UserFaker.GenerateUser().Generate(), new AccountResult(_faker.Random.Guid().ToString(), _faker.Database.Random.AlphaNumeric(5), _faker.Internet.Url()), UserCommandFaker.GenerateRegisterNewUserCommand().Generate()); message.Content.Should() .NotContain("{{picture}}").And .NotContain("{{name}}").And .NotContain("{{username}}").And .NotContain("{{code}}").And .NotContain("{{url}}").And .NotContain("{{provider}}").And .NotContain("{{phoneNumber}}").And .NotContain("{{email}}"); }
public async Task ShouldRemoveClaimWithValue() { var user = UserFaker.GenerateUser().Generate(); var command = UserManagerCommandFaker.GenerateRemoveClaimCommand().Generate(); _userService.Setup(s => s.FindByNameAsync(It.Is <string>(e => e == command.Username))).ReturnsAsync(user); _userService.Setup(s => s.RemoveClaim( It.Is <string>(c => c == user.Id), It.Is <string>(c => c.Equals(command.Type)), It.Is <string>(c => c.Equals(command.Value)))) .ReturnsAsync(true); _uow.Setup(s => s.Commit()).ReturnsAsync(true); var result = await _commandHandler.Handle(command, _tokenSource.Token); _userService.Verify(s => s.FindByNameAsync(It.Is <string>(e => e == command.Username)), Times.Once); result.Should().BeTrue(); }
public async Task Should_Add_New_User_If_It_Dont_Have_Email() { var command = UserCommandFaker.GenerateRegisterNewUserWithoutPassCommand(checkProvider: false, setEmail: false, setName: false).Generate(); _userService.SetupSequence(s => s.FindByNameAsync(It.Is <string>(e => e == command.Username))) .ReturnsAsync((IDomainUser)null) .ReturnsAsync(UserFaker.GenerateUser().Generate()); _userService.Setup(s => s.CreateUserWithouthPassword( It.Is <RegisterNewUserWithoutPassCommand>(i => i.Username.Equals(command.Username) && i.Email == null)) ) .ReturnsAsync( new AccountResult(command.Username, _faker.Random.AlphaNumeric(8), _faker.Internet.Url()) ); var result = await _commandHandler.Handle(command, _tokenSource.Token); _userService.Verify(s => s.FindByEmailAsync(It.Is <string>(e => e == command.Email)), Times.Once); _userService.Verify(s => s.FindByNameAsync(It.Is <string>(e => e == command.Username)), Times.Exactly(2)); result.Should().BeTrue(); }
public async Task ShouldNotAddNewUserIfItNameAlreadyExist() { var command = UserCommandFaker.GenerateRegisterNewUserCommand().Generate(); _userService.Setup(s => s.FindByEmailAsync(It.Is <string>(e => e == command.Email))).ReturnsAsync((User)null); _userService.Setup(s => s.FindByNameAsync(It.Is <string>(n => n == command.Username))).ReturnsAsync(UserFaker.GenerateUser().Generate()); var result = await _commandHandler.Handle(command, _tokenSource.Token); _userService.Verify(s => s.FindByEmailAsync(It.Is <string>(e => e == command.Email)), Times.Once); _userService.Verify(s => s.FindByNameAsync(It.Is <string>(n => n == command.Username)), Times.Once); result.Should().BeFalse(); }
public async Task ShouldNotAddNewUser_AfterSuccessfulLoginThrough_ExternalProvider_IfHisEmailAlreadyExist() { var command = UserCommandFaker.GenerateRegisterNewUserWithoutPassCommand().Generate(); _userService.Setup(s => s.FindByEmailAsync(It.Is <string>(e => e == command.Email))).ReturnsAsync(UserFaker.GenerateUser().Generate()); var result = await _commandHandler.Handle(command, _tokenSource.Token); _userService.Verify(s => s.FindByEmailAsync(It.Is <string>(e => e == command.Email)), Times.Once); result.Should().BeFalse(); }
public async Task Should_Not_Add_New_User_If_It_Email_Already_Exist() { var command = UserCommandFaker.GenerateRegisterNewUserCommand().Generate(); _userService.Setup(s => s.FindByEmailAsync(It.Is <string>(e => e == command.Email))).ReturnsAsync(UserFaker.GenerateUser().Generate()); var result = await _commandHandler.Handle(command, _tokenSource.Token); _userService.Verify(s => s.FindByEmailAsync(It.Is <string>(e => e == command.Email)), Times.Once); result.Should().BeFalse(); }
public async Task Should_Send_Email_After_Successfull_Registration() { _emailRepository.Setup(s => s.GetByType(It.IsAny <EmailType>())).ReturnsAsync(EmailFaker.GenerateEmail()); _userService.Setup(s => s.CreateUserWithPass(It.IsAny <RegisterNewUserCommand>(), It.IsAny <string>())).ReturnsAsync(new AccountResult(_faker.Random.Guid().ToString(), _faker.Random.String(), _faker.Internet.Url())); _userService.SetupSequence(s => s.FindByNameAsync(It.IsAny <string>())).ReturnsAsync((IDomainUser)null).ReturnsAsync(UserFaker.GenerateUser(confirmedEmail: false).Generate()); var command = UserCommandFaker.GenerateRegisterNewUserCommand(shouldConfirmEmail: true).Generate(); var result = await _commandHandler.Handle(command, _tokenSource.Token); result.Should().BeTrue(); _userService.Verify(s => s.CreateUserWithPass(It.IsAny <RegisterNewUserCommand>(), It.IsAny <string>()), Times.Once); _emailService.Verify(e => e.SendEmailAsync(It.IsAny <EmailMessage>()), Times.Once); }