我正在尝试使用Visual Studio 2005在C#中调用HttpServerUtuility.URLDecode函数,但无法找到它.我using System.Web很好,但是班级似乎并不存在.我是否需要为我的项目添加某种引用?
我想编写一个单元测试来测试一个名为UploadedFile的类的功能.
我面临的问题是这个类的静态构造函数使用HttpContext.Current属性,因为我从类库运行我的单元测试,我在测试时没有HttpContext.
看看我的静态构造函数:
static UploadedFile()
{
if (HttpContext.Current == null)
throw new Exception("web server not available");
HttpServerUtility server = HttpContext.Current.Server;
// SET UploadedFileMappingFile Names:
_resourceFileNames = new StringDictionary();
_resourceFileNames[_suppoertedFileStructures] = server.MapPath(SupportedUploadedFileStructures);
_resourceFileNames[_supportedFileStructuresXSD] = server.MapPath(SupportedUploadedFileStructuresXSD);
_resourceFileNames[UploadedFileEnum.UploadedFileFormatENUM.CSV.ToString()] = server.MapPath(UploadedFileColumnMap);
}
Run Code Online (Sandbox Code Playgroud)
我应该在我的测试环境中做什么,这样才HttpContext.Current不会为null,我可以成功设置它:
HttpServerUtility server = HttpContext.Current.Server;
Run Code Online (Sandbox Code Playgroud)