コード例 #1
0
        public async Task get_null_when_user_is_not_authenticated()
        {
            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            var provider = new HttpContextRoleProvider(httpContextAccessor);

            (await provider.GetRoleAsync()).Should().BeNull();
        }
コード例 #2
0
        public async Task get_null_when_claim_role_not_exist()
        {
            var context = new DefaultHttpContext();

            context.User = GetAuthenticatedIdentityWithoutRole();

            var httpContextAccessor = new HttpContextAccessor();

            httpContextAccessor.HttpContext = context;

            var provider = new HttpContextRoleProvider(httpContextAccessor);

            (await provider.GetRoleAsync()).Should().BeNull();
        }
コード例 #3
0
        public async Task get_the_custom_claim_role_value_of_authenticated_user()
        {
            string currentRole = "stuff";

            var context = new DefaultHttpContext();

            context.User = GetAuthenticatedIdentityWithCustomRoleClaim(role: currentRole);

            var httpContextAccessor = new HttpContextAccessor();

            httpContextAccessor.HttpContext = context;

            var provider = new HttpContextRoleProvider(httpContextAccessor);

            (await provider.GetRoleAsync()).Should().Be(currentRole);
        }
コード例 #4
0
        public async Task get_null_for_non_authenticated_user_with_default_claim_role()
        {
            string currentRole = "stuff";

            var context = new DefaultHttpContext();

            context.User = GetNonAuthenticatedIdentityWithDefaultRoleClaim(role: currentRole);

            var httpContextAccessor = new HttpContextAccessor();

            httpContextAccessor.HttpContext = context;

            var provider = new HttpContextRoleProvider(httpContextAccessor);

            (await provider.GetRoleAsync()).Should().BeNull();
        }