Exemplo n.º 1
0
        public void CheckCanAccessInternalArea_ReturnsFalse_WhenUserHasNoClaims()
        {
            // Arrange
            WeeeContext weeeContext = A.Fake <WeeeContext>();

            ClaimsPrincipal principal   = new ClaimsPrincipal();
            IUserContext    userContext = A.Fake <IUserContext>();

            A.CallTo(() => userContext.Principal).Returns(principal);

            WeeeAuthorization authorization = new WeeeAuthorization(weeeContext, userContext);

            // Act
            bool result = authorization.CheckCanAccessInternalArea();

            // Assert
            Assert.Equal(false, result);
            A.CallTo(() => weeeContext.CompetentAuthorityUsers).MustNotHaveHappened();
        }
Exemplo n.º 2
0
        public void CheckCanAccessInternalArea_ActiveUserNotRequired_ReturnsTrue_WhenUserHasClaimsAndIsNotActive()
        {
            // Arrange
            IUserContext userContext = A.Fake <IUserContext>();
            WeeeContext  weeeContext = MakeFakeWeeeContext(userContext);

            ClaimsIdentity identity = new ClaimsIdentity();

            identity.AddClaim(new Claim(ClaimTypes.AuthenticationMethod, Claims.CanAccessInternalArea));

            ClaimsPrincipal principal = new ClaimsPrincipal(identity);

            A.CallTo(() => userContext.Principal).Returns(principal);

            WeeeAuthorization authorization = new WeeeAuthorization(weeeContext, userContext);

            // Act
            bool result = authorization.CheckCanAccessInternalArea(false);

            // Assert
            Assert.Equal(true, result);
            A.CallTo(() => weeeContext.CompetentAuthorityUsers).MustNotHaveHappened();
        }
        public void CheckCanAccessInternalArea_ReturnsFalse_WhenUserHasNoClaims()
        {
            // Arrange
            WeeeContext weeeContext = A.Fake<WeeeContext>();

            ClaimsPrincipal principal = new ClaimsPrincipal();
            IUserContext userContext = A.Fake<IUserContext>();
            A.CallTo(() => userContext.Principal).Returns(principal);

            WeeeAuthorization authorization = new WeeeAuthorization(weeeContext, userContext);

            // Act
            bool result = authorization.CheckCanAccessInternalArea();

            // Assert
            Assert.Equal(false, result);
            A.CallTo(() => weeeContext.CompetentAuthorityUsers).MustNotHaveHappened();
        }
        public void CheckCanAccessInternalArea_ActiveUserNotRequired_ReturnsTrue_WhenUserHasClaimsAndIsNotActive()
        {
            // Arrange
            IUserContext userContext = A.Fake<IUserContext>();
            WeeeContext weeeContext = MakeFakeWeeeContext(userContext);

            ClaimsIdentity identity = new ClaimsIdentity();
            identity.AddClaim(new Claim(ClaimTypes.AuthenticationMethod, Claims.CanAccessInternalArea));

            ClaimsPrincipal principal = new ClaimsPrincipal(identity);
            A.CallTo(() => userContext.Principal).Returns(principal);

            WeeeAuthorization authorization = new WeeeAuthorization(weeeContext, userContext);

            // Act
            bool result = authorization.CheckCanAccessInternalArea(false);

            // Assert
            Assert.Equal(true, result);
            A.CallTo(() => weeeContext.CompetentAuthorityUsers).MustNotHaveHappened();
        }