public void GivenEmailWithoutBody_WhenFinalizing_ShouldFail()
        {
            var recipient = new EmailAddress("*****@*****.**");

            var message = EmailMessage.CreatePending(subject: "Test",
                                                     body: null,
                                                     sender: new EmailAddress("*****@*****.**"),
                                                     recipients: new[] { recipient });

            Assert.Catch <EmptyMessageBodyException>(() => { message.FinalizeMessage(); });
        }
        public void GivenEmailWithoutRecipients_WhenFinalizing_ShouldSucceed()
        {
            var recipient = new EmailAddress("*****@*****.**");

            var message = EmailMessage.CreatePending(subject: "Test",
                                                     body: MessageBody.CreateTextBody("This is test message"),
                                                     sender: new EmailAddress("*****@*****.**"),
                                                     recipients: null);

            Assert.Catch <NoRecipientsException>(() => { message.FinalizeMessage(); });
        }
        public void GivenCompleteEmail_WhenFinalizing_ShouldSucceed()
        {
            var recipient = new EmailAddress("*****@*****.**");

            var message = EmailMessage.CreatePending(subject: "Test",
                                                     body: MessageBody.CreateTextBody("This is test message"),
                                                     sender: new EmailAddress("*****@*****.**"),
                                                     recipients: new[] { recipient });

            Assert.DoesNotThrow(() => { message.FinalizeMessage(); });
        }
        public void GivenTwoSameRecipients_ShouldStoreOne()
        {
            const string emailAddress = "*****@*****.**";
            var          recipient    = new EmailAddress(emailAddress);
            var          recipient2   = new EmailAddress(emailAddress);

            var message = EmailMessage.CreatePending(subject: "Test",
                                                     body: MessageBody.CreateTextBody("This is test message"),
                                                     sender: new EmailAddress("*****@*****.**"),
                                                     recipients: new[] { recipient });

            message.AddRecipient(recipient2);

            Assert.That(message.Recipients.Count(), Is.EqualTo(1));
        }
Пример #5
0
            public async Task <Unit> Handle(CreateEmailMessage command, CancellationToken cancellationToken)
            {
                var messageBody = GetMessageBody(command.Body, command.IsHtmlBody);
                var sender      = EmailAddress.Create(command.Sender);
                var recipients  = command.Recipients?
                                  .Select(EmailAddress.Create)
                                  .Where(x => !(x is null));

                var message = command.IsPendingEmail
                    ? EmailMessage.CreatePending(command.Subject, messageBody, sender, recipients)
                    : EmailMessage.Create(command.Subject, messageBody, sender, recipients);

                await this.repository.InsertMessageAsync(message);

                return(Unit.Value);
            }