public void BuildTextBody_AndHtml(string html)
        {
            var body        = new ContentBody().WithPlainText("some text");
            var contentStep =
                new MessageBuilder.BuildContentStep.BuildBodyStep.BuildTextBodyStep(
                    MailerMessage.Create().WithBody(body), body);
            var stepBuilder = contentStep.AndHtml(html);

            stepBuilder
            .Should()
            .NotBeNull()
            .And.BeOfType <MessageBuilder.BuildContentStep.BuildBodyStep.BuildBodyCompleteStep>()
            .Which.As <IBuilderContext>()
            .Message.Body
            .As <ContentBody>()
            .ShouldBeEquivalentTo
            (
                new ContentBody
            {
                HtmlContent      = html,
                PlainTextContent = "some text"
            },
                config => config
                .Including(b => b.HtmlContent)
                .Including(b => b.PlainTextContent));
        }
Esempio n. 2
0
        public void BuildPostContentStep_WithAttachment(string fileName)
        {
            var contentStep = new MessageBuilder.BuildPostContentStep(MailerMessage.Create());

            if (string.IsNullOrEmpty(fileName))
            {
                contentStep.Invoking(s => s.WithAttachment(fileName)).Should().Throw <FileNotFoundException>();
            }
            else
            {
                var path = Path.Combine(AppContext.BaseDirectory, fileName);

                var stepBuilder = contentStep.WithAttachment(path);

                stepBuilder
                .Should()
                .NotBeNull()
                .And.BeOfType <MessageBuilder.BuildPostContentStep.BuildAttachmentOrSubstitutionStep>()
                .Which.As <IBuilderContext>()
                .Message.Attachments
                .Should()
                .NotBeEmpty()
                .And.Subject.Keys.Select(Path.GetFileName)
                .Should()
                .Contain(Path.GetFileName(path));
            }
        }
        public void BuildHtmlBodyStep_AndPlainText(string text)
        {
            var body        = new ContentBody().WithHtml("<tag>something</tag>");
            var contentStep =
                new MessageBuilder.BuildContentStep.BuildBodyStep.BuildHtmlBodyStep(
                    MailerMessage.Create().WithBody(body), body);
            var stepBuilder = contentStep.AndPlainText(text);

            stepBuilder
            .Should()
            .NotBeNull()
            .And.BeOfType <MessageBuilder.BuildContentStep.BuildBodyStep.BuildBodyCompleteStep>()
            .Which.As <IBuilderContext>()
            .Message.Body
            .As <ContentBody>()
            .Should().BeEquivalentTo
            (
                new ContentBody
            {
                HtmlContent      = "<tag>something</tag>",
                PlainTextContent = text
            },
                config => config
                .Including(b => b.HtmlContent)
                .Including(b => b.PlainTextContent));
        }
Esempio n. 4
0
        public async Task Ef_History_List()
        {
            var store = Fixture.ServiceProvider.GetService <IHistoryStore>();

            store.Should().BeOfType <EntityHistoryStore <TestHistoryContext> >();


            for (var x = 0; x < 15; x++)
            {
                await store.AddAsync(new DeliveryItem(MailerMessage.Create(), new MessageRecipient())
                {
                    CreatedDate      = DateTimeOffset.Now,
                    ToDisplayName    = x.ToString(),
                    Subject          = x.ToString(),
                    ToEmailAddress   = $"{x}@toast.com",
                    DeliveryProvider = "xunit",
                    Id               = Guid.NewGuid(),
                    IsSuccess        = true,
                    ExceptionMessage = null,
                    Body             = new ContentBody {
                        PlainTextContent = "content"
                    },
                    FromDisplayName  = "noone",
                    FromEmailAddress = "*****@*****.**"
                });
            }

            var items = await store.GetAsync(0, 10, CancellationToken.None);

            items.Should().HaveCount(10);

            var secondPageitems = await store.GetAsync(10, 5, CancellationToken.None);

            secondPageitems.Should().HaveCount(5).And.NotBeSameAs(items);
        }
