コード例 #1
0
        public void Default()
        {
            int pageIndex = 0;
            RequestResult <IEnumerable <ImmunizationResponse> > expectedResult = new RequestResult <IEnumerable <ImmunizationResponse> >()
            {
                ResultStatus = Common.Constants.ResultType.Error,
                ResultError  = new RequestResultError()
                {
                    ResultMessage = $"Unable to connect to Immunizations Endpoint, HTTP Error {HttpStatusCode.RequestTimeout}",
                    ErrorCode     = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.PHSA)
                },
                PageIndex = pageIndex,
            };

            using Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            IHttpClientService    httpClientService = GetHttpClientService(HttpStatusCode.RequestTimeout, string.Empty);
            IImmunizationDelegate immsDelegate      = new RestImmunizationDelegate(loggerFactory.CreateLogger <RestImmunizationDelegate>(), httpClientService, this.configuration);
            var actualResult = immsDelegate.GetImmunizations("token", pageIndex).Result;

            Assert.True(actualResult.IsDeepEqual(expectedResult));
        }
コード例 #2
0
        public void Ok()
        {
            ImmunizationResponse expectedResponse = new ImmunizationResponse()
            {
                Id                 = Guid.NewGuid(),
                SourceSystemId     = "mockSourceSystemId",
                Name               = "mockName",
                OccurrenceDateTime = DateTime.ParseExact("2020/09/10 17:16:10.809", "yyyy/MM/dd HH:mm:ss.fff", CultureInfo.InvariantCulture)
            };

            PHSAResult <ImmunizationResponse> phsaResponse = new PHSAResult <ImmunizationResponse>()
            {
                Result = new List <ImmunizationResponse>()
                {
                    expectedResponse,
                }
            };

            string json = JsonSerializer.Serialize(phsaResponse, null);

            RequestResult <IEnumerable <ImmunizationResponse> > expectedResult = new RequestResult <IEnumerable <ImmunizationResponse> >()
            {
                ResultStatus    = Common.Constants.ResultType.Success,
                ResourcePayload = new List <ImmunizationResponse>()
                {
                    expectedResponse,
                },
                PageIndex        = 0,
                PageSize         = 25,
                TotalResultCount = 1,
            };

            using Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            IHttpClientService httpClientService = GetHttpClientService(HttpStatusCode.OK, json);

            IImmunizationDelegate immsDelegate = new RestImmunizationDelegate(loggerFactory.CreateLogger <RestImmunizationDelegate>(), httpClientService, this.configuration);
            var actualResult = immsDelegate.GetImmunizations("token", 0).Result;

            Assert.True(expectedResult.IsDeepEqual(actualResult));
        }
コード例 #3
0
        public void BadData()
        {
            string json = "{}";

            RequestResult <IEnumerable <ImmunizationResponse> > expectedResult = new RequestResult <IEnumerable <ImmunizationResponse> >()
            {
                PageIndex    = 0,
                ResultStatus = Common.Constants.ResultType.Error,
                ResultError  = new RequestResultError()
                {
                    ResultMessage = $"Error with JSON data",
                    ErrorCode     = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.PHSA)
                },
            };

            using Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            IHttpClientService httpClientService = GetHttpClientService(HttpStatusCode.OK, json);

            IImmunizationDelegate immsDelegate = new RestImmunizationDelegate(loggerFactory.CreateLogger <RestImmunizationDelegate>(), httpClientService, this.configuration);
            var actualResult = immsDelegate.GetImmunizations("token", 0).Result;

            Assert.True(expectedResult.IsDeepEqual(actualResult));
        }