private FileStateStore GetStateStore(Action <string> onFullTempDirGenerated = null)
        {
            string tempDir = Path.GetTempPath();

            tempDir = SafeTempPath.Create(tempDir);

            var    dirMapperSvc = FakeDirectoryMapperService.Create(tempDir);
            string fullTempPath = dirMapperSvc.GetAbsolutePath(EnvDirectory.ContentRootPath);

            onFullTempDirGenerated?.Invoke(fullTempPath);

            FileStateStore store = new FileStateStore(dirMapperSvc);

            return(store);
        }
示例#2
0
        public async void Invoke_WithUseResponseFile_ResponseShouldBeAppropriate(string fileName, string expectedContentType, EnvDirectory baseDir)
        {
            string tempDir = Path.GetTempPath();
            string rootDir;

            if (baseDir == EnvDirectory.ContentRootPath)
            {
                rootDir = Path.Combine(tempDir, "contentRoot");
            }
            else
            {
                rootDir = Path.Combine(tempDir, "wwwRoot");
            }
            string safeTempFileName = SafeTempPath.Create(fileName);

            File.WriteAllText(Path.Combine(rootDir, safeTempFileName), "test");

            MiddlewareTestDesk desk = GetTestDesk(
                (httpContext) =>
            {
            },
                (optionBuilder) =>
            {
                optionBuilder.UseResponseFromFile(safeTempFileName, baseDir);
            },
                null,
                tempDir);


            await desk.MiddlewareInstance
            .Invoke(desk.CurrentHttpContext);


            desk.CurrentHttpContext.Response.StatusCode
            .ShouldBe(503);
            desk.CurrentHttpContext.Response.Headers
            .Any(h => h.Key == "Retry-After")
            .ShouldBeTrue();
            desk.CurrentHttpContext.Response.ContentType
            .ShouldBe(expectedContentType);
            GetResponseString(desk.CurrentHttpContext)
            .ShouldBe("test");
        }