public async void SdsSProxy_GetHtmlOk() { var command = new CommandRequest { Method = HttpMethod.Get, ForwardUrl = new Uri("https://testtrust.testnhs.uk/path/to/record/abc123"), Forwarded = new Forwarded { By = "127.0.0.1", For = "127.0.0.1", Host = "esttrust.testnhs.uk", Protocol = "https" }, ClientThumbprint = null, ServerThumbprint = null, UseSecure = false, Headers = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(HeaderNames.Accept, $"{ContentType.JSON_CONTENT_HEADER}"), new KeyValuePair <string, string>(HeaderNames.AcceptEncoding, "gzip, deflate"), new KeyValuePair <string, string>(HeaderNames.AcceptLanguage, "en-GB,en"), new KeyValuePair <string, string>(HeaderNames.CacheControl, "no-cache"), new KeyValuePair <string, string>(HeaderNames.Connection, "Keep-Alive"), new KeyValuePair <string, string>(HeaderNames.Host, "testtrust.testnhs.uk") } }; var request = new HttpRequestMessage { RequestUri = command.ForwardUrl, Method = command.Method, Headers = { { "Forwarded", $"by={command.Forwarded.By};for={command.Forwarded.For};host={command.Forwarded.Host};proto={command.Forwarded.Protocol}" } } }; var jsonString = FhirBinaries.Html.AsJsonString(); var response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Version = HttpVersion.Version11, ReasonPhrase = HttpStatusCode.OK.ToString(), RequestMessage = request, Content = new StringContent(jsonString, Encoding.UTF8, ContentType.JSON_CONTENT_HEADER) }; var stubHandler = HttpMessageStub.GetClientHandler(response); var httpRequestHelperMock = new Mock <IHttpRequestHelper>(); httpRequestHelperMock.Setup(op => op.GetClientHandler(It.IsAny <CommandRequest>())).Returns(stubHandler.Object); httpRequestHelperMock.Setup(op => op.GetRequestMessage(It.IsAny <CommandRequest>())).Returns(request); var service = new SspProxyService(httpRequestHelperMock.Object); var commandResponse = await service.ForwardRequest(command); var content = Encoding.UTF8.GetString(commandResponse.Content, 0, commandResponse.Content.Length); Assert.Equal(200, commandResponse.StatusCode); Assert.NotNull(commandResponse.Headers); Assert.Contains(HeaderNames.ContentType, commandResponse.Headers.Keys); Assert.Equal(jsonString, content); }
public FhirConnectorTests() { var loggerMock = new Mock <ILoggingHelper>(); //apiMock.Setup(op => op.Value).Returns(apiOpts); _loggingHelper = loggerMock.Object; _requestUri = new Uri("http://outbound.com/binary"); var httpRequest = new HttpRequestMessage() { RequestUri = _requestUri, Method = HttpMethod.Get, Headers = { { HeaderNames.AcceptEncoding, "gzip, deflate" }, { HeaderNames.AcceptLanguage, "en-GB,en" }, { HeaderNames.CacheControl, "no-cache" }, { HeaderNames.Connection, "Keep-Alive" }, { HeaderNames.Host, _requestUri.Host }, } }; var binaryHtmlAsJson = FhirBinaries.Html.AsJsonString(); var okBinaryResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Version = HttpVersion.Version11, ReasonPhrase = HttpStatusCode.OK.ToString(), RequestMessage = httpRequest, Content = new StringContent(binaryHtmlAsJson, Encoding.UTF8, ContentType.JSON_CONTENT_HEADER) }; var okBinaryResponseWithLocation = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Version = HttpVersion.Version11, ReasonPhrase = HttpStatusCode.OK.ToString(), RequestMessage = httpRequest, Content = new StringContent(binaryHtmlAsJson, Encoding.UTF8, ContentType.JSON_CONTENT_HEADER), Headers = { { HeaderNames.Location, "http://reposiroty.genhos.nhs.uk/binary/abc" } } }; var binaryBundleAsJson = FhirBinaries.AsBundle.AsJsonString(); var okBinaryBundleResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Version = HttpVersion.Version11, ReasonPhrase = HttpStatusCode.OK.ToString(), RequestMessage = httpRequest, Content = new StringContent(binaryBundleAsJson, Encoding.UTF8, ContentType.JSON_CONTENT_HEADER) }; var okEmptyContentResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Version = HttpVersion.Version11, ReasonPhrase = HttpStatusCode.OK.ToString(), RequestMessage = httpRequest, Content = new StringContent(string.Empty, Encoding.UTF8, ContentType.JSON_CONTENT_HEADER) }; var okNullContentResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Version = HttpVersion.Version11, ReasonPhrase = HttpStatusCode.OK.ToString(), RequestMessage = httpRequest, Content = null }; var operationOutcomeAsJson = FhirOperationOutcomes.NotFound.AsJsonString(); var notFoundBinaryResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.NotFound, Version = HttpVersion.Version11, ReasonPhrase = HttpStatusCode.NotFound.ToString(), RequestMessage = httpRequest, Content = new StringContent(operationOutcomeAsJson, Encoding.UTF8, ContentType.JSON_CONTENT_HEADER) }; var okBinaryStubHandler = HttpMessageStub.GetClientHandler(okBinaryResponse); var okBinaryLocationStubHandler = HttpMessageStub.GetClientHandler(okBinaryResponseWithLocation); var okBinaryBundleStubHandler = HttpMessageStub.GetClientHandler(okBinaryBundleResponse); var okNullContentStubHandler = HttpMessageStub.GetClientHandler(okNullContentResponse); var okEmptyContentStubHandler = HttpMessageStub.GetClientHandler(okEmptyContentResponse); var notFoundStubHandler = HttpMessageStub.GetClientHandler(notFoundBinaryResponse); var httpRequestHelperMock = new Mock <IHttpRequestHelper>(); httpRequestHelperMock.Setup(op => op.GetClientHandler(It.IsAny <CommandRequest>())).Returns(okBinaryStubHandler.Object); httpRequestHelperMock.Setup(op => op.GetClientHandler(It.Is <CommandRequest>(x => x.Headers.FirstOrDefault(y => y.Key == FhirConstants.HeaderSspFrom).Value == "20000000016"))).Returns(okBinaryBundleStubHandler.Object); httpRequestHelperMock.Setup(op => op.GetClientHandler(It.Is <CommandRequest>(x => x.Headers.FirstOrDefault(y => y.Key == FhirConstants.HeaderSspFrom).Value == "20000000015"))).Returns(okNullContentStubHandler.Object); httpRequestHelperMock.Setup(op => op.GetClientHandler(It.Is <CommandRequest>(x => x.Headers.FirstOrDefault(y => y.Key == FhirConstants.HeaderSspFrom).Value == "20000000014"))).Returns(okEmptyContentStubHandler.Object); httpRequestHelperMock.Setup(op => op.GetClientHandler(It.Is <CommandRequest>(x => x.Headers.FirstOrDefault(y => y.Key == FhirConstants.HeaderSspFrom).Value == "20000000013"))).Returns(notFoundStubHandler.Object); httpRequestHelperMock.Setup(op => op.GetClientHandler(It.Is <CommandRequest>(x => x.Headers.FirstOrDefault(y => y.Key == FhirConstants.HeaderSspFrom).Value == "20000000012"))).Returns(okBinaryLocationStubHandler.Object); httpRequestHelperMock.Setup(op => op.GetRequestMessage(It.IsAny <CommandRequest>())).Returns(httpRequest); _httpRequestHelper = httpRequestHelperMock.Object; _jwtToken = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2RlbW9uc3RyYXRvci5jb20iLCJzdWIiOiJodHRwczovL2ZoaXIubmhzLnVrL0lkL3Nkcy1yb2xlLXByb2ZpbGUtaWR8ZmFrZVJvbGVJZCIsImF1ZCI6Imh0dHBzOi8vbnJscy5jb20vZmhpci9kb2N1bWVudHJlZmVyZW5jZSIsImV4cCI6MTUyMjU3NzEzMCwiaWF0IjoxNTIyNTc2ODMwLCJyZWFzb25fZm9yX3JlcXVlc3QiOiJkaXJlY3RjYXJlIiwic2NvcGUiOiJwYXRpZW50L0RvY3VtZW50UmVmZXJlbmNlLndyaXRlIiwicmVxdWVzdGluZ19zeXN0ZW0iOiJodHRwczovL2ZoaXIubmhzLnVrL0lkL2FjY3JlZGl0ZWQtc3lzdGVtfDIwMDAwMDAwMDE3IiwicmVxdWVzdGluZ19vcmdhbml6YXRpb24iOiJodHRwczovL2ZoaXIubmhzLnVrL0lkL29kcy1vcmdhbml6YXRpb24tY29kZXxPUkcxIiwicmVxdWVzdGluZ191c2VyIjoiaHR0cHM6Ly9maGlyLm5ocy51ay9JZC9zZHMtcm9sZS1wcm9maWxlLWlkfGZha2VSb2xlSWQifQ."; }