public void ShouldError()
        {
            using ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            ILogger <RestPatientDelegate> logger = loggerFactory.CreateLogger <RestPatientDelegate>();

            string json        = @"{ ""hdid"":""P6FFO433A5WPMVTGM7T4ZVWBKCSVNAYGTWTU3J2LWMGUMERKI72A"",""personalhealthnumber"":""9735353315"",""firstname"":""BONNET"",""lastname"":""PROTERVITY"",""birthdate"":""1967-06-02T00:00:00"",""email"":""""}";
            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(json),
            })
            .Verifiable();
            Mock <IHttpClientService> mockHttpClientService = new Mock <IHttpClientService>();

            mockHttpClientService.Setup(s => s.CreateDefaultHttpClient()).Returns(() => new HttpClient(handlerMock.Object));
            IPatientDelegate patientDelegate = new RestPatientDelegate(
                logger,
                new Mock <ITraceService>().Object,
                mockHttpClientService.Object,
                this.configuration);
            RequestResult <string> result = patientDelegate.GetPatientPHN("HDID", "Bearer Token");

            Assert.True(result.ResultStatus == ResultType.Error);
        }
Exemple #2
0
        public void ShouldGetPHN()
        {
            RequestResult <Patient> expected = new RequestResult <Patient>()
            {
                ResultStatus = ResultType.Success, ResourcePayload = new Patient("1234", "912345678", "Test", "Gateway", DateTime.ParseExact("20001231", "yyyyMMdd", CultureInfo.InvariantCulture), string.Empty)
            };
            Mock <IHttpClientService> httpMock = new Mock <IHttpClientService>();
            var clientHandlerStub = new DelegatingHandlerStub(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonSerializer.Serialize(expected), Encoding.UTF8, MediaTypeNames.Application.Json),
            });
            var client = new HttpClient(clientHandlerStub);

            httpMock.Setup(_ => _.CreateDefaultHttpClient()).Returns(client);

            IPatientDelegate service = new RestPatientDelegate(
                new Mock <ILogger <RestPatientDelegate> >().Object,
                new Mock <ITraceService>().Object,
                httpMock.Object,
                configuration);
            RequestResult <string> result = service.GetPatientPHN(expected.ResourcePayload.HdId, "Bearer TheTestToken");

            Assert.Equal(expected.ResourcePayload.PersonalHealthNumber, result.ResourcePayload);
        }
Exemple #3
0
        public void ShouldCatchBadRequest()
        {
            Mock <IHttpClientService> httpMock = new Mock <IHttpClientService>();
            var clientHandlerStub = new DelegatingHandlerStub(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.BadRequest,
                Content    = new StringContent(string.Empty, Encoding.UTF8, MediaTypeNames.Application.Json),
            });

            var client = new HttpClient(clientHandlerStub);

            httpMock.Setup(_ => _.CreateDefaultHttpClient()).Returns(client);
            IPatientDelegate service = new RestPatientDelegate(
                new Mock <ILogger <RestPatientDelegate> >().Object,
                new Mock <ITraceService>().Object,
                httpMock.Object,
                configuration);
            RequestResult <string> patientResult = service.GetPatientPHN("", "Bearer TheTestToken");

            Assert.True(patientResult != null && patientResult.ResultStatus == Common.Constants.ResultType.Error);
        }