Esempio n. 1
0
        public void EqualClaimDescriptorTest(string type, string value, string valueType, string issuer, string originalIssuer)
        {
            var a = new ClaimDescriptor(type, value, valueType, issuer, originalIssuer);
            var b = new ClaimDescriptor(type, value, valueType, issuer, originalIssuer);

            Assert.Equal(type, a.Type);
            Assert.Equal(value, a.Value);
            Assert.Equal(valueType, a.ValueType);
            Assert.Equal(issuer, a.Issuer);
            Assert.Equal(originalIssuer, a.OriginalIssuer);
            Assert.Equal(a, a);
            Assert.Equal(a, b);
            Assert.True(((object)a).Equals(b));
            Assert.False(((object)a).Equals(null));
            Assert.False(((object)a).Equals(2));
            Assert.Equal(a.GetHashCode(), b.GetHashCode());
        }
Esempio n. 2
0
        public void ClaimCollectionTest()
        {
            var a          = new ClaimDescriptor("a", "b", "c", "d", "e");
            var b          = new ClaimDescriptor("a", "b", "c", "d", "e");
            var c          = new ClaimDescriptor("x", "b", "c", "d", "e");
            var collection = new ClaimCollection(null, null, null, null);

            Assert.Equal(ClaimTypes.Name, collection.NameClaimType);
            Assert.Equal(ClaimTypes.Role, collection.RoleClaimType);
            Assert.Null(collection.AuthenticationType);
            var count = collection.Count;

            Assert.Equal(0, count);
            Assert.True(HashSet <ClaimDescriptor> .CreateSetComparer().Equals(new HashSet <ClaimDescriptor>(collection), new HashSet <ClaimDescriptor>()));
            Assert.True(HashSet <ClaimDescriptor> .CreateSetComparer().Equals(
                            new HashSet <ClaimDescriptor>(collection),
                            new HashSet <ClaimDescriptor>(Assert.IsType <ClaimCollection>(Deserialize(Serialize(collection))))
                            ));
            collection = new ClaimCollection(new [] { a, c });
            Assert.Contains(a, collection);
            Assert.Contains(c, collection);
            Assert.Equal(ClaimTypes.Name, collection.NameClaimType);
            Assert.Equal(ClaimTypes.Role, collection.RoleClaimType);
            Assert.Equal(2, collection.Count);
            Assert.True(HashSet <ClaimDescriptor> .CreateSetComparer().Equals(new HashSet <ClaimDescriptor>(collection), new HashSet <ClaimDescriptor>(new [] { a, c })));

            Assert.True(HashSet <ClaimDescriptor> .CreateSetComparer().Equals(
                            new HashSet <ClaimDescriptor>(collection),
                            new HashSet <ClaimDescriptor>(Assert.IsType <ClaimCollection>(Deserialize(Serialize(collection))))
                            ));

            collection = new ClaimCollection(new [] { a, b, c });
            Assert.Contains(a, collection);
            Assert.Contains(c, collection);
            Assert.Equal(ClaimTypes.Name, collection.NameClaimType);
            Assert.Equal(ClaimTypes.Role, collection.RoleClaimType);
            Assert.Equal(2, collection.Count);
            Assert.True(HashSet <ClaimDescriptor> .CreateSetComparer().Equals(new HashSet <ClaimDescriptor>(collection), new HashSet <ClaimDescriptor>(new [] { a, c })));

            Assert.True(collection.HasClaim(x => x.Equals(a)));
            Assert.True(collection.HasClaim(x => x.Equals(b)));
        }
Esempio n. 3
0
        public void ClaimDescriptorTest()
        {
            var exn = Assert.Throws <ArgumentNullException>(() => new ClaimDescriptor(null, null));

            Assert.Equal("type", exn.ParamName);
            Assert.NotEqual(new ClaimDescriptor("x", "b", "c", "d", "e"), new ClaimDescriptor("a", "b", "c", "d", "e"));
            Assert.NotEqual(new ClaimDescriptor("a", "x", "c", "d", "e"), new ClaimDescriptor("a", "b", "c", "d", "e"));
            Assert.NotEqual(new ClaimDescriptor("a", "b", "x", "d", "e"), new ClaimDescriptor("a", "b", "c", "d", "e"));
            Assert.NotEqual(new ClaimDescriptor("a", "b", "c", "x", "e"), new ClaimDescriptor("a", "b", "c", "d", "e"));
            Assert.NotEqual(new ClaimDescriptor("a", "b", "c", "d", "x"), new ClaimDescriptor("a", "b", "c", "d", "e"));
            Assert.NotEqual(new ClaimDescriptor("a", null, "c", "d", "e"), new ClaimDescriptor("a", "b", "c", "d", "e"));
            Assert.NotEqual(new ClaimDescriptor("a", "b", null, "d", "e"), new ClaimDescriptor("a", "b", "c", "d", "e"));
            Assert.NotEqual(new ClaimDescriptor("a", "b", "c", null, "e"), new ClaimDescriptor("a", "b", "c", "d", "e"));
            Assert.NotEqual(new ClaimDescriptor("a", "b", "c", "d", null), new ClaimDescriptor("a", "b", "c", "d", "e"));
            var desc  = new ClaimDescriptor("a", "b", "c", "d", "e");
            var descx = new ClaimDescriptor("a", "b", "c", "d", "e");

            Assert.Equal(desc, Deserialize(Serialize(desc)));
            exn = Assert.Throws <ArgumentNullException>(() => desc.Update(null));
            Assert.Equal("update", exn.ParamName);
            var updated = desc.Update(b => b.Value = "x");

            Assert.NotSame(desc, updated);
            Assert.NotEqual(desc, updated);
            Assert.Equal("x", updated.Value);
            Assert.True(desc == descx);
            Assert.False((ClaimDescriptor)null == desc);
            Assert.False(desc == (ClaimDescriptor)null);
            Assert.True((ClaimDescriptor)null == (ClaimDescriptor)null);
            Assert.False(desc != descx);
            Assert.True((ClaimDescriptor)null != desc);
            Assert.True(desc != (ClaimDescriptor)null);
            Assert.False((ClaimDescriptor)null != (ClaimDescriptor)null);

            exn = Assert.Throws <ArgumentNullException>(() => new ClaimDescriptorBuilder().Build());
            Assert.Equal("type", exn.ParamName);
        }
 public ClaimDescriptorBuilder(ClaimDescriptor claimDescriptor)
     : this(claimDescriptor.Type, claimDescriptor.Value, claimDescriptor.ValueType, claimDescriptor.Issuer, claimDescriptor.OriginalIssuer)
 {
 }