Exemplo n.º 1
0
        public IMockedEncompassHttpClientService SetupResponseMessage(Action <HttpResponseMessage> action, KeyValuePair <string, string>?testHeader = null)
        {
            var respMsg = new HttpResponseMessage();

            action(respMsg);

            if (testHeader.HasValue)
            {
                respMsg.Headers.Add(testHeader.Value.Key, testHeader.Value.Value);
            }

            MockedHandler.Protected().Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(respMsg);
            return(this);
        }
Exemplo n.º 2
0
        public IMockedEncompassHttpClientService SetupResponseMessage(Action <HttpResponseMessage> action, Action callBack, KeyValuePair <string, string>?testHeader = null)
        {
            _logger?.LogInformation("Setup a response message for testing.");
            var respMsg = new HttpResponseMessage();

            action(respMsg);

            if (testHeader.HasValue)
            {
                respMsg.Headers.Add(testHeader.Value.Key, testHeader.Value.Value);
            }

            var returnsResult = MockedHandler.Protected().Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
                                .ReturnsAsync(respMsg);

            if (callBack != null)
            {
                returnsResult.Callback(callBack);
            }
            return(this);
        }