Example #1
0
        public async Task ProcessDefaultInvocationRequest_Succeeds()
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => ValidateDefaultInvocationRequest(request))
            .ReturnsAsync(HttpWorkerTestUtilities.GetValidHttpResponseMessage());

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(_httpWorkerOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));
            Assert.Equal(_httpClient.Timeout, _scriptJobHostOptions.FunctionTimeout.Value.Add(TimeSpan.FromMinutes(1)));
            var testScriptInvocationContext = HttpWorkerTestUtilities.GetScriptInvocationContext(TestFunctionName, _testInvocationId, _functionLogger);
            await _defaultHttpWorkerService.ProcessDefaultInvocationRequest(testScriptInvocationContext);

            var invocationResult = await testScriptInvocationContext.ResultSource.Task;

            var expectedHttpScriptInvocationResult = HttpWorkerTestUtilities.GetTestHttpScriptInvocationResult();
            var testLogs = _functionLogger.GetLogMessages();

            Assert.True(testLogs.Count() == expectedHttpScriptInvocationResult.Logs.Count());
            Assert.True(testLogs.All(m => m.FormattedMessage.Contains("invocation log")));
            Assert.Equal(expectedHttpScriptInvocationResult.Outputs.Count(), invocationResult.Outputs.Count());
            Assert.Equal(expectedHttpScriptInvocationResult.ReturnValue, invocationResult.Return);
        }
        public async Task ProcessDefaultInvocationRequest_CustomHandler_EnableRequestForwarding_False()
        {
            var handlerMock          = new Mock <HttpMessageHandler>(MockBehavior.Strict);
            var customHandlerOptions = new HttpWorkerOptions()
            {
                Port = _defaultPort,
                Type = CustomHandlerType.Http
            };

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => ValidateeSimpleHttpTriggerSentAsDefaultInvocationRequest(request))
            .ReturnsAsync(HttpWorkerTestUtilities.GetValidHttpResponseMessageWithJsonRes());

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(customHandlerOptions), _testLogger, _testEnvironment);
            var testScriptInvocationContext = HttpWorkerTestUtilities.GetSimpleHttpTriggerScriptInvocationContext(TestFunctionName, _testInvocationId, _functionLogger);
            await _defaultHttpWorkerService.InvokeAsync(testScriptInvocationContext);

            var invocationResult = await testScriptInvocationContext.ResultSource.Task;

            var expectedHttpScriptInvocationResult = HttpWorkerTestUtilities.GetHttpScriptInvocationResultWithJsonRes();
            var testLogs = _functionLogger.GetLogMessages();

            Assert.True(testLogs.Count() == expectedHttpScriptInvocationResult.Logs.Count());
            Assert.True(testLogs.All(m => m.FormattedMessage.Contains("invocation log")));
            Assert.Equal(expectedHttpScriptInvocationResult.Outputs.Count(), invocationResult.Outputs.Count());
            Assert.Equal(expectedHttpScriptInvocationResult.ReturnValue, invocationResult.Return);
            var responseJson = JObject.Parse(invocationResult.Outputs["res"].ToString());

            Assert.Equal("my world", responseJson["Body"]);
            Assert.Equal("201", responseJson["StatusCode"]);
        }
Example #3
0
        public void TestBuildAndGetUri(string pathValue, string expectedUriString)
        {
            HttpWorkerOptions testOptions = new HttpWorkerOptions
            {
                Port = 8080,
            };
            DefaultHttpWorkerService defaultHttpWorkerService = new DefaultHttpWorkerService(new HttpClient(), new OptionsWrapper <HttpWorkerOptions>(testOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));

            Assert.Equal(expectedUriString, defaultHttpWorkerService.BuildAndGetUri(pathValue));
        }
Example #4
0
        public void AddHeadersTest()
        {
            HttpWorkerOptions        testOptions = new HttpWorkerOptions();
            DefaultHttpWorkerService defaultHttpWorkerService = new DefaultHttpWorkerService(new HttpClient(), new OptionsWrapper <HttpWorkerOptions>(testOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));
            HttpRequestMessage       input = new HttpRequestMessage();
            string invocationId            = Guid.NewGuid().ToString();

            defaultHttpWorkerService.AddHeaders(input, invocationId);
            Assert.Equal(input.Headers.GetValues(HttpWorkerConstants.HostVersionHeaderName).FirstOrDefault(), ScriptHost.Version);
            Assert.Equal(input.Headers.GetValues(HttpWorkerConstants.InvocationIdHeaderName).FirstOrDefault(), invocationId);
        }
