Esempio n. 1
0
        /// <summary>
        /// Runs a command through the IActionResult ASP.Net pathways and returns a HTTP response.
        /// This is useful for testing end to end HTTP triggered functions without having to actually host the
        /// function app.
        /// A method only needs specifying in the function supports multiple methods.
        /// </summary>
        public async Task <HttpResponse> ExecuteHttpAsync <TResult>(ICommand <TResult> command, HttpMethod method = null)
        {
            HttpFunctionDefinition httpFunctionDefinition = FindHttpFunctionDefinition(command);
            ActionContext          actionContext          = _aspNetRuntime.PrepareToExecuteHttp(command, httpFunctionDefinition, method);
            IHttpResponseHandler   httpResponseHandler    = GetHttpResponseHandler(httpFunctionDefinition);
            HttpDispatcher         httpDispatcher         = new HttpDispatcher(Dispatcher, ServiceProvider);

            IActionResult actionResult = await httpDispatcher.DispatchAndConvertToActionResult(command, httpResponseHandler, httpFunctionDefinition);

            return(await _aspNetRuntime.CreateHttpResponse(actionContext, actionResult));
        }
Esempio n. 2
0
        public static TestBuilder GetTestBuilder()
        {
            if (_testBuilder != null)
            {
                return(_testBuilder);
            }

            var builder = new WebHostBuilder()
                          .UseEnvironment("Development")
                          .UseStartup <Startup>();

            var       _testServer = new TestServer(builder);
            var       _client     = _testServer.CreateClient();
            IDispatch _dispatcher = new HttpDispatcher <ITestService>(_client);

            return(new TestBuilder(_dispatcher));
        }
Esempio n. 3
0
        public static TContract GetProxy <TContract>(this HttpClient client)
        {
            var dispatcher = new HttpDispatcher <TContract>(client);

            return(ServiceProxy <TContract> .GetProxy(dispatcher));
        }