I have a class that implements IHttpHandler interface in .NET 4.7.1. The class implements ProcessRequest which accepts an HttpContext instance.

I am trying to create a test for ProcessRequest using Moq. Moq allows me to create a mock for httpContextBase but not HttpContext.

Mock<HttpContext> mockHttpContext = new Mock<HttpContext>();

Run time error:

Type to mock (HttpContext) must be an interface, a delegate, or a non-sealed, non-static class.

If I mock HttpContextBase, eventually calling the method and passing it will give an error:

Cannot convert from 'System.Web.HttpContextBase' to 'System.Web.HttpContext'

Is there a way to mock HttpContext? I can't modify the class or the method as it's not my code.

0

There are 0 best solutions below