public async Task GivenMultipleProviders_WhenRequestingCapabilitiesThenCancelling_ThenTheSemaphoreDoesNotReleaseTwice()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var provider = new ConformanceProvider(
                CreateSystemConformanceProvider(),
                Substitute.For <IConfiguredConformanceProvider>(),
                Substitute.For <IUrlResolver>(),
                Options.Create(new ConformanceConfiguration()));

            // Request a cancellation
            cancellationTokenSource.Cancel();

            // Attempt to get a semaphore with a cancelled token:
            var nextRequest = provider.GetCapabilityStatementAsync(cancellationTokenSource.Token);

            // Do we get cancellation exception instead of SemaphoreFullException?
            await Assert.ThrowsAnyAsync <TaskCanceledException>(async() => await nextRequest);
        }
        public async Task GivenMultipleProviders_WhenRequestingAMergedCapabilitiesDocument_ThenGetsAValidCapabilityStatement()
        {
            SystemConformanceProvider systemCapabilities = CreateSystemConformanceProvider();

            var mockedCapabilities = CapabilityStatementMock.GetMockedCapabilityStatement();

            CapabilityStatementMock.SetupMockResource(mockedCapabilities, ResourceType.Account, new[] { CapabilityStatement.TypeRestfulInteraction.Create, CapabilityStatement.TypeRestfulInteraction.Read });

            var configured = Substitute.For <IConfiguredConformanceProvider>();

            configured
            .GetCapabilityStatementAsync()
            .Returns(mockedCapabilities.ToResourceElement());

            var urlResolver = Substitute.For <IUrlResolver>();

            urlResolver.ResolveMetadataUrl(Arg.Any <bool>()).Returns(new Uri("http://localhost/metadata"));

            var config = new ConformanceConfiguration()
            {
                UseStrictConformance = true,
            };

            var provider = new ConformanceProvider(
                systemCapabilities,
                configured,
                urlResolver,
                Options.Create(config));

            var typedCapabilityStatement = await provider.GetCapabilityStatementAsync();

            var capabilityStatement = typedCapabilityStatement.ToPoco <CapabilityStatement>();

            Assert.NotNull(capabilityStatement.Software);
            Assert.Equal("Microsoft FHIR Server", capabilityStatement.Software.Name);
            Assert.Equal("Microsoft Corporation", capabilityStatement.Publisher);
            Assert.NotNull(capabilityStatement.Rest.Single().Resource.Single().Interaction.FirstOrDefault(x => x.Code == CapabilityStatement.TypeRestfulInteraction.Create));
            Assert.NotNull(capabilityStatement.Rest.Single().Resource.Single().Interaction.FirstOrDefault(x => x.Code == CapabilityStatement.TypeRestfulInteraction.Read));
        }