Example #1
0
        public void CanSendTemplateEmail()
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixture = new FixtureData(uow);
                var outboundEmailDaemon = new OutboundEmail();

                // SETUP
                var email = fixture.TestEmail1();

                // EXECUTE
                //var envelope = uow.EnvelopeRepository.ConfigureTemplatedEmail(email, "template", null);
                var envelope = uow.EnvelopeRepository.ConfigureTemplatedEmail(email, "a16da250-a48b-42ad-88e1-bdde24ae1dee", null);
                uow.SaveChanges();

                //adding user for alerts at outboundemail.cs  //If we don't add user, AlertManager at outboundemail generates error and test fails.
                AddNewTestCustomer(email.From);
                
                var mockEmailer = new Mock<IEmailPackager>();
                mockEmailer.Setup(a => a.Send(envelope)).Verifiable();
                ObjectFactory.Configure(
                    a => a.For<IEmailPackager>().Use(mockEmailer.Object).Named(EnvelopeDO.SendGridHander));
                DaemonTests.RunDaemonOnce(outboundEmailDaemon);

                // VERIFY
                mockEmailer.Verify(a => a.Send(envelope), "OutboundEmail daemon didn't dispatch email via Mandrill.");
            }
        }
Example #2
0
        public void FailsToSendInvalidEnvelope()
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixture = new FixtureData(uow);
                var outboundEmailDaemon = new OutboundEmail();

                // SETUP
                var email = fixture.TestEmail1();

                // EXECUTE
                var envelope = uow.EnvelopeRepository.ConfigureTemplatedEmail(email, "a16da250-a48b-42ad-88e1-bdde24ae1dee", null);

                envelope.Handler = "INVALID EMAIL PACKAGER";
                uow.SaveChanges();

                //adding user for alerts at outboundemail.cs  //If we don't add user, AlertManager at outboundemail generates error and test fails.
                AddNewTestCustomer(email.From);

                var mockMandrillEmailer = new Mock<IEmailPackager>();
                mockMandrillEmailer.Setup(a => a.Send(envelope)).Throws<ApplicationException>(); // shouldn't be invoked
                ObjectFactory.Configure(
                    a => a.For<IEmailPackager>().Use(mockMandrillEmailer.Object).Named(EnvelopeDO.SendGridHander));
                var mockSendGridEmailer = new Mock<IEmailPackager>();
                mockSendGridEmailer.Setup(a => a.Send(envelope)).Throws<ApplicationException>(); // shouldn't be invoked
                ObjectFactory.Configure(
                    a => a.For<IEmailPackager>().Use(mockSendGridEmailer.Object).Named(EnvelopeDO.SendGridHander));

                // VERIFY
                Assert.Throws<UnknownEmailPackagerException>(
                    () => DaemonTests.RunDaemonOnce(outboundEmailDaemon),
                    "OutboundEmail daemon didn't throw an exception for invalid EnvelopeDO.");
            }
        }