public void Send_Given51Tos_SendTwoBatches() { var senderMock = new Mock<IEmailSender>(); var service = new Portal.EmailService.EmailService(senderMock.Object); var tos = new List<string>(); const string from = "*****@*****.**"; const string subject = "Test Email"; const string body = "<div>Hallo test</div>"; for (var i = 0; i < 51; i++) tos.Add(string.Format("MyMail{0}@test.test", i)); IList<SendEmailRequest> request = new List<SendEmailRequest>(); senderMock.SetupGet(s => s.MaxRecipientPerBatch).Returns(50); senderMock.Setup(s => s.Send(It.IsAny<SendEmailRequest>())).Callback<SendEmailRequest>(request.Add); service.Send(from, tos, null, subject, body); senderMock.Verify(s => s.Send(It.IsAny<SendEmailRequest>()), Times.Exactly(2)); Assert.That(request.Count, Is.EqualTo(2)); Assert.That(request.First().Destination.ToAddresses.Count, Is.EqualTo(50)); Assert.That(request.Skip(1).First().Destination.ToAddresses.Count, Is.EqualTo(1)); }
public void Send_GivenSingleTo_SendSingleEmail() { var senderMock = new Mock<IEmailSender>(); var service = new Portal.EmailService.EmailService(senderMock.Object); const string to = "*****@*****.**"; const string from = "*****@*****.**"; const string subject = "Test Email"; const string body = "<div>Hallo test</div>"; SendEmailRequest request = null; senderMock.Setup(s => s.Send(It.IsAny<SendEmailRequest>())).Callback<SendEmailRequest>(r => request = r); service.Send(from, to, subject, body); senderMock.Verify( s => s.Send(It.IsAny<SendEmailRequest>()), Times.Once()); Assert.That(request, Is.Not.Null); Assert.That(request.Source, Is.EqualTo(from)); Assert.That(request.Destination.ToAddresses, Is.Not.Null); Assert.That(request.Destination.ToAddresses.Count, Is.EqualTo(1)); Assert.That(request.Destination.ToAddresses.First(), Is.EqualTo(to)); Assert.That(request.Message.Subject.Data, Is.EqualTo(subject)); Assert.That(request.Message.Body.Html.Data, Is.EqualTo(body)); }