Example #5
0
        public void TestPathValue(string functionName, CustomHandlerType type, bool enableForwardingHttpRequest, string expectedValue, string hostValue = "localhost")
        {
            HttpRequest       testHttpRequest = HttpWorkerTestUtilities.GetTestHttpRequest(hostValue);
            HttpWorkerOptions testOptions     = new HttpWorkerOptions
            {
                Type = type,
                EnableForwardingHttpRequest = enableForwardingHttpRequest,
            };
            DefaultHttpWorkerService defaultHttpWorkerService = new DefaultHttpWorkerService(new HttpClient(), new OptionsWrapper <HttpWorkerOptions>(testOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));
            string actualValue = defaultHttpWorkerService.GetPathValue(testOptions, functionName, testHttpRequest);

            Assert.Equal(actualValue, expectedValue);
        }
Example #6
0
        public async Task ProcessPing_Succeeds()
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => ValidateSimpleHttpTriggerInvocationRequest(request))
            .ReturnsAsync(HttpWorkerTestUtilities.GetSimpleNotFoundHttpResponseMessage());

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(_httpWorkerOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));
            await _defaultHttpWorkerService.PingAsync();

            handlerMock.VerifyAll();
        }
Example #7
0
        public async Task IsWorkerReady_Returns_True()
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => RequestHandler(request))
            .ReturnsAsync(HttpWorkerTestUtilities.GetValidHttpResponseMessage());

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(_httpWorkerOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));

            bool workerReady = await _defaultHttpWorkerService.IsWorkerReady(CancellationToken.None);

            Assert.True(workerReady);
        }
        public async Task ProcessDefaultInvocationRequest_InvalidMediaType_Throws()
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => RequestHandler(request))
            .ReturnsAsync(HttpWorkerTestUtilities.GetHttpResponseMessageWithStringContent());

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(_httpWorkerOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));
            var testScriptInvocationContext = HttpWorkerTestUtilities.GetScriptInvocationContext(TestFunctionName, _testInvocationId, _testLogger);
            await _defaultHttpWorkerService.ProcessDefaultInvocationRequest(testScriptInvocationContext);

            await Assert.ThrowsAsync <UnsupportedMediaTypeException>(async() => await testScriptInvocationContext.ResultSource.Task);
        }
Example #9
0
        public async Task ProcessDefaultInvocationRequest_OkResponse_InvalidBody_Throws()
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => RequestHandler(request))
            .ReturnsAsync(HttpWorkerTestUtilities.GetValidHttpResponseMessage_JsonType_InvalidContent());

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(_httpWorkerOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));
            var testScriptInvocationContext = HttpWorkerTestUtilities.GetScriptInvocationContext(TestFunctionName, _testInvocationId, _functionLogger);
            await _defaultHttpWorkerService.ProcessDefaultInvocationRequest(testScriptInvocationContext);

            InvalidOperationException recodedEx = await Assert.ThrowsAsync <InvalidOperationException>(async() => await testScriptInvocationContext.ResultSource.Task);

            Assert.Contains("Hello World", recodedEx.Message);
            Assert.Contains("StatusCode: 200", recodedEx.Message);
        }
Example #10
0
        public async Task ProcessDefaultInvocationRequest_JsonResponse_Succeeds()
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => RequestHandler(request))
            .ReturnsAsync(HttpWorkerTestUtilities.GetHttpResponseMessageWithJsonContent());

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(_httpWorkerOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));
            var testScriptInvocationContext = HttpWorkerTestUtilities.GetScriptInvocationContext(TestFunctionName, _testInvocationId, _functionLogger);
            await _defaultHttpWorkerService.ProcessDefaultInvocationRequest(testScriptInvocationContext);

            var invocationResult = await testScriptInvocationContext.ResultSource.Task;

            Assert.Empty(invocationResult.Outputs);
            Assert.Null(invocationResult.Return);
        }
Example #11
0
        public async Task ProcessDefaultInvocationRequest_BadRequestResponse_Throws()
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => RequestHandler(request))
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.BadRequest
            });

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(_httpWorkerOptions), _testLoggerFactory);
            var testScriptInvocationContext = HttpWorkerTestUtilities.GetScriptInvocationContext(TestFunctionName, _testInvocationId, _testLogger);
            await _defaultHttpWorkerService.ProcessDefaultInvocationRequest(testScriptInvocationContext);

            await Assert.ThrowsAsync <HttpRequestException>(async() => await testScriptInvocationContext.ResultSource.Task);
        }
