title: How should register my System.Web.Security.Membership to avoid this issue in the unit test of an API controller?
body: <p>I created a unit test to a log in a user, using an api controller and the membership is checking the user that is in my Dto using this line of code.</p>
  
  <pre><code>  MembershipUser membershipUser = System.Web.Security.Membership.GetUser(Username);
  </code></pre>
  
  <p>On the web application this is working well, but on the test project and my unit test I am having this exception.</p>
  
  <blockquote>
    <p>Access to the path 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\App_Data' is denied.</p>
  </blockquote>
  
  <p>How should register my System.Web.Security.Membership to avoid this issue in the unit test?</p>
  
  <p>My test method looks like this:</p>
  
  <pre><code>  [TestMethod]
    public void LoginSuccessfullyAnUser()
    {
        //Arrange
        var controller = new TokensController(unitOfWork, unitOfWorkMembership, configManager);
        var credentials = new LoginUserDTO
                               { 
                                   Username = "user1", 
                                   Password = "12345678" 
                                };
  
        controller.Request = new HttpRequestMessage 
        {
             RequestUri = new Uri("http://localhost/api/tokens")
        };
  
        controller.Configuration = new HttpConfiguration();
        controller.Configuration.Routes.MapHttpRoute(name: "DefaultApi", 
                                           routeTemplate: "api/{controller}/{id}",
                                           defaults: new { id = RouteParameter.Optional });
  
        controller.RequestContext.RouteData = new HttpRouteData(route: new HttpRoute(),
                                                               values: new HttpRouteValueDictionary 
                                                                              { 
                                                                                { "controller", "tokens" } 
                                                                              });
  
        //Act
        var response = controller.Post(credentials);
  
        //Assert
        Assert.IsNotNull(response);
  }
  </code></pre>