Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Unit Testing Page Model Throws Null Ref On ModelState check #6943

Closed
@scottsauber

Description

While testing Razor Pages, when I create a new PageModel, it throws a null reference exception when doing the ModelState.IsValid check. The NRE is on ModelState itself.

This seems to be a change from the way MVC's ModelState "just worked" when newing up the controller.

For instance (some Arrange code removed for brevity)...

In MVC:

var controller = new AccountController(dependency1, dependency2);
var result = await controller.Login(new LoginViewModel()));
// **Does NOT** throw NRE on ModelState.IsValid check

In Razor Pages:

var loginModel = new LoginModel(dependency1, dependency2);
var result = await loginModel.OnPostAsync();
// **DOES** throw NRE on ModelState.IsValid check, because ModelState is null.

This is bit of an annoyance.

/cc @DamianEdwards

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions