Пример #1
0
        public async Task ThenChecksIfEmployerIsAuthorised(
            [Frozen] Mock <IEmployerAccountAuthorisationHandler> employerAccountAuthorizationHandler,
            HasEmployerViewerUserRoleOrIsProviderRequirement orIsProviderRequirement,
            AuthorizationFilterContext contextFilter,
            HasEmployerViewerUserRoleOrIsProvider provider)
        {
            //Assign
            var context = new AuthorizationHandlerContext(new [] { orIsProviderRequirement }, ClaimsPrincipal.Current, contextFilter);
            var filter  = context.Resource as AuthorizationFilterContext;

            filter.RouteData.Values.Add(RouteValues.EmployerAccountId, 1234);

            //Act
            await provider.HandleAsync(context);

            //Assert
            employerAccountAuthorizationHandler.Verify(h => h.IsEmployerAuthorised(context, true), Times.Once);
        }
Пример #2
0
        public async Task ThenFailsCheckIfEmployerIsNotAuthorised(
            [Frozen] Mock <IEmployerAccountAuthorisationHandler> employerAccountAuthorizationHandler,
            HasEmployerViewerUserRoleOrIsProviderRequirement orIsProviderRequirement,
            AuthorizationFilterContext contextFilter,
            HasEmployerViewerUserRoleOrIsProvider provider)
        {
            //Assign
            var context = new AuthorizationHandlerContext(new [] { orIsProviderRequirement }, ClaimsPrincipal.Current, contextFilter);
            var filter  = context.Resource as AuthorizationFilterContext;

            filter.RouteData.Values.Add(RouteValues.EmployerAccountId, 1234);

            employerAccountAuthorizationHandler
            .Setup(h => h.IsEmployerAuthorised(It.IsAny <AuthorizationHandlerContext>(), It.IsAny <bool>()))
            .Returns(false);

            //Act
            await provider.HandleAsync(context);

            //Assert
            Assert.IsFalse(context.HasSucceeded);
        }
Пример #3
0
        public async Task ThenPassesCheckIfProviderIsNotAuthorised(
            [Frozen] Mock <IProviderAuthorisationHandler> providerAuthorizationHandler,
            HasEmployerViewerUserRoleOrIsProviderRequirement orIsProviderRequirement,
            AuthorizationFilterContext contextFilter,
            HasEmployerViewerUserRoleOrIsProvider provider)
        {
            //Assign
            var context = new AuthorizationHandlerContext(new [] { orIsProviderRequirement }, ClaimsPrincipal.Current, contextFilter);
            var filter  = context.Resource as AuthorizationFilterContext;

            filter.RouteData.Values.Add("ukprn", 1234);

            providerAuthorizationHandler
            .Setup(h => h.IsProviderAuthorised(It.IsAny <AuthorizationHandlerContext>()))
            .Returns(true);

            //Act
            await provider.HandleAsync(context);

            //Assert
            Assert.IsTrue(context.HasSucceeded);
        }