コード例 #1
0
        public void ShouldException()
        {
            var handlerMock = new Mock <HttpMessageHandler>();

            handlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                )
            .Throws <HttpRequestException>()
            .Verifiable();
            using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            Mock <IHttpClientService> mockHttpClientService = new Mock <IHttpClientService>();

            mockHttpClientService.Setup(s => s.CreateDefaultHttpClient()).Returns(() => new HttpClient(handlerMock.Object));
            IMSPVisitDelegate mspVisitDelegate = new RestMSPVisitDelegate(
                loggerFactory.CreateLogger <RestMSPVisitDelegate>(),
                mockHttpClientService.Object,
                this.configuration);
            ODRHistoryQuery query = new ODRHistoryQuery()
            {
                PHN = "123456789",
            };
            RequestResult <MSPVisitHistoryResponse> actualResult = Task.Run(async() => await mspVisitDelegate.GetMSPVisitHistoryAsync(query, string.Empty, string.Empty)).Result;

            Assert.True(actualResult.ResultStatus == Common.Constants.ResultType.Error && actualResult.ResultError.ErrorCode == "testhostServer-CE-ODR");
        }
コード例 #2
0
        public void ShouldGetMSPVisits()
        {
            string content     = @"
                   { 
                        ""uuid"": ""7c51465c-7a7d-489f-b186-8755ae094d09"",
                        ""hdid"": ""P6FFO433A5WPMVTGM7T4ZVWBKCSVNAYGTWTU3J2LWMGUMERKI72A"",
                        ""getMspVisitHistoryResponse"": {
                            ""totalRecords"":  1,
                            ""totalPages"": 1,
                            ""claims"": [
                            {
                                ""claimId"": 1,
                                ""serviceDate"": ""2020-05-27"",
                                ""feeDesc"": ""TACROLIMUS"",
                                ""diagnosticCode"": {
                                    ""diagCode1"": ""01L"",
                                    ""diagCode2"": ""02L"",
                                    ""diagCode3"": ""03L""
                                },
                                ""specialtyDesc"": ""LABORATORY MEDICINE"",
                                ""practitionerName"": ""PRACTITIONER NAME"",
                                ""locationName"": ""PAYEE NAME"",
                                ""locationAddress"": {
                                    ""addrLine1"": ""address line 1"",
                                    ""addrLine2"": ""address line 2"",
                                    ""addrLine3"": ""address line 3"",
                                    ""addrLine4"": ""address line 4"",
                                    ""city"": ""city"",
                                    ""postalCode"": ""V9V9V9"",
                                    ""province"": ""BC""
                                }
                            }]
                        }
                    }";
            var    handlerMock = new Mock <HttpMessageHandler>();

            handlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                )
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(content),
            })
            .Verifiable();
            using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            Mock <IHttpClientService> mockHttpClientService = new Mock <IHttpClientService>();

            mockHttpClientService.Setup(s => s.CreateDefaultHttpClient()).Returns(() => new HttpClient(handlerMock.Object));
            IMSPVisitDelegate mspVisitDelegate = new RestMSPVisitDelegate(
                loggerFactory.CreateLogger <RestMSPVisitDelegate>(),
                mockHttpClientService.Object,
                this.configuration);
            ODRHistoryQuery query = new ODRHistoryQuery()
            {
                PHN = "123456789",
            };
            RequestResult <MSPVisitHistoryResponse> actualResult = Task.Run(async() => await mspVisitDelegate.GetMSPVisitHistoryAsync(query, string.Empty, string.Empty)).Result;

            Assert.Equal(Common.Constants.ResultType.Success, actualResult.ResultStatus);
            Assert.Single(actualResult.ResourcePayload.Claims);
            Assert.Equal(1, actualResult.TotalResultCount);
        }
コード例 #3
0
        public void ShouldErrorDynamicLookup()
        {
            var handlerMock = new Mock <HttpMessageHandler>();

            handlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                )
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.Unauthorized,
                Content    = new StringContent(string.Empty),
            })
            .Verifiable();
            using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            Mock <IHttpClientService> mockHttpClientService = new Mock <IHttpClientService>();

            mockHttpClientService.Setup(s => s.CreateDefaultHttpClient()).Returns(() => new HttpClient(handlerMock.Object));

            var myConfiguration = new Dictionary <string, string>
            {
                { "ODR:DynamicServiceLookup", "True" },
                { "ODR:BaseEndpoint", "http://mockendpoint/" },
            };

            var localConfig = new ConfigurationBuilder()
                              .AddInMemoryCollection(myConfiguration)
                              .Build();

            IMSPVisitDelegate mspVisitDelegate = new RestMSPVisitDelegate(
                loggerFactory.CreateLogger <RestMSPVisitDelegate>(),
                mockHttpClientService.Object,
                localConfig);
            ODRHistoryQuery query = new ODRHistoryQuery()
            {
                PHN = "123456789",
            };
            RequestResult <MSPVisitHistoryResponse> actualResult = Task.Run(async() => await mspVisitDelegate.GetMSPVisitHistoryAsync(query, string.Empty, string.Empty)).Result;

            Assert.Equal(Common.Constants.ResultType.Error, actualResult.ResultStatus);
        }