You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe your issue
I have a CMS system which by default every controller gets static content. Some sites need more additional data hence it derives from the BaseApiController and overrides the default behavior so as to include relevant data.
The way it works is that using ControllerContext.ActionDescriptor.ControllerName, we can get the name of the page controller we are at, this works when when the class overrides the default method. But in method where it is not overridden, rather inherited. The value is not up to date only in tests.
Expected behavior ControllerContext.ActionDescriptor.ControllerName to have derived controller name.
Now, the code
[ApiController][Route("[controller]")]publicclassBaseApiController:ControllerBase{publicvirtualasyncTask<ActionResult<MainLayout>>Index([FromBody]Sessionsession=null){return HandleResult(awaitGetContent<MainLayout>(IDMembership: session?.IDMembership));}}publicclassAboutUsController:BaseApiController//not working in tests, but works in browser{}publicclassReviewsController:BaseApiController//works in tests, and in the browser{[HttpGet()]publicoverrideasyncTask<ActionResult<MainLayout>>Index([FromBody]Sessionsession=null){returnnew ReviewsDTO;//some DTO derived from MainLayout}}
Tests
[Collection("Test")]publicclassStaticPages{[Fact]publicvoidAbout()//but will work for Reviews{MyController<AboutUsController>.Instance().Calling(x => x.Index(null)).ShouldReturn().Ok(x =>{ x.ShouldPassForThe<MainLayout>(x => x.ParagraphTop.Contains("<h1>About Us</h1>"));});}}
Describe your issue
I have a CMS system which by default every controller gets static content. Some sites need more additional data hence it derives from the
BaseApiController
and overrides the default behavior so as to include relevant data.The way it works is that using
ControllerContext.ActionDescriptor.ControllerName
, we can get the name of the page controller we are at, this works when when the class overrides the default method. But in method where it is not overridden, rather inherited. The value is not up to date only in tests.Expected behavior
ControllerContext.ActionDescriptor.ControllerName
to have derived controller name.Now, the code
Environment:
The text was updated successfully, but these errors were encountered: