コード例 #1
0
        public async Task ShouldGetMedications()
        {
            HNMessage expected = new HNMessage()
            {
                Message = "Test",
                IsErr   = false,
            };

            Mock <IAuthService> authMock = new Mock <IAuthService>();

            authMock.Setup(s => s.ClientCredentialsAuth()).ReturnsAsync(new JWTModel());

            Mock <IHNMessageParser <MedicationStatement> > parserMock = new Mock <IHNMessageParser <MedicationStatement> >();

            parserMock.Setup(s => s.ParseResponseMessage(expected.Message)).Returns(new List <MedicationStatement>());

            Mock <IHttpClientFactory> httpMock = new Mock <IHttpClientFactory>();
            var clientHandlerStub = new DelegatingHandlerStub((request, cancellationToken) => {
                request.SetConfiguration(new HttpConfiguration());
                HttpResponseMessage response = request.CreateResponse(HttpStatusCode.OK, expected, MediaTypeNames.Application.Json);
                return(Task.FromResult(response));
            });
            var client = new HttpClient(clientHandlerStub);

            httpMock.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);

            IMedicationService         service     = new RestMedicationService(parserMock.Object, httpMock.Object, configuration, authMock.Object);
            List <MedicationStatement> medications = await service.GetMedicationsAsync("123456789", "test", "10.0.0.1");

            Assert.True(medications.Count == 0);
        }
コード例 #2
0
        public void ShouldGetMedications()
        {
            DateTime           loadDate = DateTime.Parse("2020/09/29");
            string             DIN      = "00000000";
            List <DrugProduct> fedData  = new List <DrugProduct>()
            {
                new DrugProduct()
                {
                    DrugIdentificationNumber = DIN,
                    UpdatedDateTime          = loadDate,
                }
            };

            List <PharmaCareDrug> provData = new List <PharmaCareDrug>()
            {
                new PharmaCareDrug()
                {
                    DINPIN          = DIN,
                    UpdatedDateTime = loadDate,
                },
            };

            Dictionary <string, Models.MedicationInformation> expected = new Dictionary <string, Models.MedicationInformation>()
            {
                {
                    DIN,
                    new Models.MedicationInformation()
                    {
                        DIN         = DIN,
                        FederalData = new FederalDrugSource()
                        {
                            UpdateDateTime = loadDate,
                            DrugProduct    = fedData.First(),
                        },
                        ProvincialData = new ProvincialDrugSource()
                        {
                            UpdateDateTime = loadDate,
                            PharmaCareDrug = provData.First(),
                        }
                    }
                }
            };

            Mock <IDrugLookupDelegate> mockDelegate = new Mock <IDrugLookupDelegate>();

            mockDelegate.Setup(s => s.GetDrugProductsByDIN(It.IsAny <List <string> >())).Returns(fedData);
            mockDelegate.Setup(s => s.GetPharmaCareDrugsByDIN(It.IsAny <List <string> >())).Returns(provData);

            using Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            ILogger <RestMedicationService> logger = loggerFactory.CreateLogger <RestMedicationService>();

            IMedicationService service = new RestMedicationService(logger, mockDelegate.Object);
            var actual = service.GetMedications(new List <string>());

            Assert.True(actual.IsDeepEqual(expected));
        }
コード例 #3
0
        public async Task ShouldCatchBadRequest()
        {
            Mock <IAuthService> authMock = new Mock <IAuthService>();

            authMock.Setup(s => s.ClientCredentialsAuth()).ReturnsAsync(new JWTModel());

            Mock <IHNMessageParser <MedicationStatement> > parserMock = new Mock <IHNMessageParser <MedicationStatement> >();
            Mock <IHttpClientFactory> httpMock = new Mock <IHttpClientFactory>();
            var clientHandlerStub = new DelegatingHandlerStub((request, cancellationToken) => {
                request.SetConfiguration(new HttpConfiguration());
                HttpResponseMessage response = request.CreateResponse(HttpStatusCode.BadRequest);
                return(Task.FromResult(response));
            });
            var client = new HttpClient(clientHandlerStub);

            httpMock.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);
            IMedicationService   service = new RestMedicationService(parserMock.Object, httpMock.Object, configuration, authMock.Object);
            HttpRequestException ex      = await Assert.ThrowsAsync <HttpRequestException>(() => service.GetMedicationsAsync("", "", ""));
        }