Esempio n. 1
0
        public async Task TestCacheWriteDelegatingHandler_FileExtension_ReflectsMediaType()
        {
            var handler = new TestCacheWriteDelegatingHandler(ResponseFilesPath);

            handler.InnerHandler = new FakeHttpResponseHandler();

            var request = new HttpRequestMessage(HttpMethod.Get, "https://services.odata.org/$metadata");

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
            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, "services.odata.org", "metadata.xml")).Should().BeTrue();
        }
Esempio n. 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();
        }