Example #12
0
        public async Task ProcessSimpleHttpTriggerInvocationRequest_CustomHandler_EnableForwardingHttpRequest_True()
        {
            var handlerMock          = new Mock <HttpMessageHandler>(MockBehavior.Strict);
            var customHandlerOptions = new HttpWorkerOptions()
            {
                Port = _defaultPort,
                EnableForwardingHttpRequest = true
            };

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => ValidateSimpleHttpTriggerInvocationRequest(request))
            .ReturnsAsync(HttpWorkerTestUtilities.GetValidSimpleHttpResponseMessage());

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(customHandlerOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));
            var testScriptInvocationContext = HttpWorkerTestUtilities.GetSimpleHttpTriggerScriptInvocationContext(TestFunctionName, _testInvocationId, _functionLogger);
            await _defaultHttpWorkerService.InvokeAsync(testScriptInvocationContext);

            var invocationResult            = await testScriptInvocationContext.ResultSource.Task;
            var expectedHttpResponseMessage = HttpWorkerTestUtilities.GetValidSimpleHttpResponseMessage();
            var expectedResponseContent     = await expectedHttpResponseMessage.Content.ReadAsStringAsync();

            var testLogs = _functionLogger.GetLogMessages();

            Assert.Equal(0, testLogs.Count());

            Assert.Equal(1, invocationResult.Outputs.Count());
            var httpOutputResponse = invocationResult.Outputs.FirstOrDefault().Value as HttpResponseMessage;

            Assert.NotNull(httpOutputResponse);
            Assert.Equal(expectedHttpResponseMessage.StatusCode, httpOutputResponse.StatusCode);
            Assert.Equal(expectedResponseContent, await httpOutputResponse.Content.ReadAsStringAsync());

            var response = invocationResult.Return as HttpResponseMessage;

            Assert.NotNull(response);
            Assert.Equal(expectedHttpResponseMessage.StatusCode, response.StatusCode);
            Assert.Equal(expectedResponseContent, await response.Content.ReadAsStringAsync());
        }
Example #13
0
        public async Task IsWorkerReady_Returns_False()
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => RequestHandler(request))
            .Throws(new HttpRequestException("Invalid http worker service", new SocketException()));

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(_httpWorkerOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));

            bool workerReady = await _defaultHttpWorkerService.IsWorkerReady(CancellationToken.None);

            Assert.False(workerReady);

            var testLogs = _testLogger.GetLogMessages();

            Assert.True(testLogs.All(m => m.FormattedMessage.Contains("Invalid http worker service")));
        }
Example #14
0
        public void ProcessOutputLogs_Succeeds(HttpScriptInvocationResult httpScriptInvocationResult)
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => RequestHandler(request))
            .ReturnsAsync(HttpWorkerTestUtilities.GetValidHttpResponseMessage());

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(_httpWorkerOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));
            _defaultHttpWorkerService.ProcessLogsFromHttpResponse(HttpWorkerTestUtilities.GetScriptInvocationContext(TestFunctionName, _testInvocationId, _functionLogger), httpScriptInvocationResult);
            var testLogs = _functionLogger.GetLogMessages();

            if (httpScriptInvocationResult.Logs != null && httpScriptInvocationResult.Logs.Any())
            {
                Assert.True(testLogs.Count() == httpScriptInvocationResult.Logs?.Count());
                Assert.True(testLogs.All(m => m.FormattedMessage.Contains("test log")));
            }
        }
Example #15
0
        public async Task ProcessDefaultInvocationRequest_BinaryData_Succeeds()
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => ValidateDefaultInvocationRequest(request))
            .ReturnsAsync(HttpWorkerTestUtilities.GetValidHttpResponseMessage_Binary_Data());

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(_httpWorkerOptions), _testLogger, _testEnvironment, new OptionsWrapper <ScriptJobHostOptions>(_scriptJobHostOptions));
            var testScriptInvocationContext = HttpWorkerTestUtilities.GetScriptInvocationContext(TestFunctionName, _testInvocationId, _functionLogger);
            await _defaultHttpWorkerService.ProcessDefaultInvocationRequest(testScriptInvocationContext);

            var invocationResult = await testScriptInvocationContext.ResultSource.Task;

            var expectedHttpScriptInvocationResult = HttpWorkerTestUtilities.GetTestHttpScriptInvocationResult_Binary_Outputs();
            var testLogs = _functionLogger.GetLogMessages();

            Assert.True(testLogs.Count() == expectedHttpScriptInvocationResult.Logs.Count());
            Assert.True(testLogs.All(m => m.FormattedMessage.Contains("invocation log")));
            Assert.Equal(expectedHttpScriptInvocationResult.Outputs.Count(), invocationResult.Outputs.Count());

            // Verifies decoding for binary data from base64 encoded string
            foreach (var expectedOutput in expectedHttpScriptInvocationResult.Outputs)
            {
                byte[] expectedOutputData   = Convert.FromBase64String((string)expectedOutput.Value);
                string expectedOutputString = Encoding.UTF8.GetString(expectedOutputData);
                string actualOutputString   = Encoding.UTF8.GetString((byte[])invocationResult.Outputs[expectedOutput.Key]);
                Assert.Equal(expectedOutputString, actualOutputString);
            }

            byte[] expectedStringData = Convert.FromBase64String((string)expectedHttpScriptInvocationResult.ReturnValue);
            string expectedString     = Encoding.UTF8.GetString(expectedStringData);
            string actualString       = Encoding.UTF8.GetString((byte[])invocationResult.Return);

            Assert.Equal(expectedString, actualString);
        }
