public void CoordinatorCompleteWithEmailAndDefaultEmailSendsEmail()
        {
            var mailActioner = MockRepository.GenerateMock<IMailActioner>();
            var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>();
            var session = MockRepository.GenerateMock<IDocumentSession>();
            ravenDocStore.Expect(r => r.GetStore().OpenSession("Configuration"))
                .Return(session);
            var mailgunConfig = new MailgunConfiguration {ApiKey = "key", DomainName = "domain", DefaultFrom = "*****@*****.**"};
            session.Expect(s => s.Load<MailgunConfiguration>("MailgunConfig")).Return(mailgunConfig);
            var emailDefaultNotification = new EmailDefaultNotification { EmailAddresses = new List<string> { "*****@*****.**", "*****@*****.**" } };
            session.Expect(s => s.Load<EmailDefaultNotification>("EmailDefaultConfig")).Return(emailDefaultNotification);

            var message = new MailMessage();
            mailActioner.Expect(m => m.Send(Arg<MailgunConfiguration>.Is.Equal(mailgunConfig), Arg<MailMessage>.Is.NotNull)).WhenCalled(a => message = (MailMessage)(a.Arguments[1]));

            var emailService = new EmailService { MailActioner = mailActioner, RavenDocStore = ravenDocStore };
            var coordinatorComplete = new CoordinatorCompleteEmail
                                          {
                                              CoordinatorId = Guid.NewGuid(),
                                              EmailAddress = "*****@*****.**",
                                              FinishTimeUtc = DateTime.Now,
                                              StartTimeUtc = DateTime.Now.AddMinutes(-10),
                                              SendingData = new SendingData()
                                          };
            emailService.Handle(coordinatorComplete);

            mailActioner.VerifyAllExpectations();
            Assert.That(message.From.ToString(), Is.EqualTo(mailgunConfig.DefaultFrom));
            Assert.That(message.To[0].Address, Is.EqualTo(coordinatorComplete.EmailAddress));
            Assert.That(message.To[1].Address, Is.EqualTo(emailDefaultNotification.EmailAddresses[0]));
            Assert.That(message.To[2].Address, Is.EqualTo(emailDefaultNotification.EmailAddresses[1]));
        }
        public void CoordinatorCompleteWithEmailDefaultFromNotSentThrowsException()
        {
            var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>();
            var session = MockRepository.GenerateMock<IDocumentSession>();
            ravenDocStore.Expect(r => r.GetStore().OpenSession("Configuration"))
                .Return(session);
            var mailgunConfig = new MailgunConfiguration { ApiKey = "key", DomainName = "domain", DefaultFrom = string.Empty };
            session.Expect(s => s.Load<MailgunConfiguration>("MailgunConfig")).Return(mailgunConfig);

            var emailService = new EmailService { RavenDocStore = ravenDocStore };
            var coordinatorComplete = new CoordinatorCompleteEmail { EmailAddress = "*****@*****.**" };
            Assert.That(() => emailService.Handle(coordinatorComplete), Throws.Exception.With.Message.EqualTo("Could not find the default 'From' sender."));
        }
        public void CoordinatorCompleteNoEmailInMessageOrDefaultNoAction()
        {
            var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>();
            var session = MockRepository.GenerateMock<IDocumentSession>();
            ravenDocStore.Expect(r => r.GetStore().OpenSession("Configuration"))
                .Return(session);
            var emailDefaultNotification = new EmailDefaultNotification();
            session.Expect(s => s.Load<EmailDefaultNotification>("EmailDefaultConfig")).Return(emailDefaultNotification);

            var emailService = new EmailService { RavenDocStore = ravenDocStore};
            var coordinatorComplete = new CoordinatorCompleteEmail();
            emailService.Handle(coordinatorComplete);
        }
 public void CoordinatorCompleteNoEmailNoAction()
 {
     var emailService = new EmailService();
     var coordinatorComplete = new CoordinatorCompleteEmail();
     emailService.Handle(coordinatorComplete);
 }