Created
June 6, 2013 13:12
-
-
Save bitsprint/5721384 to your computer and use it in GitHub Desktop.
Controller Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Test] | |
| public void ActionReturnsRedirectToRouteResult() | |
| { | |
| var result = this.controller.Action(); | |
| Assert.That(result, Is.TypeOf<RedirectToRouteResult>()); | |
| var routeResult = (RedirectToRouteResult)result; | |
| Assert.That(routeResult.RouteValues["area"], Is.EqualTo(string.Empty)); | |
| Assert.That(routeResult.RouteValues["action"], Is.EqualTo("Index")); | |
| Assert.That(routeResult.RouteValues["controller"], Is.EqualTo("Home")); | |
| } | |
| [Test] | |
| public void WhenRegularRequestShouldReturnCorrectViewAndModel() | |
| { | |
| var result = this.controller.Action(); | |
| Assert.That(result, Is.TypeOf<ViewResult>()); | |
| Assert.That(((ViewResult)result).ViewName, Is.EqualTo("Foo")); | |
| Assert.That(((ViewResult)result).Model, Is.TypeOf<FooViewModel>()); | |
| } | |
| [Test] | |
| public void WhenAjaxRequestShouldReturnCorrectPartialViewAndModel() | |
| { | |
| var result = this.controller.MakeAjax().Action(); | |
| Assert.That(result, Is.TypeOf<PartialViewResult>()); | |
| Assert.That(((PartialViewResult)result).ViewName, Is.EqualTo("_Foo")); | |
| Assert.That(((ViewResult)result).Model, Is.TypeOf<FooViewModel>()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment