title: Testing a custom user profile for use with ASP Membership
body: <p>I've just finished implementing a basic asp membership into my MVC project and I'm looking to write some tests. I had some initial problems with mocking the provider but now that is sorted. Obviously as the provider is mocked no data is in there nor can you add any data but the profile's cannot be directly mocked as they are created every time a user profile is required. I'm not sure how to approach testing these as (obviously) when a profile is called it returns null.</p>
  
  <p>For example:</p>
  
  <p>Using DI my repository is injected:</p>
  
  <pre><code>    public AccountMembershipService(MembershipProvider provider)
      {
          _provider = provider ?? Membership.Provider;
  
      }
  </code></pre>
  
  <p>And lets take for example, the create user method</p>
  
  <pre><code>    public MembershipCreateStatus CreateUser(string userName, string password, string email, string passwordQuestion, string passwordAnswer)
      {
          if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
          if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");
          if (String.IsNullOrEmpty(email)) throw new ArgumentException("Value cannot be null or empty.", "email");
  
          MembershipCreateStatus status;
          _provider.CreateUser(userName, password, email, passwordQuestion, passwordAnswer, true, null, out status);
  
          if (status == MembershipCreateStatus.Success)
          {
              UserProfile profile = UserProfile.GetProfile(userName);
              profile.IPAddress = "0.0.0.0";
              profile.Save();
          }
          return status;
      }
  </code></pre>
  
  <p>The .CreateUser works perfectly (As far as mocking is concerned) but when it comes to GetProfile obviously there is no profile in existence so it just errors. Any ideas on how I might be able to approach testing this?</p>
  
  <p>I've been staring at this for a good couple of hours now, any help would be REALLY appreciated!!</p>