Exemple #1
0
        private string GetClaimStingValue(Func <IPrincipal, Claim> claimGetter)
        {
            NullGuard.NotNull(claimGetter, nameof(claimGetter));

            IPrincipal currentPrincipal = _principalResolver.GetCurrentPrincipal();

            Claim claim = claimGetter(currentPrincipal);

            if (claim == null || string.IsNullOrWhiteSpace(claim.Value))
            {
                return(null);
            }

            return(claim.Value);
        }
Exemple #2
0
        public void GetCurrentPrincipal_WhenCalled_AssertHttpContextWasCalledOnHttpContextAccessor()
        {
            IPrincipalResolver sut = CreateSut();

            sut.GetCurrentPrincipal();

            _httpContextAccessorMock.Verify(m => m.HttpContext, Times.Once);
        }
Exemple #3
0
        public void GetCurrentPrincipal_WhenCalledAndCurrentPrincipalIsNotNull_ReturnsCurrentPrincipal()
        {
            IPrincipal         currentPrincipal = CreatePrincipalMock().Object;
            IPrincipalResolver sut = CreateSut(currentPrincipal);

            IPrincipal result = sut.GetCurrentPrincipal();

            Assert.That(result, Is.EqualTo(currentPrincipal));
        }
Exemple #4
0
        public void GetCurrentPrincipal_WhenCalledAndCurrentPrincipalIsNull_ReturnsNull()
        {
            const IPrincipal   currentPrincipal = null;
            IPrincipalResolver sut = CreateSut(currentPrincipal);

            IPrincipal result = sut.GetCurrentPrincipal();

            Assert.That(result, Is.Null);
        }
Exemple #5
0
        public void GetCurrentPrincipal_WhenCalled_ReturnsPrincipalFromHttpContext()
        {
            ClaimsPrincipal    claimsPrincipal = new ClaimsPrincipal();
            IPrincipalResolver sut             = CreateSut(claimsPrincipal);

            IPrincipal result = sut.GetCurrentPrincipal();

            Assert.That(result, Is.EqualTo(claimsPrincipal));
        }