Umbraco Testing - RenderController
# help-with-umbraco
i
Hi all, I'm new to Umbraco testing and I'm struggling a bit with how to properly test RenderControllers. I've read the very simple example Umbraco provides here: https://docs.umbraco.com/umbraco-cms/13.latest/implementation/unit-testing#testing-a-rendercontroller In some of our RenderControllers, we use CurrentPage in the Index() method to get a reference to the page and from there we perform some custom logic. Is there any way to mock the CurrentPage properly? A controller could look like this:
Copy code
public class TestRenderController : RenderController
    {
        public TestRenderController(
                ILogger<TestRenderController> logger,
                ICompositeViewEngine compositeViewEngine,
                IUmbracoContextAccessor umbracoContextAccessor)
                : base(logger,
                        compositeViewEngine,
                        umbracoContextAccessor)
        {
        }

        [HttpGet]
        public override IActionResult Index()
        {
            var redirectPage = (CurrentPage as MyModel)?.CustomPageRedirect;
            if (redirectPage != null)
                return Redirect(redirectPage.Url());
            return NotFound();
        }
    }