title: httpcontext.current.server.mappath and unit testing
body: <p>I use asp.net mvc3/razor with dbfirst model.
  I send a confirmation email after registration that is in a xml format.
  I need to read this xml file while unit testing,
  I get null reference error as httpcontext.current is null.I tried to mock it, but again I get a error saying "value cannot be null"
  This is my code, please help:</p>
  
  <p>accountcontroller:</p>
  
  <pre><code>  Fds.ReadXml(HttpContext.Current.Server.MapPath("~/Files/ForgotPassword.xml"));
  </code></pre>
  
  <p>unit testing:</p>
  
  <pre><code> public void Saveuser()
           {
               RegisterModel model = new RegisterModel();
               FormCollection f = new FormCollection();
               List&lt;MailModel&gt; m = new List&lt;MailModel&gt;();
               HttpContext.Current = FakeHttpContext();
               m = user.GetMail().ToList();
               MailModel mmodel = new MailModel();
               mmodel = m[0];
             model.Name = "testuse11r9788";
            model.UserName = "test1user9878";
            model.Password = "1234567";
            model.ConfirmPassword = "1234567";
            model.Email = "testus11979@gmail.com";
            var controller = new AccountController(user,mail);
            var saveuser = controller.Register(model,f) as ViewResult;
            var saveActUser = (RegisterModel)saveuser.ViewData.Model;
            var saveExpUser = model;
             areuserEqual(saveExpUser, saveActUser);
           }
  
  public static HttpContext FakeHttpContext()
          {
  </code></pre>
  
  <p>//please help me what should be entered in httprequest????</p>
  
  <pre><code>  var httpRequest = new HttpRequest("", "http://localhost:mmmm/", "");
                   var stringWriter = new StringWriter();
                   var httpResponce = new HttpResponse(stringWriter);
                  var httpContext = new HttpContext(httpRequest, httpResponce);
  
              var sessionContainer = new HttpSessionStateContainer("id", new SessionStateItemCollection(),
                                                      new HttpStaticObjectsCollection(), 10, true,
                                                      HttpCookieMode.AutoDetect,
                                                      SessionStateMode.InProc, false);
  
              httpContext.Items["AspSession"] = typeof(HttpSessionState).GetConstructor(
                                          BindingFlags.NonPublic | BindingFlags.Instance,
                                          null, CallingConventions.Standard,
                                          new[] { typeof(HttpSessionStateContainer) },
                                          null)
                                  .Invoke(new object[] { sessionContainer });
  
              return httpContext;
          }
  </code></pre>