I am unit testing controller actions, so I have set up a fake httpContext that includes a fake session as a dictionary that I can populate.
However, as part of some refactoring, code in the constructor now calls into the session before I can populate the fake Session.
Is there a way to populate the base controller’s Session object before the derived controller ctor runs and throws a NullReferenceException? Or will this code in the ctor need changing?
I have changed the code in the ctor to use an
ISomeServicethat calls the code that access the Session, this is easily fake-able.As per @dnaack’s comment, the concrete type can be injected in.