Exemple #1
0
        public void DefaultUniqueClaimTypes_NotPresent_SerializesAllClaimTypes()
        {
            var identity = new MockClaimsIdentity();

            identity.AddClaim(ClaimTypes.Email, "*****@*****.**");
            identity.AddClaim(ClaimTypes.GivenName, "some");
            identity.AddClaim(ClaimTypes.Surname, "one");
            identity.AddClaim(ClaimTypes.NameIdentifier, String.Empty);

            // Arrange
            var claimsIdentity = (ClaimsIdentity)identity;

            // Act
            var identiferParameters = DefaultClaimUidExtractor.GetUniqueIdentifierParameters(claimsIdentity)
                                      .ToArray();
            var claims = claimsIdentity.Claims.ToList();

            claims.Sort((a, b) => string.Compare(a.Type, b.Type, StringComparison.Ordinal));

            // Assert
            int index = 0;

            foreach (var claim in claims)
            {
                Assert.True(String.Equals(identiferParameters[index++], claim.Type, StringComparison.Ordinal));
                Assert.True(String.Equals(identiferParameters[index++], claim.Value, StringComparison.Ordinal));
            }
        }
Exemple #2
0
        public void DefaultUniqueClaimTypes_NotPresent_SerializesAllClaimTypes()
        {
            var identity = new MockClaimsIdentity();
            identity.AddClaim(ClaimTypes.Email, "*****@*****.**");
            identity.AddClaim(ClaimTypes.GivenName, "some");
            identity.AddClaim(ClaimTypes.Surname, "one");
            identity.AddClaim(ClaimTypes.NameIdentifier, String.Empty);

            // Arrange
            var claimsIdentity = (ClaimsIdentity)identity;

            // Act
            var identiferParameters = DefaultClaimUidExtractor.GetUniqueIdentifierParameters(claimsIdentity)
                                                              .ToArray();
            var claims = claimsIdentity.Claims.ToList();
            claims.Sort((a, b) => string.Compare(a.Type, b.Type, StringComparison.Ordinal));

            // Assert
            int index = 0;
            foreach (var claim in claims)
            {
                Assert.True(String.Equals(identiferParameters[index++], claim.Type, StringComparison.Ordinal));
                Assert.True(String.Equals(identiferParameters[index++], claim.Value, StringComparison.Ordinal));
            }
        }
Exemple #3
0
        public void DefaultUniqueClaimTypes_Present()
        {
            // Arrange
            var identity = new MockClaimsIdentity();

            identity.AddClaim("fooClaim", "fooClaimValue");
            identity.AddClaim(ClaimTypes.NameIdentifier, "nameIdentifierValue");

            // Act
            var uniqueIdentifierParameters = DefaultClaimUidExtractor.GetUniqueIdentifierParameters(identity);

            // Assert
            Assert.Equal(new string[]
            {
                ClaimTypes.NameIdentifier,
                "nameIdentifierValue",
            }, uniqueIdentifierParameters);
        }
Exemple #4
0
        public void DefaultUniqueClaimTypes_Present()
        {
            // Arrange
            var identity = new MockClaimsIdentity();
            identity.AddClaim("fooClaim", "fooClaimValue");
            identity.AddClaim(ClaimTypes.NameIdentifier, "nameIdentifierValue");

            // Act
            var uniqueIdentifierParameters = DefaultClaimUidExtractor.GetUniqueIdentifierParameters(identity);

            // Assert
            Assert.Equal(new string[]
            {
                ClaimTypes.NameIdentifier,
                "nameIdentifierValue",
            }, uniqueIdentifierParameters);
        }