Exemplo n.º 1
0
        public async void GivenNoEncounterIdentifier_WhenResolveResourceIdentitiesAsync_ThenResourceIdentityNotDefinedExceptionThrown_Test()
        {
            var fhirClient      = Substitute.For <IFhirClient>();
            var resourceService = Substitute.For <ResourceManagementService>();
            var device          = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Patient/123"),
            };

            var mg = Substitute.For <IMeasurementGroup>();

            mg.DeviceId.Returns("deviceId");
            mg.EncounterId.Returns((string)null);

            resourceService.GetResourceByIdentityAsync <Model.Device>(Arg.Any <IFhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromResult(device));

            using (var idSrv = new R4DeviceAndPatientWithEncounterLookupIdentityService(fhirClient, resourceService))
            {
                var ex = await Assert.ThrowsAsync <ResourceIdentityNotDefinedException>(async() => await idSrv.ResolveResourceIdentitiesAsync(mg));

                Assert.Equal(ResourceType.Encounter, ex.FhirResourceType);
            }

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", null);

            await resourceService.DidNotReceiveWithAnyArgs().GetResourceByIdentityAsync <Model.Encounter>(null, null, null);
        }
Exemplo n.º 2
0
        public async void GivenValidEncounterIdentifier_WhenResolveResourceIdentitiesAsync_ThenEncounterIdReturned_Test()
        {
            var fhirClient      = Substitute.For <IFhirClient>();
            var resourceService = Substitute.For <ResourceManagementService>();
            var device          = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Patient/123"),
            };

            var encounter = new Model.Encounter
            {
                Id = "abc",
            };

            var mg = Substitute.For <IMeasurementGroup>();

            mg.DeviceId.Returns("deviceId");
            mg.EncounterId.Returns("eId");

            resourceService.GetResourceByIdentityAsync <Model.Device>(Arg.Any <IFhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromResult(device));

            resourceService.GetResourceByIdentityAsync <Model.Encounter>(Arg.Any <IFhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromResult(encounter));

            using (var idSrv = new R4DeviceAndPatientWithEncounterLookupIdentityService(fhirClient, resourceService))
            {
                var ids = await idSrv.ResolveResourceIdentitiesAsync(mg);

                Assert.Equal("1", ids[ResourceType.Device]);
                Assert.Equal("123", ids[ResourceType.Patient]);
                Assert.Equal("abc", ids[ResourceType.Encounter]);
            }

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", null);

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Encounter>(fhirClient, "eId", null);
        }