Example #16
0
        public async Task ProcessSimpleHttpTriggerInvocationRequest_Sets_ExpectedResult()
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => RequestHandler(request))
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.InternalServerError
            });

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(_httpWorkerOptions), _testLoggerFactory);
            var testScriptInvocationContext = HttpWorkerTestUtilities.GetSimpleHttpTriggerScriptInvocationContext(TestFunctionName, _testInvocationId, _testLogger);
            await _defaultHttpWorkerService.ProcessHttpInAndOutInvocationRequest(testScriptInvocationContext);

            var invocationResult            = await testScriptInvocationContext.ResultSource.Task;
            var expectedHttpResponseMessage = HttpWorkerTestUtilities.GetValidSimpleHttpResponseMessage();
            var expectedResponseContent     = await expectedHttpResponseMessage.Content.ReadAsStringAsync();

            var testLogs = _testLogger.GetLogMessages();

            Assert.Equal(0, testLogs.Count());

            Assert.Equal(1, invocationResult.Outputs.Count());
            var httpOutputResponse = invocationResult.Outputs.FirstOrDefault().Value as HttpResponseMessage;

            Assert.NotNull(httpOutputResponse);
            Assert.Equal(HttpStatusCode.InternalServerError, httpOutputResponse.StatusCode);

            var response = invocationResult.Return as HttpResponseMessage;

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
Example #17
0
        public async Task ProcessDefaultInvocationRequest_DataType_Binary_Succeeds()
        {
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                        ItExpr.IsAny <HttpRequestMessage>(),
                                                                        ItExpr.IsAny <CancellationToken>())
            .Callback <HttpRequestMessage, CancellationToken>((request, token) => ValidateDefaultInvocationRequest(request))
            .ReturnsAsync(HttpWorkerTestUtilities.GetValidHttpResponseMessage_DataType_Binary_Data());

            _httpClient = new HttpClient(handlerMock.Object);
            _defaultHttpWorkerService = new DefaultHttpWorkerService(_httpClient, new OptionsWrapper <HttpWorkerOptions>(_httpWorkerOptions), _testLoggerFactory);
            var testScriptInvocationContext = HttpWorkerTestUtilities.GetScriptInvocationContext(TestFunctionName, _testInvocationId, _testLogger, Script.Description.DataType.Binary);
            await _defaultHttpWorkerService.ProcessDefaultInvocationRequest(testScriptInvocationContext);

            var invocationResult = await testScriptInvocationContext.ResultSource.Task;

            var expectedHttpScriptInvocationResult = HttpWorkerTestUtilities.GetTestHttpScriptInvocationResult_DataType_Binary_Outputs();
            var testLogs = _testLogger.GetLogMessages();

            Assert.True(testLogs.Count() == expectedHttpScriptInvocationResult.Logs.Count());
            Assert.True(testLogs.All(m => m.FormattedMessage.Contains("invocation log")));
            Assert.Equal(expectedHttpScriptInvocationResult.Outputs.Count(), invocationResult.Outputs.Count());

            // Verifies output data is not transformed if dataType is set to binary
            foreach (var expectedOutput in expectedHttpScriptInvocationResult.Outputs)
            {
                string expectedOutputString = Encoding.UTF8.GetString((byte[])expectedOutput.Value);
                string actualOutputString   = Encoding.UTF8.GetString((byte[])invocationResult.Outputs[expectedOutput.Key]);
                Assert.Equal(expectedOutputString, actualOutputString);
            }

            string expectedString = Encoding.UTF8.GetString((byte[])expectedHttpScriptInvocationResult.ReturnValue);
            string actualString   = Encoding.UTF8.GetString((byte[])invocationResult.Return);

            Assert.Equal(expectedString, actualString);
        }