public void Arrange() { _configuration = new EmployerAccountsConfiguration { SupportConsoleUsers = SupportConsoleUsers }; _mockAuthenticationService = new Mock <IAuthenticationService>(); AuthorizationContextTestsFixture = new AuthorizationContextTestsFixture(); MockIAuthorisationResourceRepository = new Mock <IAuthorisationResourceRepository>(); Options = new List <string>(); _userContext = new UserContext(_mockAuthenticationService.Object, _configuration); SutDefaultAuthorizationHandler = new DefaultAuthorizationHandler(MockIAuthorisationResourceRepository.Object, _userContext); _testAuthorizationResource = new AuthorizationResource { Name = "Test", Value = Guid.NewGuid().ToString() }; ResourceList = new List <AuthorizationResource> { _testAuthorizationResource }; MockIAuthorisationResourceRepository.Setup(x => x.Get(It.IsAny <ClaimsIdentity>())).Returns(ResourceList); AuthorizationContext = new AuthorizationContext(); }
public void GetAuthorizationResult_WhenTheUserIsConsoleUser_ThenAllowTheUserToViewTeamPage(string role) { //Arrange AuthorizationContextTestsFixture.SetData(_testAuthorizationResource.Value, role); //Act AuthorizationContextTestsFixture.AuthorizationContext.ToString(); //Assert var authorizationResult = SutDefaultAuthorizationHandler.GetAuthorizationResult(Options, AuthorizationContextTestsFixture.AuthorizationContext); authorizationResult.Result.IsAuthorized.Should().Be(true); }
public void GetAuthorizationResult_WhenTheUserInRoleINotSupportConsoleAndClaimsSet_ThenAuthorizedTheUser() { //Arrange AuthorizationContextTestsFixture.SetDataNotSupportConsoleUser(); //Act AuthorizationContextTestsFixture.AuthorizationContext.ToString(); //Assert var authorizationResult = SutDefaultAuthorizationHandler.GetAuthorizationResult(Options, AuthorizationContextTestsFixture.AuthorizationContext); authorizationResult.Result.IsAuthorized.Should().Be(true); }
public void GetAuthorizationResult_WhenTheUserInRoleIsSupportConsoleAndResourceNotSet_ThenAuthorizedTheUser(string role) { //Arrange AuthorizationContextTestsFixture.SetDataSupportConsoleUserNoResource(role); _mockAuthenticationService.Setup(m => m.HasClaim(ClaimsIdentity.DefaultRoleClaimType, role)).Returns(true); //Act AuthorizationContextTestsFixture.AuthorizationContext.ToString(); //Assert var authorizationResult = SutDefaultAuthorizationHandler.GetAuthorizationResult(Options, AuthorizationContextTestsFixture.AuthorizationContext); authorizationResult.Result.IsAuthorized.Should().Be(false); }