【发布时间】:2017-06-01 06:30:32
【问题描述】:
我得到了
在 *****Tests.dll 中发生了“System.NullReferenceException”类型的异常,但未在用户代码中处理
附加信息:对象引用未设置为对象的实例。
如何正确地为绑定模型赋值?
public class PersonRegistration
{
RegisterBindingModel model;
[TestMethod]
public void TestMethod1()
{
AccountController ac = new AccountController(userManager, loggingService);
model.UserName = "test123@gmail.com";
var result = ac.Register(model);
Assert.AreEqual("User Registered Successfully", result);
}
执行model.UserName = "test123@gmail.com";时出现异常
public class RegisterBindingModel
{
public RegisterBindingModel();
[Display(Name = "User name")]
[Required]
public string UserName { get; set; }
}
【问题讨论】:
-
除非有必要,否则您通常不会测试控制器。
标签: c# asp.net-mvc model-binding custom-binding custom-model-binder