1

I'm writing a unit test for a controller in .Net Framework 4.5.2 but I'm getting a NullReferenceException when this line is hit:

return RedirectToAction<MyController>(action => action.Edit(itemId), "Something");

However, when I change it (and nothing else) to

return RedirectToAction("Edit", "Something", new { myId = itemId });

it works perfectly.

Any ideas why this would be?

Astrum97
  • 11
  • 1

1 Answers1

1

Dependency injection configured in your project? That might be the reason.

For Unit test try to inject HttpContext in a mock controller object. Sample code is available here: https://stackoverflow.com/a/2497618/218408

Rahatur
  • 3,147
  • 3
  • 33
  • 49