Esempio n. 5
0
        public void BuildPostContentStep_WithSubstitution(string token, string value)
        {
            var contentStep = new MessageBuilder.BuildPostContentStep(MailerMessage.Create());

            if (token == null)
            {
                contentStep.Invoking(c => c.WithSubstitution(null, value)).Should().Throw <ArgumentNullException>();
            }
            else
            {
                var stepBuilder = contentStep.WithSubstitution(token, value);

                stepBuilder
                .Should()
                .NotBeNull()
                .And.BeOfType <MessageBuilder.BuildPostContentStep.BuildAttachmentOrSubstitutionStep>()
                .Which.As <IBuilderContext>()
                .Message.Substitutions
                .Should()
                .NotBeEmpty()
                .And.ContainKey(token)
                .WhichValue.Should()
                .Be(value);
            }
        }
        public async Task Ef_Sql_History_Search()
        {
            var history = Fixture.ServiceProvider.GetService <IHistoryStore>();
            await history.AddAsync(new DeliveryItem(MailerMessage.Create(), new MessageRecipient())
            {
                CreatedDate           = DateTimeOffset.Now,
                ToDisplayName         = "No One",
                Subject               = "test message",
                ToEmailAddress        = "*****@*****.**",
                DeliveryProvider      = "xunit",
                SourceApplicationName = "xunit",
                Id               = Guid.NewGuid(),
                IsSuccess        = true,
                ExceptionMessage = null,
                Body             = new ContentBody {
                    PlainTextContent = "content"
                },
                FromDisplayName  = "noone",
                FromEmailAddress = "*****@*****.**"
            });

            await history.AddAsync(new DeliveryItem(MailerMessage.Create(), new MessageRecipient())
            {
                CreatedDate           = DateTimeOffset.Now,
                ToDisplayName         = "Some One",
                Subject               = "test message",
                ToEmailAddress        = "*****@*****.**",
                DeliveryProvider      = "xunit",
                SourceApplicationName = "xunit",
                Id               = Guid.NewGuid(),
                IsSuccess        = true,
                ExceptionMessage = null,
                Body             = new ContentBody {
                    PlainTextContent = "content"
                },
                FromDisplayName  = "noone",
                FromEmailAddress = "*****@*****.**"
            });

            var searchA = await history.SearchAsync("else");

            searchA.Should().NotBeNull().And.OnlyContain(i => i.SourceApplicationName == "xunit");
            searchA.Should().NotBeNull().And.OnlyContain(i => i.ToEmailAddress == "*****@*****.**");

            var searchB = await history.SearchAsync("else", sourceApplicationName : "noxunit");

            searchB.Should().BeEmpty();

            var searchC = await history.SearchAsync("else", startDate : DateTimeOffset.UtcNow.AddHours(-1),
                                                    endDate : DateTimeOffset.UtcNow);

            searchC.Should().NotBeNull().And.OnlyContain(i => i.SourceApplicationName == "xunit");
            searchC.Should().NotBeNull().And.OnlyContain(i => i.ToEmailAddress == "*****@*****.**");

            var searchD = await history.SearchAsync("else", startDate : DateTimeOffset.UtcNow.AddHours(-2),
                                                    endDate : DateTimeOffset.UtcNow.AddHours(-1));

            searchD.Should().BeEmpty();
        }
        public void BuildContentStep_ForBody()
        {
            var contentStep = new MessageBuilder.BuildContentStep(MailerMessage.Create());
            var stepBuilder = contentStep.ForBody();

            stepBuilder
            .Should()
            .NotBeNull()
            .And.BeOfType <MessageBuilder.BuildContentStep.BuildBodyStep>();
        }
        public void BuildTextBody_And()
        {
            var contentStep =
                new MessageBuilder.BuildContentStep.BuildBodyStep.BuildTextBodyStep(MailerMessage.Create(),
                                                                                    ContentBody.Create());

            contentStep.And
            .Should()
            .NotBeNull()
            .And.BeOfType <MessageBuilder.BuildPostContentStep>();
        }
