UploadedFile이라는 클래스의 기능을 테스트하는 단위 테스트를 작성하고 싶습니다.유닛 테스트에서 HttpContext를 사용할 수있게하려면 어떻게해야합니까?
이 클래스의 정적 생성자는 HttpContext.Current 속성을 사용하며 클래스 라이브러리에서 단위 테스트를 실행하기 때문에 테스트 할 때 HttpContext가 없습니다. 내 정적 생성자에서
봐 : 나는 HttpContext.Current
가 null되지 않습니다 나는이 성공적으로 설정 할 수 있도록이 내 테스트 환경에서 무엇을해야
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);
}
:
HttpServerUtility server = HttpContext.Current.Server;
아이디어를 제공해 주셔서 감사합니다. 나는 Rhino를 사용하지 않았습니다 .Mocks.dll은 지금까지 불행하게도. 먼저 익숙해 져야 할 것 같아서 제안을 구현하려고합니다. 감사! – pencilCake