/// <summary> /// Shoulds the return head. /// <example> /// <code> /// [TestClass] /// public class UserControllerRedirectsTest /// { /// [TestMethod] /// public void NewReturnsItself() /// { /// GivenController.As<UserController>() /// .ShouldRenderItself("New") /// .WhenCalling(x => x.New()); /// } /// </code> /// </example> /// </summary> /// <param name="fluentAction"></param> /// <param name="statusCode">The status code.</param> /// <returns></returns> public static ActionExpectations <T> ShouldReturnHead <T>(this ActionExpectations <T> fluentAction, HttpStatusCode statusCode) where T : ControllerBase, new() { return (fluentAction.Should( actionResult => actionResult.AssertResultIs <HeadResult>().StatusCode.ShouldBe(statusCode))); }
/// <summary> /// Shoulds the render partial. /// <example> /// <code> /// [TestClass] /// public class UserControllerRedirectsTest /// { /// [TestMethod] /// public void EditReturnsPartialAddress() /// { /// GivenController.As<UserController>() /// .ShouldRenderPartial("Address") /// .WhenCalling(x => x.Edit()); /// } /// </code> /// </example> /// </summary> /// <param name="fluentAction"></param> /// <param name="partialViewName">Partial name of the view.</param> /// <returns></returns> public static ActionExpectations <T> ShouldRenderPartial <T>( this ActionExpectations <T> fluentAction, string partialViewName) where T : ControllerBase, new() { return (fluentAction.Should( actionResult => actionResult.AssertResultIs <PartialViewResult>().ForView(partialViewName))); }
/// <summary> /// Shoulds the return file. /// <example> /// <code> /// [TestClass] /// public class UserControllerRedirectsTest /// { /// [TestMethod] /// public void NewReturnsItself() /// { /// GivenController.As<UserController>() /// .ShouldReturnFile("C:\person.jpg") /// .WhenCalling(x => x.ShowImage()); /// } /// </code> /// </example> /// </summary> /// <param name="fluentAction"></param> /// <param name="fileDownloadName">Name of the file download.</param> /// <returns></returns> public static ActionExpectations <T> ShouldReturnFile <T>(this ActionExpectations <T> fluentAction, string fileDownloadName) where T : ControllerBase, new() { return (fluentAction.Should( actionResult => actionResult.AssertResultIs <FileResult>().FileDownloadName.ShouldBe(fileDownloadName))); }
/// <summary> /// Shoulds the redirect to. /// <example> /// <code> /// [TestClass] /// public class UserControllerRedirectsTest /// { /// [TestMethod] /// public void SuccessfulCreateRedirectsToIndexActionOfHomeController() /// { /// GivenController.As<UserController>() /// .ShouldRedirectTo("Home", "Index") /// .IfCallSucceeds() /// .WhenCalling(x => x.Create(null)); /// } /// </code> /// </example> /// </summary> /// <param name="fluentAction"></param> /// <param name="controller">The controller of the action.</param> /// <param name="action">The action.</param> /// <returns></returns> public static ActionExpectations <T> ShouldRedirectTo <T>(this ActionExpectations <T> fluentAction, string controller, string action) where T : ControllerBase, new() { return(fluentAction.Should( actionResult => actionResult.AssertActionRedirect().ToAction(action).ToController(controller) )); }
/// <summary> /// Shoulds the return empty. /// <example> /// <code> /// [TestClass] /// public class UserControllerRedirectsTest /// { /// [TestMethod] /// public void SaveToWatchListShouldReturnEmptyResult() /// { /// GivenController.As<UserController>() /// .ShouldReturnEmpty() /// .WhenCalling(x => x.SaveToWatchList()); /// } /// </code> /// </example> /// </summary> /// <returns></returns> public static ActionExpectations <T> ShouldReturnEmpty <T>(this ActionExpectations <T> fluentAction) where T : ControllerBase, new() { return(fluentAction.Should(actionResult => { if (actionResult == null) { return; } actionResult.AssertResultIs <EmptyResult>(); })); }
/// <summary> /// Shoulds the render itself. /// <example> /// <code> /// [TestClass] /// public class UserControllerRedirectsTest /// { /// [TestMethod] /// public void NewReturnsItself() /// { /// GivenController.As<UserController>() /// .ShouldRenderItself("New") /// .WhenCalling(x => x.New()); /// } /// </code> /// </example> /// </summary> /// <param name="fluentAction"></param> /// <param name="actionName">Name of the action.</param> /// <returns></returns> public static ActionExpectations <T> ShouldRenderItself <T>( this ActionExpectations <T> fluentAction, string actionName) where T : ControllerBase, new() { return(fluentAction.Should(actionResult => actionResult.AssertViewRendered().ForViewOrItself(actionName))); }