我们如何在Code下编写单元测试?任何人都可以帮助我解决这个问题

时间:2014-10-16 11:06:36

标签: asp.net mocking asp.net-identity

    private ApplicationSignInManager _signInManager;
    private ApplicationUserManager _userManager;

    public AccountController()
    {
    }

    public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager)
    {
        UserManager = userManager;
        SignInManager = signInManager;
    }

    public ApplicationSignInManager SignInManager
    {
        get
        {
            return _signInManager ?? HttpContext.GetOwinContext().Get<ApplicationSignInManager>();
        }
        private set
        {
            _signInManager = value;
        }
    }

    public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
    {
      var result = await SignInManager.PasswordSignInAsync
      (model.Email, model.Password, model.RememberMe, shouldLockout: false);
        switch (result)
        {
            case SignInStatus.Success:
                return RedirectToLocal(returnUrl);

            case SignInStatus.LockedOut:
                return View("Lockout");

            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return View(model);
        }
    }

1 个答案:

答案 0 :(得分:-1)

使用像MOQ这样的模拟框架。模拟SignInManager。为每个案例写一个单元测试。