Пример #1
0
        private async Task <HttpResponseMessage> ReadData(HttpRequestMessage request)
        {
            var mockRequest = MockRequestBuilder.MockRequest(request, true);

            using (var stream = await DataStream(mockRequest))
            {
                var resourceStream = stream;
                if (resourceStream == null && mockRequest.IsRouted)
                {
                    resourceStream = await DataStream(MockRequestBuilder.MockRequest(request, false));
                }

                if (resourceStream == null)
                {
                    return(new HttpResponseMessage(HttpStatusCode.NotFound));
                }

                return(ReadData(resourceStream));
            }
        }
        public void MockRequest_AfterBuild_WithoutRouting()
        {
            //Assign
            const string expectedValue        = "_controller_method_41";
            const string url                  = "http://example.com/controller/method/41";
            var          appEnvironmentConfig = GetEnvironmentConfig(MockFilesFormats.Json, new List <string> {
                nameof(MockRequestBuilderTests)
            }, nameof(MockRequest_AfterBuild_WithRouting));

            Routes.AddRoute("{controller}/method/{id}");
            const bool isRequestRouted = false;

            //Act
            var message            = new HttpRequestMessage(HttpMethod.Get, new Uri(url));
            var mockrequestBuilder = new MockRequestBuilder(appEnvironmentConfig);
            var mockRequest        = mockrequestBuilder.MockRequest(message, isRequestRouted);

            //Assert
            Assert.AreEqual(expectedValue, mockRequest.FileName);
        }