Esempio n. 1
0
        public void TestRetryWorks()
        {
            var count     = 0;
            var messenger = new Mock <IMessenger>();

            messenger.Setup(a => a.Send(It.IsAny <Message>()))

            .Callback(() =>
            {
                Debug.WriteLine(Thread.CurrentThread.ManagedThreadId);
                count++;
                if (count == 2)
                {
                    throw new SmtpException();
                }
            });

            SmtpClient.Send(messenger.Object, Messages, TimeSpan.FromSeconds(1), 3);

            messenger.Verify(m => m.Send(It.IsAny <Message>()), Times.Exactly(4));

            messenger.Verify(m => m.Send(It.Is <Message>(s => s.Subject == "m1")), Times.AtLeastOnce());
            messenger.Verify(m => m.Send(It.Is <Message>(s => s.Subject == "m2")), Times.AtLeastOnce());
            messenger.Verify(m => m.Send(It.Is <Message>(s => s.Subject == "m3")), Times.AtLeastOnce());
        }
Esempio n. 2
0
        public void TestEachMessageIsSent()
        {
            var messenger = new Mock <IMessenger>();

            SmtpClient.Send(messenger.Object, Messages, TimeSpan.FromSeconds(3), 2);

            messenger.Verify(m => m.Send(It.Is <Message>(s => s.Subject == "m1")), Times.Once);
            messenger.Verify(m => m.Send(It.Is <Message>(s => s.Subject == "m2")), Times.Once);
            messenger.Verify(m => m.Send(It.Is <Message>(s => s.Subject == "m3")), Times.Once);
        }