title: How can I verify the output of this method using Moq
body: <p>I have an MVC3 app and I've got a Register ActionMethod on the AccountController. When a user registers I want it to email them their user details. I'm using <a href="http://aboutcode.net/postal/" rel="nofollow">Postal</a> (for the first time) and want to run a unit test that verifies that the Send method gets called and that I've called the Register email template.</p>
  
  <p>Here is the section of code in my Register ActionMethod that calls the email tempalte:</p>
  
  <pre><code>dynamic email = new Email("Register");
  email.To = model.Email;
  _emailService.Send(email);
  </code></pre>
  
  <p>_emailService is of type IEmailService. I'm using Moq and know how to verify a method has been called but in this instance I'm passing an Email object into Send. So I don't know if I create a Mock or whether the Email object used on the Register controller is what I should be testing. I'm also not sure on the best way to test the 'output' of the email or to at least verify that the 'Register' template in the Views/Emails folder is called. Here's my test so far:</p>
  
  <pre><code>    [TestMethod]
      public void register_post_success_sends_email_with_account_details()
      {
          // Arrange
          // fakeMembers contains a List&lt;Member&gt; repository of 5 fake Members which I 
          // use to ensure the Register completes and then steps into the code 
          // that calls the email code authentication code
          FakeMembers fakeMembers = new FakeMembers();
          _mockMemberRepository.Setup(x =&gt; x.GetMembers()).Returns(fakeMembers.Members);
          _mockEmailService.Setup(e =&gt; e.Send(?? what do I place here??));
          // set up of emailService.Send is a void method so do I just not use Returns?
  
          //// Arrange
          Member model = new Member()
          {
              Email = "member6@mydomain.com",
              Password = "test123",
              ConfirmPassword = "test123"
          };
          Mock&lt;Email&gt; mockEmail = new Mock&lt;Email&gt;();
          // Act
          var result = _controller.Register(model);
  
          // Assert
          // Do I use a mockEmail.Object here? I want to test the Email called on the 
          // Register ActionMethod?
  
          // Test Send method was called ONCE
          _mockEmailService.Verify(e =&gt; e.Send(mockEmail.Object), Times.Once());
  
          //Test either the output of the Email that was sent OR check that it was the
          //Register email template that was called
      }
  </code></pre>
  
  <p>I hope I've been concise enough and someone can help</p>