public async Task GetConfigurationAsync_ValidParameters_ReturnsIssuerMetadata()
        {
            var metadata        = @"{""tenant_discovery_endpoint"":""https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration"",""api-version"":""1.1"",""metadata"":[{""preferred_network"":""login.microsoftonline.com"",""preferred_cache"":""login.windows.net"",""aliases"":[""login.microsoftonline.com""]}]}";
            var metadataAddress = "address";

            var configurationRetriever = new IssuerConfigurationRetriever();
            var documentRetriever      = Substitute.For <IDocumentRetriever>();

            documentRetriever.GetDocumentAsync(metadataAddress, CancellationToken.None).Returns(Task.FromResult(metadata));

            var actualIssuerMetadata = await configurationRetriever.GetConfigurationAsync(metadataAddress, documentRetriever, CancellationToken.None).ConfigureAwait(false);
        }
        public async Task GetConfigurationAsync_NullOrEmptyParameters_ThrowsException()
        {
            var configurationRetriever            = new IssuerConfigurationRetriever();
            var expectedAddressExceptionMessage   = "Azure AD Issuer metadata address url is required (Parameter 'address')";
            var expectedRetrieverExceptionMessage = "No metadata document retriever is provided (Parameter 'retriever')";

            var exception = await Assert.ThrowsAsync <ArgumentNullException>("address", () => configurationRetriever.GetConfigurationAsync(null, null, CancellationToken.None));

            Assert.Equal(expectedAddressExceptionMessage, exception.Message);

            exception = await Assert.ThrowsAsync <ArgumentNullException>("address", () => configurationRetriever.GetConfigurationAsync("", null, CancellationToken.None));

            Assert.Equal(expectedAddressExceptionMessage, exception.Message);

            exception = await Assert.ThrowsAsync <ArgumentNullException>("retriever", () => configurationRetriever.GetConfigurationAsync("address", null, CancellationToken.None));

            Assert.Equal(expectedRetrieverExceptionMessage, exception.Message);
        }
        public async Task GetConfigurationAsync_NullOrEmptyParameters_ThrowsException()
        {
            var configurationRetriever = new IssuerConfigurationRetriever();

            string expectedErrorMessage = IDWebErrorMessage.IssuerMetadataURLIsRequired + " (Parameter 'address')";

            var exception = await Assert.ThrowsAsync <ArgumentNullException>("address", () => configurationRetriever.GetConfigurationAsync(null, null, CancellationToken.None)).ConfigureAwait(false);

            Assert.Equal(expectedErrorMessage, exception.Message);

            exception = await Assert.ThrowsAsync <ArgumentNullException>("address", () => configurationRetriever.GetConfigurationAsync(string.Empty, null, CancellationToken.None)).ConfigureAwait(false);

            Assert.Equal(expectedErrorMessage, exception.Message);

            exception = await Assert.ThrowsAsync <ArgumentNullException>("retriever", () => configurationRetriever.GetConfigurationAsync("address", null, CancellationToken.None)).ConfigureAwait(false);

            Assert.Equal(IDWebErrorMessage.NoMetadataDocumentRetrieverProvided + " (Parameter 'retriever')", exception.Message);
        }