Beispiel #1
0
        public async Task GetConfiguredIdentityProviders_ReturnsIdentityProvidersAsync()
        {
            var expectedProviders = new List <AuthenticationScheme>
            {
                new AuthenticationScheme("OpenID Connect", "Azure Active Directory", typeof(JwtBearerHandler)),
                new AuthenticationScheme("Windows", "Windows", typeof(JwtBearerHandler))
            };

            var httpContextMock = new Mock <HttpContext>();

            var httpContextAccessorMock = new Mock <IHttpContextAccessor>();

            httpContextAccessorMock.Setup(mock => mock.HttpContext).Returns(httpContextMock.Object);

            var authenticationSchemeProviderMock = new Mock <IAuthenticationSchemeProvider>();

            authenticationSchemeProviderMock.Setup(mock => mock.GetAllSchemesAsync()).ReturnsAsync(expectedProviders);

            var appConfig = new AppConfiguration {
                WindowsAuthenticationEnabled = true
            };

            var identityProviderConfigurationService = new IdentityProviderConfigurationService(httpContextAccessorMock.Object, authenticationSchemeProviderMock.Object, appConfig);
            var providers = await identityProviderConfigurationService.GetConfiguredIdentityProviders();

            Assert.NotNull(providers);
            Assert.Equal(expectedProviders.Count, providers.Count);
        }
Beispiel #2
0
        public void GetConfiguredIdentityProviders_ReturnsIdentityProviders()
        {
            var expectedProviders = new List <AuthenticationDescription>
            {
                new AuthenticationDescription
                {
                    AuthenticationScheme = "OpenId Connect",
                    DisplayName          = "Azure Active Directory"
                },
                new AuthenticationDescription
                {
                    AuthenticationScheme = "Windows",
                    DisplayName          = "Windows"
                }
            };

            var authenticationManagerMock = new Mock <AuthenticationManager>();

            authenticationManagerMock.Setup(mock => mock.GetAuthenticationSchemes())
            .Returns(expectedProviders);

            var httpContextMock = new Mock <HttpContext>();

            httpContextMock.Setup(mock => mock.Authentication).Returns(authenticationManagerMock.Object);

            var httpContextAccessorMock = new Mock <IHttpContextAccessor>();

            httpContextAccessorMock.Setup(mock => mock.HttpContext).Returns(httpContextMock.Object);

            var appConfig = new AppConfiguration {
                WindowsAuthenticationEnabled = true
            };

            var identityProviderConfigurationService = new IdentityProviderConfigurationService(httpContextAccessorMock.Object, appConfig);
            var providers = identityProviderConfigurationService.GetConfiguredIdentityProviders();

            Assert.NotNull(providers);
            Assert.Equal(expectedProviders.Count, providers.Count);
        }