public void Create_WhenPassedValidEmailRequest_ReturnsMailMessageCorrectToCcBccAndReplyTo()
        {
            var mailSettings = new BencoSmtpSettings();

            var mockOptions = new Mock <IOptions <BencoSmtpSettings> >();

            mockOptions.Setup(m => m.Value)
            .Returns(mailSettings);
            var fixture      = new Fixture();
            var emailRequest = fixture
                               .Build <EmailRequest>()
                               .Without(s => s.Attachments)
                               .With(s => s.From, "*****@*****.**")
                               .With(s => s.To, new[] { "*****@*****.**", "*****@*****.**" })
                               .With(s => s.Cc, new[] { "*****@*****.**" })
                               .With(s => s.Bcc, new[] { "*****@*****.**" })
                               .With(s => s.ReplyTo, new [] { "*****@*****.**" })
                               .Create();

            var sut = new EmailSender(mockOptions.Object);

            var actualResult = sut.CreateEmail(emailRequest);

            Assert.Equal(new[] { "*****@*****.**", "*****@*****.**" }, actualResult.To.Select(s => s.Address));
            Assert.Equal(new[] { "*****@*****.**" }, actualResult.CC.Select(s => s.Address));
            Assert.Equal(new[] { "*****@*****.**" }, actualResult.Bcc.Select(s => s.Address));
            Assert.Equal(new[] { "*****@*****.**" }, actualResult.ReplyToList.Select(s => s.Address));
        }
        public void Create_WhenPassedRequestWithNullReplyTo_CreatesMessageWithoutReplyTo()
        {
            var mailSettings = new BencoSmtpSettings();

            var mockOptions = new Mock <IOptions <BencoSmtpSettings> >();

            mockOptions.Setup(m => m.Value)
            .Returns(mailSettings);
            var fixture      = new Fixture();
            var emailRequest = fixture
                               .Build <EmailRequest>()
                               .Without(s => s.Attachments)
                               .With(s => s.From, "*****@*****.**")
                               .With(s => s.To, new[] { "*****@*****.**", "*****@*****.**" })
                               .With(s => s.Cc, new[] { "*****@*****.**" })
                               .With(s => s.Bcc, new[] { "*****@*****.**" })
                               .With(s => s.ReplyTo, (string[])null)
                               .Create();

            var sut = new EmailSender(mockOptions.Object);

            var actualResult = sut.CreateEmail(emailRequest);

            Assert.Equal(new[] { "*****@*****.**", "*****@*****.**" }, actualResult.To.Select(s => s.Address));
            Assert.Equal(new[] { "*****@*****.**" }, actualResult.CC.Select(s => s.Address));
            Assert.Equal(new[] { "*****@*****.**" }, actualResult.Bcc.Select(s => s.Address));
            Assert.Equal(Enumerable.Empty <string>(), actualResult.ReplyToList.Select(s => s.Address).ToArray());
        }
        public void Create_WhenOnProductionAndPassedValidEmailRequest_ReturnsMailMessageWithValidFrom()
        {
            var mailSettings = new BencoSmtpSettings();

            var mockOptions = new Mock <IOptions <BencoSmtpSettings> >();

            mockOptions.Setup(m => m.Value)
            .Returns(mailSettings);
            var fixture      = new Fixture();
            var emailRequest = fixture
                               .Build <EmailRequest>()
                               .Without(s => s.Attachments)
                               .With(s => s.From, "*****@*****.**")
                               .With(s => s.To, new [] { "*****@*****.**", "*****@*****.**" })
                               .With(s => s.Cc, new string[] {})
                               .With(s => s.Bcc, new string[] { })
                               .With(s => s.ReplyTo, new[] { "*****@*****.**" })
                               .Create();

            var sut = new EmailSender(mockOptions.Object);

            var actualResult = sut.CreateEmail(emailRequest);

            Assert.Equal(emailRequest.From, actualResult.From.Address);
        }
        public void Create_WhenPassedRequestWithNullFrom_ThrowsArgumentNullException()
        {
            var mailSettings = new BencoSmtpSettings();

            var mockOptions = new Mock <IOptions <BencoSmtpSettings> >();

            mockOptions.Setup(m => m.Value)
            .Returns(mailSettings);
            var fixture      = new Fixture();
            var emailRequest = fixture
                               .Build <EmailRequest>()
                               .Without(s => s.Attachments)
                               .With(s => s.From, (string)null)
                               .With(s => s.To, new[] { "*****@*****.**", "*****@*****.**" })
                               .With(s => s.Cc, new[] { "*****@*****.**" })
                               .With(s => s.Bcc, new[] { "*****@*****.**" })
                               .With(s => s.ReplyTo, new[] { "*****@*****.**" })
                               .Create();

            var sut = new EmailSender(mockOptions.Object);

            var exception = Assert.Throws <ArgumentNullException>(() => sut.CreateEmail(emailRequest));

            Assert.Equal("address", exception.ParamName);
        }
        public void CanCreateEmailSender()
        {
            var mailSettings = new BencoSmtpSettings();
            var mockOptions  = new Mock <IOptions <BencoSmtpSettings> >();

            mockOptions.Setup(m => m.Value)
            .Returns(mailSettings);

            // ReSharper disable once UnusedVariable
            var sut = new EmailSender(mockOptions.Object);
        }
        public void Create_WhenPassedNull_ThrowsArgumentNullException()
        {
            var mailSettings = new BencoSmtpSettings();
            var mockOptions  = new Mock <IOptions <BencoSmtpSettings> >();

            mockOptions.Setup(m => m.Value)
            .Returns(mailSettings);

            var sut = new EmailSender(mockOptions.Object);

            Assert.Throws <ArgumentNullException>(() => sut.CreateEmail(null));
        }
        public void Create_WhenPassedRequestWithAttachments_CreatesMessageWithAttachments()
        {
            var mailSettings = new BencoSmtpSettings();

            var mockOptions = new Mock <IOptions <BencoSmtpSettings> >();

            mockOptions.Setup(m => m.Value)
            .Returns(mailSettings);

            var attachments = new[]
            {
                new EmailAttachment
                {
                    Filename = "spreadsheet.csv",
                    Data     = new MemoryStream()
                },
                new EmailAttachment
                {
                    Filename = "Resume.pdf",
                    Data     = new MemoryStream()
                }
            };

            var fixture      = new Fixture();
            var emailRequest = fixture
                               .Build <EmailRequest>()
                               .With(s => s.From, "*****@*****.**")
                               .With(s => s.To, new[] { "*****@*****.**", "*****@*****.**" })
                               .With(s => s.Cc, (string[])null)
                               .With(s => s.Bcc, (string[])null)
                               .With(s => s.ReplyTo, (string[])null)
                               .With(s => s.Attachments, attachments)
                               .Create();

            var sut = new EmailSender(mockOptions.Object);

            var actualResult = sut.CreateEmail(emailRequest);

            Assert.Equal(2, actualResult.Attachments.Count);
        }