title: Global Scope for Mock HTTPContext - CloudService Project?
body: <p>I'm trying to set up a Unit Testing Framework for my WebRole project. I created a mock HTTP context and attached it to the controller that I'm trying to test as such:</p>
  
  <pre><code>var fakeHttpContext = new Mock&lt;HttpContextBase&gt;();
  var fakeIdentity = new GenericIdentity(username);
  var principal = new GenericPrincipal(fakeIdentity, null);
  
  fakeHttpContext.Setup(t =&gt; t.User).Returns(principal);
  var controllerContext = new Mock&lt;ControllerContext&gt;();
  controllerContext.Setup(t =&gt; t.HttpContext).Returns(fakeHttpContext.Object);
  
  var controller = new HomeController();
  controller.ControllerContext = controllerContext.Object;
  </code></pre>
  
  <p>My question is instead of attaching the mock context to one controller, can I mock up HTTP context for the project on a global scope, so all controller and utility classes have access to the mock HTTP context?</p>
  
  <pre><code>//Mock Context is attached to this controller. When Membership provider is accessed 
  //from inside the controller it works fine. However when Membership Provider 
  //is used from outside the Controller it returns null. 
  public void controlerMethodinHomeController()
  { 
      //Returns Null
      var userID = Utility.GetUserId();
  
      //Returns valid UserID
      var userID = Membership.GetUser(User.Identity.Name).ProviderUserKey;
  }
  
  ///Utility Class
  public static Guid GetUserId()
  {
    var user = Membership.GetUser();
    return user.ProviderUserKey
  }
  </code></pre>