title: ActionMailer FakeHttpContext
body: <p>I'm trying to create Unit Test for code that using ActionMailer, after I wrote the test I got System.ArgumentNullException error for httpContext parameter.</p>
  
  <p><strong>MailController.cs</strong>:</p>
  
  <pre><code>new Mailer().Welcome(new WelcomeModel
  {
      Name = "sss",
      Email = model.Email
  }).Deliver();
  </code></pre>
  
  <p><strong>MailControllerTest.cs</strong>:</p>
  
  <pre><code>var model = new WelcomeInputModel{ Email = "dsadsa@gmail.com" };
  var result = _controller.SendMail(model);
  Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
  </code></pre>
  
  <p>What should to do?</p>
  
  <p><strong>UPDATE</strong>, I updated my code:</p>
  
  <p><strong>MailControllerTest.cs</strong>:</p>
  
  <pre><code>var request = new Mock&lt;HttpRequestBase&gt;();
  request.Setup(r =&gt; r.HttpMethod).Returns("GET");
  _mockHttoContextBase.Setup(c =&gt; c.Request).Returns(request.Object);
  </code></pre>
  
  <p><strong>MailController.cs</strong>:</p>
  
  <pre><code>var controller = new MailController {HttpContextBase = _contextBase};
  controller.Forgot(new ForgotModel
  {
      UserName = membershipUser.UserName, 
      Email = user.Email, 
      Password = membershipUser.ResetPassword()
  }).Deliver();
  </code></pre>
  
  <p>Now the error that I getting is:
  System.NullReferenceException: Object reference not set to an instance of an object.</p>