MyTested.AspNetCore.Mvc icon indicating copy to clipboard operation
MyTested.AspNetCore.Mvc copied to clipboard

Separate the route and pipeline testing and their action invoking

Open ivaylokenov opened this issue 6 years ago • 0 comments

Route tests should not execute the action and its action filters. A route test should only assert whether ASP.NET Core has the correct mapping of the URL and whether the model binding is working.

A pipeline test should execute both the action and its action filters - the whole MVC pipeline.

This breaking change is required because currently, the route tests mock the actual action call for performance reasons but action filters may need the actual data but unfortunately, they receive mocks, which leads to unexpected behavior.

// Does not execute action and action filters by default.
MyRouting
    .Configuration()
    .ShouldMap("/My/Action/5")
    .To<MyController>(c => c.Action(5));
// Executes action and action filters by default.
MyPipeline
    .Configuration()
    .ShouldMap("/My/Action/5")
    .To<MyController>(c => c.Action(5));

Optional methods should be provided - WithActionExecution and WithoutActionExecution for overriding the default behaviour.

ivaylokenov avatar Dec 04 '19 06:12 ivaylokenov