Ejemplo n.º 1
0
        public void IgnoreBuffer_SendsEmailRegardless()
        {
            // ARRANGE
            var batch = GetBatch();
            batch.Add(new MAIL()
            {
                UserID = "example-user",
                SenderEmailAddress = "*****@*****.**",
                ReceiverEmailAddress = "*****@*****.**",
                EnqueuedUTC = DateTime.UtcNow,
                NextProcessingAttemptUTC = DateTime.UtcNow,
                BufferIgnored = true,
                BufferHours = 4,
                Subject = "subject",
                Body = "body",
                SummaryHeader = "Welcome,",
                SummaryFooter = "Thanks",
                SummarySubject = "summary",
                SummaryBody = "summarybody"
            });

            var repMock = new Mock<IRepository<MAIL>>();
            var subject = new SqlMailQueue(repMock.Object);

            var last = new MAIL()
            {
                SentUTC = DateTime.UtcNow.AddHours(0) // buffer should be active
            };

            var sent = new List<Models.RenderedMail>();

            // ACT
            subject.Dequeue(m =>
            {
                sent.Add(m);
                return true;
            },
            () => batch,
            (uid) => last);

            // ASSERT
            Assert.AreEqual(1, sent.Count);

            var mail = sent.First();
            Assert.AreEqual("subject", mail.Subject);
        }
Ejemplo n.º 2
0
        public void WithBuffer_FlushWhenWindowIsOver_WithHtml()
        {
            // ARRANGE
            var batch = new List<MAIL>();
            batch.Add(new MAIL()
            {
                UserID = "example-user",
                SenderEmailAddress = "*****@*****.**",
                ReceiverEmailAddress = "*****@*****.**",
                EnqueuedUTC = DateTime.UtcNow,
                NextProcessingAttemptUTC = DateTime.UtcNow,
                Subject = "subject",
                SummarySubject = "summary",

                Body = "htmlbody",
                SummaryHeader = "htmlWelcome,",
                SummaryFooter = "htmlThanks",
                SummaryBody = "htmlsummarybody",

                TextBody = "textbody",
                SummaryTextHeader = "textWelcome,",
                SummaryTextFooter = "textThanks",
                SummaryTextBody = "textsummarybody",

                BufferHours = 4
            });

            var repMock = new Mock<IRepository<MAIL>>();
            var subject = new SqlMailQueue(repMock.Object);

            var last = new MAIL()
            {
                SentUTC = DateTime.UtcNow.AddHours(-5) // buffer should be active
            };

            var sent = new List<Models.RenderedMail>();

            // ACT
            subject.Dequeue(m =>
            {
                sent.Add(m);
                return true;
            },
            () => batch,
            (uid) => last);

            // ASSERT
            Assert.AreEqual(1, sent.Count);

            var mail = sent.First();
            Assert.AreEqual("summary", mail.Subject);
            const string assembledHtmlBody =
            @"htmlWelcome,
htmlsummarybody
htmlThanks
";
            Assert.AreEqual(assembledHtmlBody, mail.Body);

            const string assembledTextBody =
          @"textWelcome,
textsummarybody
textThanks
";
            Assert.AreEqual(assembledTextBody, mail.TextBody);

        }