Esempio n. 9
0
        public void BuildPostContentStep_Build()
        {
            var contentStep = new MessageBuilder.BuildPostContentStep(MailerMessage.Create());

            var message = contentStep.Build();

            message
            .Should()
            .NotBeNull()
            .And.BeOfType <MailerMessage>();
        }
        public void BuildContentStep_ForTemplate(string templateName)
        {
            var contentStep = new MessageBuilder.BuildContentStep(MailerMessage.Create());
            var stepBuilder = contentStep.ForTemplate(templateName);

            stepBuilder
            .Should()
            .NotBeNull()
            .And.BeOfType <MessageBuilder.BuildContentStep.BuildContentTemplateStep>()
            .Which.As <IBuilderContext>()
            .Message.Body.As <TemplateBody>()
            .TemplateName
            .Should()
            .Be(templateName);
        }
Esempio n. 11
0
        public void BuildBodyStep_WithPlainText(string text)
        {
            var contentStep = new MessageBuilder.BuildContentStep.BuildBodyStep(MailerMessage.Create());
            var stepBuilder = contentStep.WithPlainText(text);

            stepBuilder
            .Should()
            .NotBeNull()
            .And.BeOfType <MessageBuilder.BuildContentStep.BuildBodyStep.BuildTextBodyStep>()
            .Which.As <IBuilderContext>()
            .Message.Body
            .As <ContentBody>()
            .PlainTextContent
            .Should()
            .Be(text);
        }
Esempio n. 12
0
        public void BuildBodyStep_WithHtml(string html)
        {
            var contentStep = new MessageBuilder.BuildContentStep.BuildBodyStep(MailerMessage.Create());
            var stepBuilder = contentStep.WithHtml(html);

            stepBuilder
            .Should()
            .NotBeNull()
            .And.BeOfType <MessageBuilder.BuildContentStep.BuildBodyStep.BuildHtmlBodyStep>()
            .Which.As <IBuilderContext>()
            .Message.Body
            .As <ContentBody>()
            .HtmlContent
            .Should()
            .Be(html);
        }
        public void BuildContentStep_To(string address)
        {
            var contentStep = new MessageBuilder.BuildContentStep(MailerMessage.Create());
            var stepBuilder = contentStep.To(address);

            stepBuilder
            .Should()
            .NotBeNull()
            .And.BeOfType <MessageBuilder.BuildRecipientsStep.BuildToStep>()
            .Which.As <IBuilderContext>()
            .Message.Recipients
            .Should()
            .NotBeNull()
            .And.NotBeEmpty()
            .And.AllBeAssignableTo <MessageRecipient>()
            .And.Contain(r => r.EmailAddress == address);
        }
        public void BuildHtmlBodyStep_Build()
        {
            var body        = new ContentBody().WithHtml("<tag>something</tag>");
            var contentStep =
                new MessageBuilder.BuildContentStep.BuildBodyStep.BuildHtmlBodyStep(
                    MailerMessage.Create().WithBody(body), body);
            var message = contentStep.Build();

            message
            .Should()
            .NotBeNull()
            .And.BeOfType <MailerMessage>()
            .Which.Body.As <ContentBody>()
            .HtmlContent
            .Should()
            .NotBeNullOrEmpty()
            .And.Be("<tag>something</tag>");
        }
        public void BuildTextBody_Build()
        {
            var body        = new ContentBody().WithPlainText("some text");
            var contentStep =
                new MessageBuilder.BuildContentStep.BuildBodyStep.BuildTextBodyStep(
                    MailerMessage.Create().WithBody(body), body);

            var message = contentStep.Build();

            message
            .Should()
            .NotBeNull()
            .And.BeOfType <MailerMessage>()
            .Which.Body.As <ContentBody>()
            .PlainTextContent
            .Should()
            .NotBeNullOrEmpty()
            .And.Be("some text");
        }
        public void BuildAttachmentOrSubstitutionStep_And()
        {
            var contentStep =
                new MessageBuilder.BuildPostContentStep.BuildAttachmentOrSubstitutionStep(MailerMessage.Create());

            contentStep.And
            .Should()
            .NotBeNull()
            .And.BeOfType <MessageBuilder.BuildPostContentStep>();
        }