I've written two extension methods for getting IP / Browser from current HttpRequest:
public static class Extensions
{
public static string IP (this HttpRequest currentRequest)
{
string ips = currentRequest.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ips))
{
return ips.Split(',')[0];
}
return currentRequest.ServerVariables["REMOTE_ADDR"];
}
public static string Browser (this HttpRequest currentRequest)
{
return currentRequest.Browser.Type;
}
}
I would like to unit test both methods. I've seen answers how to mock http request like this and this. But I can not mock IP and Browser from HttpRequest. Any ideas ?