Error using MVCContrib TestHelper

When I try to execute the second answer to the previous question , I get an error message.

I implemented the methods, as the message shows, and the first three work correctly. The fourth (HomeController_Delete_Action_Handler_Should_Redirect_If_Model_Successfully_Delete) gives this error: Could not find a parameter named "controller" in the collection of values.

If I changed the code to:

actual 
    .AssertActionRedirect() 
    .ToAction("Index");

it works correctly, but I don't like the magic string and prefers to use the lambda method that another poster used.

My controller method is as follows:

    [HttpPost]
    public ActionResult Delete(State model)
    {
        try
        {
            if( model == null )
            {
                return View( model );
            }

            _stateService.Delete( model );

            return RedirectToAction("Index");
        }
        catch
        {
            return View( model );
        }
    }

What am I doing wrong?

+3
1

MVCContrib.TestHelper , Delete:

return RedirectToAction("Index", "Home");

:

actual
    .AssertActionRedirect()
    .ToAction<HomeController>(c => c.Index());

- ToActionCustom:

public static class TestHelperExtensions
{
    public static RedirectToRouteResult ToActionCustom<TController>(
        this RedirectToRouteResult result, 
        Expression<Action<TController>> action
    ) where TController : IController
    {
        var body = (MethodCallExpression)action.Body;
        var name = body.Method.Name;
        return result.ToAction(name);
    }
}

:

return RedirectToAction("Index");

:

actual
    .AssertActionRedirect()
    .ToActionCustom<HomeController>(c => c.Index());
+9

Source: https://habr.com/ru/post/1748591/


All Articles