public void ShouldThrowIfEmptyBody()
        {
            // Arrange
            IEmailRequestBuilder builder = new EmailRequestBuilder()
                .AddTo("*****@*****.**")
                .WithSubject("Hello");

            // Act & Assert
            Should.Throw<DreamFactoryException>(() => builder.Build());
        }
        public void ShouldThrowIfNoTitle()
        {
            // Arrange
            IEmailRequestBuilder builder = new EmailRequestBuilder()
                .AddTo("*****@*****.**")
                .WithBody("Hello, World!");

            // Act & Assert
            Should.Throw<DreamFactoryException>(() => builder.Build());
        }
        public void ShouldThrowIfNoRecipients()
        {
            // Arrange
            IEmailRequestBuilder builder = new EmailRequestBuilder()
                .WithSubject("Hello")
                .WithBody("Hello, World!");

            // Act & Assert
            Should.Throw<DreamFactoryException>(() => builder.Build());
        }
        public void ShouldBuildEmailRequest()
        {
            // Arrange
            IEmailRequestBuilder builder = new EmailRequestBuilder()
                .AddTo("*****@*****.**")
                .WithSubject("Hello")
                .WithBody("Hello, World!");

            // Act
            EmailRequest request = builder.Build();

            // Assert
            request.subject.ShouldBe("Hello");
            request.body_text.ShouldBe("Hello, World!");
            request.to.Single().email.ShouldBe("*****@*****.**");
        }
Example #5
0
        public async Task RunAsync(IRestContext context)
        {
            // Send an email
            Console.WriteLine("Sending email...");

            // Using the builder is good for simple emails
            EmailRequest request = new EmailRequestBuilder().AddTo("*****@*****.**")
                                                            .WithSubject("Hello")
                                                            .WithBody("Hello, world!")
                                                            .Build();

            IEmailApi emailApi = context.Factory.CreateEmailApi("email");
            int count = await emailApi.SendEmailAsync(request);

            Console.WriteLine("{0} email(s) sent.", count);
        }
        public void ShouldBuildEmailRequest()
        {
            // Arrange
            IEmailRequestBuilder builder = new EmailRequestBuilder()
                .AddTo("*****@*****.**")
                .WithSubject("Hello")
                .WithBody("Hello, World!");

            // Act
            EmailRequest request = builder.Build();

            // Assert
            request.Subject.ShouldBe("Hello");
            request.BodyText.ShouldBe("Hello, World!");
            request.To.Single().Email.ShouldBe("*****@*****.**");

            Should.Throw<ArgumentNullException>(() => builder.AddTo(null));
            Should.Throw<ArgumentNullException>(() => builder.WithSubject(null));
            Should.Throw<ArgumentNullException>(() => builder.WithBody(null));
        }