public ConvertRequest_DoesLazyGetBufferlessInputStream_TestResults ConvertRequest_DoesLazyGetBufferlessInputStream()
        {
            bool inputStreamCalled = false;

            HttpRequestBase stubRequest = HttpControllerHandlerTest.CreateStubRequestBase(() =>
            {
                inputStreamCalled = true;
                return new MemoryStream();
            },
            buffered: false);
            HttpContextBase context = HttpControllerHandlerTest.CreateStubContextBase(request: stubRequest, items: null);

            GlobalConfiguration.Configuration.Services.Replace(typeof(IHostBufferPolicySelector), new BufferOutputOnlyPolicySelector());
            HttpRequestMessage actualRequest = HttpControllerHandler.ConvertRequest(context);

            ConvertRequest_DoesLazyGetBufferlessInputStream_TestResults results = new ConvertRequest_DoesLazyGetBufferlessInputStream_TestResults();
            results.inputStreamCalledBeforeContentIsRead = inputStreamCalled;
            Stream contentStream = actualRequest.Content.ReadAsStreamAsync().Result;
            results.inputStreamCalledAfterContentIsRead = inputStreamCalled;
            return results;
        }
Esempio n. 2
0
        public ConvertRequest_DoesLazyGetBufferlessInputStream_TestResults ConvertRequest_DoesLazyGetBufferlessInputStream()
        {
            bool inputStreamCalled = false;

            HttpRequestBase stubRequest = HttpControllerHandlerTest.CreateStubRequestBase(() =>
            {
                inputStreamCalled = true;
                return(new MemoryStream());
            },
                                                                                          buffered: false);
            HttpContextBase context = HttpControllerHandlerTest.CreateStubContextBase(request: stubRequest, items: null);

            GlobalConfiguration.Configuration.Services.Replace(typeof(IHostBufferPolicySelector), new BufferOutputOnlyPolicySelector());
            HttpRequestMessage actualRequest = HttpControllerHandler.ConvertRequest(context);

            ConvertRequest_DoesLazyGetBufferlessInputStream_TestResults results = new ConvertRequest_DoesLazyGetBufferlessInputStream_TestResults();

            results.inputStreamCalledBeforeContentIsRead = inputStreamCalled;
            Stream contentStream = actualRequest.Content.ReadAsStreamAsync().Result;

            results.inputStreamCalledAfterContentIsRead = inputStreamCalled;
            return(results);
        }