예제 #1
0
 public void TestClaimsIdentityGetGroups()
 {
     IdentityId id = new IdentityId();
     Mock<IAccountFactory> mock = new Mock<IAccountFactory>(MockBehavior.Strict);
     mock.Setup(m => m.GetAccount(It.IsAny<IdentityId>())).
         Returns(() => new Account(id, "nativeId-group", "test", AccountType.Group)).Verifiable();
     mock.Setup(m => m.GetGroups(It.IsAny<IdentityId>())).Verifiable();
     mock.Setup(m => m.GetRoles(It.IsAny<IdentityId>())).Verifiable();
     _container.Register(Component.For(typeof(IAccountFactory)).UsingFactoryMethod(() => mock.Object));
     IClaimsIdentity claimsIdentity = new ClaimsIdentity(id) ;
     claimsIdentity.Claims.Add(new Claim(ClaimType.Group.ToString(), new IdentityId().ToString()));
     claimsIdentity.Claims.Add(new Claim(ClaimType.Group.ToString(), new IdentityId().ToString()));
     claimsIdentity.Claims.Add(new Claim(ClaimType.Group.ToString(), new IdentityId().ToString()));
     claimsIdentity.Claims.Add(new Claim(ClaimType.Group.ToString(), new IdentityId().ToString()));
     IEnumerable<IIdentity> groups = claimsIdentity.MemberOf();
     Assert.IsNotNull(groups);
     Assert.AreEqual(4, groups.Count());
     foreach (IIdentity identity in groups)
     {
         Assert.IsTrue(identity is IdentitySurrogate);
     }
     mock.Verify(m => m.GetRoles(It.IsAny<IdentityId>()), Times.Never());
     mock.Verify(m => m.GetAccount(It.IsAny<IdentityId>()), Times.Never());
     mock.Verify(m => m.GetGroups(It.IsAny<IdentityId>()), Times.Never());
 }
예제 #2
0
 public void TestIdentityGetMappedIdFromClaimsIdentity()
 {
     IdentityId id = new IdentityId();
     Mock<IAccountFactory> mock = new Mock<IAccountFactory>(MockBehavior.Strict);
     mock.Setup(m => m.GetAccount(It.IsAny<IdentityId>())).
         Returns(() => new Account(id, "nativeId-group", "test", AccountType.Group)).Verifiable();
     _container.Register(Component.For(typeof(IAccountFactory)).UsingFactoryMethod(() => mock.Object));
     IClaimsIdentity surrogate = new ClaimsIdentity(id);
     IdentityId mappedId = surrogate.GetMappedId();
     Assert.IsNotNull(mappedId);
     Assert.AreEqual(id, mappedId);
     mock.Verify(m => m.GetAccount(It.IsAny<IdentityId>()), Times.Never());
 }