public void GetStaticFilePath_CanParse_Uris(string mediaType, string directoryPath, string fileName, string requestUri)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, requestUri);

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(mediaType));
            var(DirectoryPath, FilePath) = TestCacheDelegatingHandlerBase.GetPathInfo(request, ResponseFilesPath);
            Path.GetFileName(FilePath).IndexOfAny(Path.GetInvalidFileNameChars()).Should().BeLessThan(0);
            DirectoryPath.Should().Be(directoryPath);
            FilePath.Should().Be($"{fileName}{TestCacheDelegatingHandlerBase.GetFileExtensionString(request)}");
        }
示例#2
0
        public async Task TestCacheWriteDelegatingHandler_CanWriteFile(string mediaType, string directoryPath, string fileName, string requestUri)
        {
            var handler = new TestCacheWriteDelegatingHandler(ResponseFilesPath);

            handler.InnerHandler = new FakeHttpResponseHandler();

            var request = new HttpRequestMessage(HttpMethod.Get, requestUri);

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(mediaType));
            var response = await handler.SendAsyncInternal(request);

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var content = await response.Content.ReadAsStringAsync();

            content.Should().NotBeNullOrEmpty();

            File.Exists(Path.Combine(ResponseFilesPath, directoryPath, $"{fileName}{TestCacheDelegatingHandlerBase.GetFileExtensionString(request)}")).Should().BeTrue();
        }