I am writing a unit test for a controller like this:
public HttpResponseMessage PostLogin(LoginModel model)
{
if (!ModelState.IsValid)
return new HttpResponseMessage(HttpStatusCode.BadRequest);
}
the model looks like:
public class LoginModel
{
[Required]
public string Username { set; get; }
[Required]
public string Password { set; get; }
}
Then I have unit test like this one:
[TestMethod]
public void TestLogin_InvalidModel()
{
AccountController controller = CreateAccountController();
...
var response = controller.PostLogin(new LoginModel() { });
Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
}
Actually the ModelState is validated... which is weird for me as both fields are required...
Could anybody advise?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…