Esempio n. 1
0
        public static IServiceCollection AddFhirClient(this IServiceCollection serviceCollection, IConfiguration configuration)
        {
            EnsureArg.IsNotNull(serviceCollection, nameof(serviceCollection));
            EnsureArg.IsNotNull(configuration, nameof(configuration));

            var  url = new Uri(configuration.GetValue <string>("FhirService:Url"));
            bool useManagedIdentity = configuration.GetValue <bool>("FhirClient:UseManagedIdentity");

            serviceCollection.AddHttpClient <IFhirClient, FhirClient>((client, sp) =>
            {
                client.BaseAddress = url;
                client.Timeout     = TimeSpan.FromSeconds(60);

                var logger = sp.GetRequiredService <ITelemetryLogger>();

                // Using discard because we don't need result
                var fhirClient = new FhirClient(client);
                _ = fhirClient.ValidateFhirClientAsync(logger);

                return(fhirClient);
            })
            .AddAuthenticationHandler(serviceCollection, url, useManagedIdentity);

            return(serviceCollection);
        }
Esempio n. 2
0
        private async Task ValidateFhirClientUrl(string url, bool expectedIsValid)
        {
            var fhirClientSettings = new FhirClientSettings
            {
                PreferredFormat = ResourceFormat.Json,
            };

            var fhirClient = new FhirClient(new Uri(url), fhirClientSettings.PreferredFormat);

            var logger = Substitute.For <ITelemetryLogger>();

            bool actualIsValid = await fhirClient.ValidateFhirClientAsync(logger);

            Assert.Equal(expectedIsValid, actualIsValid);
        }