I am mocking an HttpRequest object using Moq for unit testing in ASP.NET MVC. I need to set one of the ServerVariables (LOGON_USER) in the request. Is this possible? I have tried using the following method, but I get an exception because the ServerVariables collection is non-overridable.
request.SetupGet(req => req.ServerVariables["LOGON_USER"]).Returns(@"TestUserName");
Is is possible to set a ServerVariable value for testing?
Do I need to pass in a new NameValueCollection rather than trying to set one specific key?