locked
Issue in adding HttpContext.Current.Request.ServerVariables.Add() method from NUnit project RRS feed

  • Question

  •  

    i am working in an NUnit testing project.i need to test a method in another project from my nunit project. That original method contains a line

    "string result =HttpContext.Current.Request.ServerVariables["HTTP_HOST"].ToString()."

    To handle this i Created HttpContext object using the following the code piece in the Nunit project.

    "HttpContext.Current = new HttpContext(new HttpRequest(null, url, null), new HttpResponse(null));"

    And i added the server variables using

    "HttpContext.Current.Request.ServerVariables.Add(string key,string value)" method.But this code piece producing an error "Operation not supported in this

    platform{" at run time. But if i need to add cookies using the method 'HttpContext.Current.Request.Cookies.add()' it is working fine and no

    problem happening.So what is the exact issue when adding server variables and headers. Could you please provide a fix for this issue..

    Tuesday, November 20, 2012 11:27 AM