Posted By

heathbo on 07/03/14


Tagged

Moq c#


Versions (?)

Using Moq, check to see the value of passed in parameters.


 / Published in: C#
 

Were making sure the list that is passed in has 3 attachments. SendMail is run later in the SendEmail mehtod.

  1. private MockRepository repository = new MockRepository(MockBehavior.Loose);
  2. private Mock<IEmailService> mockEmailService = repository.Create<IEmailService>();
  3. private EmailUtility target = new EmailUtility(mockEmailService.Object);
  4.  
  5.  
  6. // Setup
  7. const string emailAddress = @"[email protected]";
  8. const string messageSubject = @"foo example";
  9. const string messageBody = @"foo body";
  10. const bool highPriority = true;
  11. const string fromAccount = "TestAccount";
  12.  
  13. var attachmentList = new List<Attachment>();
  14.  
  15. attachmentList.Add(new Attachment(new StreamClass(), ""));
  16. attachmentList.Add(new Attachment(new StreamClass(), ""));
  17. attachmentList.Add(new Attachment(new StreamClass(), ""));
  18.  
  19. // Action
  20. target.SendEmail(emailAddress, messageSubject, messageBody, true, fromAccount, attachmentList);
  21.  
  22. // Assert
  23. mockEmailService.Verify(x => x.SendMail(It.Is<MailMessage>(p => p.Attachments.Count() == 3), It.IsAny<bool>()));

Report this snippet  

You need to login to post a comment.