/// <summary>
 /// If the call succeeds.
 /// <example>
 /// <code>
 ///    [TestClass]
 ///    public class UserControllerRedirectsTest
 ///    {
 ///        [TestMethod]
 ///        public void SuccessfulCreateRedirectsToIndex()
 ///        {
 ///            GivenController.As&lt;UserController>
 ///                .ShouldRedirectTo("Index")
 ///                .IfCallSucceeds()
 ///                .WhenCalling(x => x.Create(null));
 ///        }
 /// </code>
 /// </example>
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <param name="action"></param>
 /// <param name="model">The model.</param>
 /// <returns></returns>
 public static ActionExpectations <T> IfCallSucceeds <T, TResult>(this ActionExpectations <T> action, TResult model)
     where T : AbstractFluentController, new()
 {
     ModelStateHelper.SetModelStateValid(action);
     action.MockController.ViewData.Model = model;
     return(action);
 }
 /// <summary>
 /// Shoulds the return head.
 /// <example>
 /// <code>
 ///    [TestClass]
 ///    public class UserControllerRedirectsTest
 ///    {
 ///        [TestMethod]
 ///        public void NewReturnsItself()
 ///        {
 ///            GivenController.As&lt;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&lt;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&lt;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)));
 }
Example #5
0
 /// <summary>
 /// Shoulds the redirect to.
 /// <example>
 /// <code>
 ///    [TestClass]
 ///    public class UserControllerRedirectsTest
 ///    {
 ///        [TestMethod]
 ///        public void SuccessfulCreateRedirectsToIndexActionOfHomeController()
 ///        {
 ///            GivenController.As&lt;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&lt;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>();
     }));
 }
Example #7
0
 /// <summary>
 /// Shoulds the redirect to.
 /// <example>
 /// <code>
 ///    [TestClass]
 ///    public class UserControllerRedirectsTest
 ///    {
 ///        [TestMethod]
 ///        public void SuccessfulCreateRedirectsToIndexActionOfHomeController()
 ///        {
 ///            Controller&lt;UserController>
 ///                .ShouldRedirectTo("Home", "Index")
 ///                .IfCallSucceeds()
 ///                .WhenCalling(x => x.Create(null));
 ///        }
 /// </code>
 /// </example>
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="fluentAction">The fluent action.</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,
                                                           RestfulAction action)
     where T : ControllerBase, new()
 {
     return(fluentAction.ShouldRedirectTo(controller, action.ToString()));
 }
 /// <summary>
 /// If the call fails.
 /// <example>
 /// <code>
 ///    [TestClass]
 ///    public class UserControllerRedirectsTest
 ///    {
 ///        [TestMethod]
 ///        public void SuccessfulCreateRedirectsToIndex()
 ///        {
 ///            GivenController.As&lt;UserController>
 ///                .ShouldRedirectTo("Index")
 ///                .IfCallFails()
 ///                .WhenCalling(x => x.Create(null));
 ///        }
 /// </code>
 /// </example>
 /// </summary>
 /// <returns></returns>
 public static ActionExpectations <T> IfCallFails <T>(this ActionExpectations <T> action)
     where T : AbstractFluentController, new()
 {
     ModelStateHelper.SetModelStateInvalid(action);
     return(action);
 }
 /// <summary>
 /// Ifs the call succeeds.
 /// <example>
 /// <code>
 ///    [TestClass]
 ///    public class UserControllerRedirectsTest
 ///    {
 ///        [TestMethod]
 ///        public void SuccessfulCreateRedirectsToIndex()
 ///        {
 ///            GivenController.As&lt;UserController>
 ///                .ShouldRedirectTo("Index")
 ///                .IfCallSucceeds()
 ///                .WhenCalling(x => x.Create(null));
 ///        }
 /// </code>
 /// </example>
 /// </summary>
 /// <returns></returns>
 public static ActionExpectations <T> IfCallSucceeds <T>(this ActionExpectations <T> action)
     where T : AbstractFluentController, new()
 {
     return(IfCallSucceeds <T, object>(action, null));
 }
 public static void SetModelStateValid <T>(ActionExpectations <T> action)
     where T : Controller, new()
 {
     action.MockController.ViewData.ModelState.Clear();
 }
 public static void SetModelStateInvalid <T>(ActionExpectations <T> action)
     where T : Controller, new()
 {
     action.MockController.ViewData.ModelState.AddModelError("Test Error", "Error message");
 }
 /// <summary>
 /// Shoulds the render itself.
 /// <example>
 /// <code>
 ///    [TestClass]
 ///    public class UserControllerRedirectsTest
 ///    {
 ///        [TestMethod]
 ///        public void NewReturnsItself()
 ///        {
 ///            Controller&lt;UserController>
 ///                .ShouldRenderItself("New")
 ///                .WhenCalling(x => x.New());
 ///        }
 /// </code>
 /// </example>
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="fluentAction">The fluent action.</param>
 /// <param name="action">The action.</param>
 /// <returns></returns>
 public static ActionExpectations <T> ShouldRenderItself <T>(this ActionExpectations <T> fluentAction,
                                                             RestfulAction action)
     where T : ControllerBase, new()
 {
     return(fluentAction.ShouldRenderItself(action.ToString()));
 }
 /// <summary>
 /// Shoulds the render itself.
 /// <example>
 /// <code>
 ///    [TestClass]
 ///    public class UserControllerRedirectsTest
 ///    {
 ///        [TestMethod]
 ///        public void NewReturnsItself()
 ///        {
 ///            GivenController.As&lt;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)));
 }