public void Process_FormatReturnsNoMessage_DoesNotSendMessage()
        {
            var mockMF = new Mock<IMessageFormatter>();
            var mockMD = new Mock<IMessageDelivery>();

            var sub = new EmailEventHandler(mockMF.Object, mockMD.Object);

            var mockAcct = new MockUserAccount();
            var mockEvt = new Mock<UserAccountEvent>();
            mockEvt.Object.Account = mockAcct.Object;
            sub.Process(mockEvt.Object);

            mockMD.Verify(x => x.Send(It.IsAny<Message>()), Times.Never());
        }
        public void Process_FormatReturnsNoMessage_DoesNotSendMessage()
        {
            var mockMF = new Mock <IMessageFormatter>();
            var mockMD = new Mock <IMessageDelivery>();

            var sub = new EmailEventHandler(mockMF.Object, mockMD.Object);

            var mockAcct = new MockUserAccount();
            var mockEvt  = new Mock <UserAccountEvent>();

            mockEvt.Object.Account = mockAcct.Object;
            sub.Process(mockEvt.Object);

            mockMD.Verify(x => x.Send(It.IsAny <Message>()), Times.Never());
        }
        public void Process_FormatReturnsMessage_SendsMessage()
        {
            var msg = new Message();
            var mockMF = new Mock<IMessageFormatter>();
            var mockMD = new Mock<IMessageDelivery>();
            mockMF.Setup(x => x.Format(It.IsAny<UserAccountEvent>())).Returns(msg);

            var sub = new EmailEventHandler(mockMF.Object, mockMD.Object);

            var mockAcct = new MockUserAccount();
            var mockEvt = new Mock<UserAccountEvent>();
            mockEvt.Object.Account = mockAcct.Object;
            sub.Process(mockEvt.Object);

            mockMD.Verify(x => x.Send(msg));
        }
        public void Process_ExplicitEmailParam_UsesExplicitEmail()
        {
            var msg = new Message();
            var mockMF = new Mock<IMessageFormatter>();
            var mockMD = new Mock<IMessageDelivery>();
            mockMF.Setup(x => x.Format(It.IsAny<UserAccountEvent>())).Returns(msg);

            var sub = new EmailEventHandler(mockMF.Object, mockMD.Object);

            var mockAcct = new MockUserAccount();
            mockAcct.Object.Email = "foo";
            var mockEvt = new Mock<UserAccountEvent>();
            mockEvt.Object.Account = mockAcct.Object;
            sub.Process(mockEvt.Object, "bar");

            Assert.AreEqual("bar", msg.To);
        }
        public void Process_FormatReturnsMessage_SendsMessage()
        {
            var msg    = new Message();
            var mockMF = new Mock <IMessageFormatter>();
            var mockMD = new Mock <IMessageDelivery>();

            mockMF.Setup(x => x.Format(It.IsAny <UserAccountEvent>())).Returns(msg);

            var sub = new EmailEventHandler(mockMF.Object, mockMD.Object);

            var mockAcct = new MockUserAccount();
            var mockEvt  = new Mock <UserAccountEvent>();

            mockEvt.Object.Account = mockAcct.Object;
            sub.Process(mockEvt.Object);

            mockMD.Verify(x => x.Send(msg));
        }
        public void Process_ExplicitEmailParam_UsesExplicitEmail()
        {
            var msg    = new Message();
            var mockMF = new Mock <IMessageFormatter>();
            var mockMD = new Mock <IMessageDelivery>();

            mockMF.Setup(x => x.Format(It.IsAny <UserAccountEvent>())).Returns(msg);

            var sub = new EmailEventHandler(mockMF.Object, mockMD.Object);

            var mockAcct = new MockUserAccount();

            mockAcct.Object.Email = "foo";
            var mockEvt = new Mock <UserAccountEvent>();

            mockEvt.Object.Account = mockAcct.Object;
            sub.Process(mockEvt.Object, "bar");

            Assert.AreEqual("bar", msg.To);
        }