public void GetNameIdentifier_WhenCalled_AssertGetCurrentPrincipalWasCalledOnPrincipalResolver()
        {
            IClaimResolver sut = CreateSut();

            sut.GetNameIdentifier();

            _principalResolverMock.Verify(m => m.GetCurrentPrincipal(), Times.Once);
        }
        public void GetNameIdentifier_WhenCalledAndPrincipalDoesNotHaveNameIdentifierClaim_ReturnsNull()
        {
            IPrincipal     principal = CreateClaimsPrincipal(new[] { new Claim(_fixture.Create <string>(), _fixture.Create <string>()) });
            IClaimResolver sut       = CreateSut(principal);

            string result = sut.GetNameIdentifier();

            Assert.That(result, Is.Null);
        }
        public void GetNameIdentifier_WhenCalledAndPrincipalHasNameIdentifierClaim_ReturnsNameIdentifier()
        {
            string         nameIdentifier = _fixture.Create <string>();
            IPrincipal     principal      = CreateClaimsPrincipal(new[] { new Claim(_fixture.Create <string>(), _fixture.Create <string>()), ClaimHelper.CreateNameIdentifierClaim(nameIdentifier) });
            IClaimResolver sut            = CreateSut(principal);

            string result = sut.GetNameIdentifier();

            Assert.That(result, Is.EqualTo(nameIdentifier));
        }
        private string GetUserIdentifier()
        {
            string userIdentifier = _claimResolver.GetMailAddress();

            if (string.IsNullOrWhiteSpace(userIdentifier) == false)
            {
                return(userIdentifier);
            }

            userIdentifier = _claimResolver.GetNameIdentifier();
            if (string.IsNullOrWhiteSpace(userIdentifier) == false)
            {
                return(userIdentifier);
            }

            throw new IntranetExceptionBuilder(ErrorCode.UnableToResolveUserIdentifier).Build();
        }