Beispiel #1
0
        public async Task Context()
        {
            _email = A.Fake <Email>();
            var emailParts = new EmailPart[0];

            A.CallTo(() => _email.Id).Returns(EmailId);
            A.CallTo(() => _email.Parts).Returns(emailParts);

            _recipientOne = RecipientBuilder.New.WithId(RecipientOneId).WithEmailAddress(RecipientOneEmailAddress).WithName(RecipientOneName).Build();
            _recipientTwo = RecipientBuilder.New.WithId(RecipientTwoId).WithEmailAddress(RecipientTwoEmailAddress).WithName(RecipientTwoName).Build();
            A.CallTo(() => _email.EmailRecipients).Returns(new HashSet <EmailRecipient>
            {
                new EmailRecipient(_email, _recipientOne),
                new EmailRecipient(_email, _recipientTwo)
            });

            A.CallTo(() => _email.FromAddress).Returns(FromAddress);
            A.CallTo(() => _email.Subject).Returns(Subject);

            var emailRepository = A.Fake <IRepository <Email> >();

            A.CallTo(() => emailRepository.GetAsync(EmailId)).Returns(_email);

            var emailHtmlBuilder = A.Fake <IEmailHtmlBuilder>();

            A.CallTo(() => emailHtmlBuilder.BuildHtmlEmail(emailParts)).Returns(EmailHtml);

            _bus = A.Fake <IBus>();
            _bus.ExpectMessageSentLocal <SendEmailForEmailRecipientMessage>(x => _sentMessages.Add(x));

            var handler = new EmailEnqueuedToBeSentEventMessageHandler(emailRepository, emailHtmlBuilder, _bus);
            await handler.Handle(new EmailEnqueuedToBeSentEventMessage { EmailId = EmailId });
        }
        public void Context()
        {
            _email = MockRepository.GenerateMock<Email>();
            var emailParts = new EmailPart[0];
            _email.Stub(a => a.Id).Return(EmailId);
            _email.Stub(a => a.Parts).Return(emailParts);

            _recipientOne = RecipientBuilder.New.WithId(RecipientOneId).WithEmailAddress(RecipientOneEmailAddress).WithName(RecipientOneName).Build();
            _recipientTwo = RecipientBuilder.New.WithId(RecipientTwoId).WithEmailAddress(RecipientTwoEmailAddress).WithName(RecipientTwoName).Build();
            _email.Stub(a => a.EmailRecipients).Return(new HashSet<EmailRecipient>
                                                          {
                                                              new EmailRecipient(_email, _recipientOne),
                                                              new EmailRecipient(_email, _recipientTwo)
                                                          });

            _email.Stub(a => a.FromAddress).Return(FromAddress);
            _email.Stub(a => a.Subject).Return(Subject);

            var emailRepository = MockRepository.GenerateStub<IRepository<Email>>();
            emailRepository.Stub(a => a.GetById(EmailId)).Return(_email);

            var emailHtmlBuilder = MockRepository.GenerateStub<IEmailHtmlBuilder>();
            emailHtmlBuilder.Stub(a => a.BuildHtmlEmail(emailParts)).Return(EmailHtml);

            _bus = MockRepository.GenerateStub<IBus>();

            var handler = new EmailEnqueuedToBeSentEventMessageHandler(emailRepository, emailHtmlBuilder, _bus);
            handler.Handle(new EmailEnqueuedToBeSentEventMessage {EmailId = EmailId});
        }