public async Task Should_Save_Email() { var command = EmailFaker.GenerateEmailViewModel().Generate(); var result = await _emailAppService.SaveEmail(command); result.Should().BeTrue(becauseArgs: _notifications.GetNotificationsByKey()); _database.Emails.FirstOrDefault(f => f.Type == command.Type).Should().NotBeNull(); }
public async Task Should_Save_Email_With_Many_Bccs() { var command = EmailFaker.GenerateEmailViewModel().Generate(); var emailBcc = _faker.Person.Email; command.Bcc = $"{emailBcc};{_faker.Internet.Email()};{_faker.Internet.Email()};{_faker.Internet.ExampleEmail()}"; var result = await _emailAppService.SaveEmail(command); result.Should().BeTrue(becauseArgs: _notifications.GetNotificationsByKey()); }
public async Task Should_Remove_Template() { var command = EmailFaker.GenerateTemplateViewModel().Generate(); var result = await _emailAppService.SaveTemplate(command); result.Should().BeTrue(); result = await _emailAppService.RemoveTemplate(command.Name); result.Should().BeTrue(becauseArgs: _notifications.GetNotificationsByKey()); _database.Templates.FirstOrDefault(f => f.Name == command.Name).Should().BeNull(); }
public async Task Should_Find_Email_By_Type() { var command = EmailFaker.GenerateEmailViewModel().Generate(); await _emailAppService.SaveEmail(command); var email = await _emailAppService.FindByType(command.Type); _database.Emails.FirstOrDefault(f => f.Type == command.Type).Should().NotBeNull(); email.Should().NotBeNull(); email.Sender.Should().NotBeNull(); email.Sender.Name.Should().NotBeNull(); email.Sender.Address.Should().NotBeNull(); }
public async Task ShouldSaveEmailWithManyBccs() { var command = EmailFaker.GenerateEmailViewModel().Generate(); var emailBcc = _faker.Person.Email; command.Bcc = $"{emailBcc};{_faker.Internet.Email()};{_faker.Internet.Email()};{_faker.Internet.ExampleEmail()}"; var result = await _emailAppService.SaveEmail(command); result.Should().BeTrue(becauseArgs: _notifications.GetNotificationsByKey()); var email = _database.Emails.FirstOrDefault(f => f.Type == command.Type); email.Bcc.Recipients.Should().Contain(s => s.Equals(emailBcc)); }
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 Shoulh_Remove_Template() { var emailCommand = EmailCommandFaker.GenerateRemoveTemplateCommand().Generate(); var templateToRemove = EmailFaker.GenerateTemplate().Generate(); _uow.Setup(s => s.Commit()).ReturnsAsync(true); _templateRepository.Setup(s => s.GetByName(It.Is <string>(m => m == emailCommand.Name))).ReturnsAsync(templateToRemove); _templateRepository.Setup(s => s.Remove(It.Is <Template>(m => m.Id == templateToRemove.Id))); var result = await _commandHandler.Handle(emailCommand, CancellationToken.None); _templateRepository.Verify(v => v.Remove(It.IsAny <Template>()), Times.Once); result.Should().BeTrue(); }
public async Task Should_Update_Email_With_Null_Bcc() { var command = EmailFaker.GenerateEmailViewModel().Generate(); var result = await _emailAppService.SaveEmail(command); result.Should().BeTrue(becauseArgs: _notifications.GetNotificationsByKey()); var email = _database.Emails.FirstOrDefault(f => f.Type == command.Type); email.Should().NotBeNull(); command.Bcc = new BlindCarbonCopy(); command.Content = _faker.Lorem.Paragraphs(); await _emailAppService.SaveEmail(command); email = _database.Emails.FirstOrDefault(f => f.Type == command.Type); email.Should().NotBeNull(); }
public async Task Should_Update_Template() { var template = EmailCommandFaker.GenerateUpdateTemplateCommand().Generate(); _templateRepository.Setup(s => s.GetByName(It.Is <string>(m => m == template.OldName))).ReturnsAsync(EmailFaker.GenerateTemplate()); _templateRepository.Setup(s => s.Update(It.Is <Template>(m => !string.IsNullOrEmpty(m.Username) && m.Name == template.Name))); _uow.Setup(s => s.Commit()).ReturnsAsync(true); var result = await _commandHandler.Handle(template, CancellationToken.None); _templateRepository.Verify(v => v.GetByName(It.IsAny <string>()), Times.Once); result.Should().BeTrue(); }
public async Task Should_Update_Email_When_Type_Found() { var emailCommand = EmailCommandFaker.GenerateSaveEmailCommand().Generate(); _emailRepository.Setup(s => s.GetByType(It.IsAny <EmailType>())).ReturnsAsync(EmailFaker.GenerateEmail().Generate()); _emailRepository.Setup(s => s.Update(It.IsAny <Email>())); _uow.Setup(s => s.Commit()).ReturnsAsync(true); var result = await _commandHandler.Handle(emailCommand, CancellationToken.None); _emailRepository.Verify(s => s.Update(It.IsAny <Email>()), Times.Once); result.Should().BeTrue(); }
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); }