예제 #1
0
		public void IIdentityCtorNonClaimsIdentityWorks ()
		{
			var id = new TestIdentity {
				Name = "test_name", 
				AuthenticationType = "test_auth"
			};
			var p = new ClaimsPrincipal (id);

			Assert.IsNotNull (p.Identities, "#1");
			Assert.AreEqual (1, p.Identities.Count (), "#2");

			Assert.AreNotEqual (id, p.Identities.First (), "#3");
			Assert.AreNotEqual (id, p.Identity, "#4");
			Assert.AreEqual (id.Name, p.Identity.Name, "#5");

			Assert.IsNotNull (p.Claims, "#6");
			Assert.AreEqual (1, p.Claims.Count (), "#7");
			Assert.IsTrue (p.Claims.Any (claim => claim.Type == ClaimsIdentity.DefaultNameClaimType && claim.Value == "test_name"), "#8");
		}
        public void IIdentityCtorNonClaimsIdentityWorks()
        {
            var id = new TestIdentity {
                Name = "test_name",
                AuthenticationType = "test_auth"
            };
            var p = new ClaimsPrincipal(id);

            Assert.IsNotNull(p.Identities, "#1");
            Assert.AreEqual(1, p.Identities.Count(), "#2");

            Assert.AreNotEqual(id, p.Identities.First(), "#3");
            Assert.AreNotEqual(id, p.Identity, "#4");
            Assert.AreEqual(id.Name, p.Identity.Name, "#5");

            Assert.IsNotNull(p.Claims, "#6");
            Assert.AreEqual(1, p.Claims.Count(), "#7");
            Assert.IsTrue(p.Claims.Any(claim => claim.Type == ClaimsIdentity.DefaultNameClaimType && claim.Value == "test_name"), "#8");
        }
예제 #3
0
		public void IdentityEnumClaimsCtorNonClaimsIdentityClaimsWorks ()
		{
			var baseId = new TestIdentity {
				Name = "base_name", AuthenticationType = "TestId_AuthType"
			};

			var id = new ClaimsIdentity (
					   baseId,
					   new [] {
					new Claim ("claim_type", "claim_value"),
					new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
					new Claim ("claim_role_type", "claim_role_value"), 
				});

			Assert.AreEqual ("TestId_AuthType", id.AuthenticationType, "#1");

			Assert.IsNull (id.Actor, "#2");
			Assert.IsNull (id.BootstrapContext, "#3");
			Assert.IsNotNull (id.Claims, "#4");
			Assert.AreEqual (4, id.Claims.Count (), "#5");
			Assert.AreEqual (2, id.Claims.Count (_ => _.Type == ClaimsIdentity.DefaultNameClaimType), "#5b");
			Assert.IsTrue (id.IsAuthenticated, "#6");
			Assert.IsNull (id.Label, "#7");
			Assert.AreEqual ("base_name", id.Name, "#8");
			Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
			Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
		}