title: ASP .Net MVC 3: Unit testing controller actions
body: <p>I am quite new to Unit testing and Mock concepts. I am trying to figure out how to write a good test case for the basic out-of-the box user registration code below:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Register(RegisterModel model)
  {
      if (ModelState.IsValid)
      {
          // Attempt to register the user
          MembershipCreateStatus createStatus;
          Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
  
          if (createStatus == MembershipCreateStatus.Success)
          {
              FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
              return RedirectToAction("Index", "Home");
          }
          else
          {
              ModelState.AddModelError("", ErrorCodeToString(createStatus));
          }
      }
  
      // If we got this far, something failed, redisplay form
      return View(model);
  }
  </code></pre>
  
  <p>Below are some of the specific points where I need your opinion/help:</p>
  
  <ol>
  <li>I do not necessarily want to create a new user in ASP .Net membership database.</li>
  <li>Based on the <strong>model</strong> passed in, how do I really make sure that if the user was successfully registered or there were errors in the process.</li>
  </ol>