title: How can I mock Server.HtmlEncode
body: <p>I am trying the following, but I am getting : Object reference not set to an instance of an object.</p>
  
  <pre><code> HttpContextBase mockContext = MockRepository.GenerateMock&lt;HttpContextBase&gt;();
  
   mockContext.Expect(c =&gt; c.Server.HtmlEncode("")).IgnoreArguments().Return("");
   mockContext.Expect(c =&gt; c.Server.HtmlDecode("")).Return("");
  
   controller.ControllerContext = 
      new ControllerContext(mockContext, new RouteData(), controller);
  </code></pre>
  
  <p>Matin,</p>
  
  <p>Thanks.  That was enough to point me in the right direction provided here:</p>
  
  <pre><code>var mockContext = MockRepository.GenerateMock&lt;HttpContextBase&gt;();       
  var mockServer = MockRepository.GenerateMock&lt;HttpServerUtilityBase&gt;();
  
  mockServer.Expect(s =&gt; s.HtmlEncode(""))
      .IgnoreArguments()
      .Repeat.AtLeastOnce()
      .Return("");
  
  mockContext.Expect(c =&gt; c.Server)
      .IgnoreArguments()
      .Repeat.AtLeastOnce()
      .Return(mockServer);
  
  controller.ControllerContext = 
      new ControllerContext(mockContext, new RouteData(), controller);
  </code></pre>