Mocking HttpContext when testing IActionFilters in MVC

While trying to figure out how to make a full featured implementation of ContextMock builder based solely on Moq in order to make unit tests for an implementation of IActionFilter I stumbled upon a problem :

System.NotSupportedException Invalid setup on a non-virtual (overridable in VB) member: x => x.Values

Then I read some Q&A on stackoverflow here and here and some others in which in summary is stated that :

Moq cannot mock non-virtual methods and sealed classes.

I really wanted to keep using Mock<T> mainly because

  1. it matches nicely with builder pattern which I like to use for unit testing harness.
  2. it has Verify methods which is great for the “assert” section of the unit test.

But because I did not manage to get it through I made another implementation based on .NET classes rather then Mock<.Net classes>. The implementation is suitable for extension and serves the needs for “arranging” the HttpContext for the unit test of the IActionFilter. So here it is :