Examples
Here are some other random examples of assertions that you can make (see the documentation for the full list):
var vm = new SomeViewModel();
_controller.WithModelErrors().WithCallTo(c => c.Index(vm))
.ShouldRenderDefaultView()
.WithModel(vm);
_controller.WithCallTo(c => c.Index())
.ShouldRenderDefaultView()
.WithModel<ModelType>()
.AndModelErrorFor(m => m.Property1).ThatEquals("The error message.")
.AndModelErrorFor(m => m.Property2);
_controller.WithCallTo(c => c.Index())
.ShouldRenderView("ViewName");
_controller.WithCallTo(c => c.Index())
.ShouldReturnEmptyResult();
_controller.WithCallTo(c => c.Index())
.ShouldRedirectTo("http://www.google.com.au/");
_controller.WithCallTo(c => c.ActionWithRedirectToAction())
.ShouldRedirectTo(c => c.ActionInSameController);
_controller.WithCallTo(c => c.Index())
.ShouldRedirectTo<SomeOtherController>(c => c.SomeAction());
_controller.WithCallTo(c => c.Index())
.ShouldRenderAnyFile("content/type");
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileContents("text");
_controller.WithCallTo(c => c.Index())
.ShouldReturnContent("expected content");
_controller.WithCallTo(c => c.Index())
.ShouldGiveHttpStatus(404);
_controller.WithCallTo(c => c.Index()).ShouldReturnJson(data =>
{
Assert.That(data.SomeProperty, Is.EqualTo("SomeValue");
});
A real-world example can be seen in the AndTakeUserToASuccessPage
method of the SuccessfulTeamResetPasswordScenario
code snippet shown in one of Rob's blog posts.
Updated less than a minute ago