public void EnsureCanAccessInternalArea_ThrowsSecurityException_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
            Action action = () => authorization.EnsureCanAccessInternalArea();

            // Assert
            Assert.Throws(typeof(SecurityException), action);
            A.CallTo(() => weeeContext.CompetentAuthorityUsers).MustNotHaveHappened();
        }
        public void EnsureCanAccessInternalArea_ThrowsSecurityException_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
            Action action = () => authorization.EnsureCanAccessInternalArea();

            // Assert
            Assert.Throws(typeof(SecurityException), action);
            A.CallTo(() => weeeContext.CompetentAuthorityUsers).MustNotHaveHappened();
        }
        public void EnsureCanAccessInternalArea_ActiveUserNotRequired_DoesNotThrowSecurityException_WhenUserHasClaimsAndIsNotActive()
        {
            // Arrange
            IUserContext userContext = A.Fake<IUserContext>();
            WeeeContext weeeContext = MakeFakeWeeeContext(userContext, userStatusActive: false);

            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
            var ex = Record.Exception(() => authorization.EnsureCanAccessInternalArea(false));

            // Assert
            Assert.Null(ex);
            A.CallTo(() => weeeContext.CompetentAuthorityUsers).MustNotHaveHappened();
        }
        public void EnsureCanAccessInternalArea_ActiveUserNotRequired_DoesNotThrowSecurityException_WhenUserHasClaimsAndIsNotActive()
        {
            // Arrange
            IUserContext userContext = A.Fake <IUserContext>();
            WeeeContext  weeeContext = MakeFakeWeeeContext(userContext, userStatusActive: false);

            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
            var ex = Record.Exception(() => authorization.EnsureCanAccessInternalArea(false));

            // Assert
            Assert.Null(ex);
            A.CallTo(() => weeeContext.CompetentAuthorityUsers).MustNotHaveHappened();
        }