asp.net - 为 ASP.NET MVC Identity 编写单元测试
问题描述
我的客户控制器如下所示:
public class CustomersController : Controller
{
private ApplicationUserManager _userManager;
public CustomersController()
{
}
public CustomersController(ApplicationUserManager userManager)
{
UserManager = userManager;
}
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
...
}
如何编写创建用户的单元测试?UserManager
UnitTesting 方面缺少类。
[TestClass]
public class StoreUnitTest
{
[TestMethod]
public void CreateUserTest()
{
User user = new User()
{
FirstName = "Bill",
LastName = "Gates",
UserName = "billg@microsoft.com",
LoweredUserName = "billg@microsoft.com",
Email = "billg@microsoft.com",
LoweredEmail = "billg@microsoft.com"
};
// UserManager is missing!
IdentityResult result = UserManager.Create(user, "password");
Assert.IsTrue(result.Succeeded);
}
}
解决方案
推荐阅读
- python-3.x - 以下代码片段的高效实现
- android - LiveData、MutableLiveData 之间的区别
- android - 什么是在 Android Studio 中指示 AGPBI 错误?
- dialogflow-es - 使用 api 上传意图时无法从用户短语中提取实体
- hyperledger-composer - 使用查询功能如何获取资产总量?
- javascript - Angular 6反应形式输入值到大写
- php - 在自定义表中保存 WooCommerce 订单详细信息
- python - 如何通过唯一的rowID组合两个数据框,一个比另一个具有更少的值
- python - 如何在 scikit learn predict 中添加 none 选项
- java - Eclipse Formatter 在代码块之间添加空行