Пример #1
0
        public async Task ShouldNotRegisterUserWithAFutureBirthdate()
        {
            var command = UserCommandFaker.GenerateRegisterNewUserCommand(birthdate: _faker.Date.Future()).Generate();

            var result = await _commandHandler.Handle(command, CancellationToken.None);

            result.Should().BeFalse();
        }
        public async Task ShouldNotAddNewUserIfPasswordDifferFromConfirmation()
        {
            var command = UserCommandFaker.GenerateRegisterNewUserCommand(_faker.Internet.Password()).Generate();

            var result = await _commandHandler.Handle(command, _tokenSource.Token);


            result.Should().BeFalse();
        }
        public async Task ShouldNotAddNewUserIfItEmailAlreadyExist()
        {
            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();
        }
Пример #4
0
        public async Task ShouldSendEmailAfterSuccessfullRegistration()
        {
            _emailRepository.Setup(s => s.GetByType(It.IsAny <EmailType>())).ReturnsAsync(EmailFaker.GenerateEmail());
            _userService.Setup(s => s.CreateUserWithPass(It.IsAny <User>(), It.IsAny <string>())).ReturnsAsync(new AccountResult(_faker.Random.Guid().ToString(), _faker.Random.String(), _faker.Internet.Url()));

            var command = UserCommandFaker.GenerateRegisterNewUserCommand().Generate();

            var result = await _commandHandler.Handle(command, _tokenSource.Token);

            result.Should().BeTrue();
            _emailService.Verify(e => e.SendEmailAsync(It.IsAny <EmailMessage>()), Times.Once);
        }
        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);
        }
        public async Task Should_Not_Add_New_User_If_It_Name_Already_Exist()
        {
            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 void Should_Replace_Email_Variables()
        {
            var email   = EmailFaker.GenerateEmail().Generate();
            var claims  = ClaimFaker.GenerateClaim().Generate(10);
            var message = email.GetMessage(UserFaker.GenerateUser().Generate(), new AccountResult(_faker.Random.Guid().ToString(), _faker.Database.Random.AlphaNumeric(5), _faker.Internet.Url()), UserCommandFaker.GenerateRegisterNewUserCommand().Generate(), claims);

            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}}");
        }