public void TestIdentitySurrogateGetRoles()
 {
     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.GetRoles(It.IsAny<IdentityId>())).
         Returns(() => new[]
                           {
                               new Account(new IdentityId(), "nativeId-ROLE-1", "role1", AccountType.Role),
                               new Account(new IdentityId(), "nativeId-ROLE-2", "role2", AccountType.Role),
                               new Account(new IdentityId(), "nativeId-ROLE-3", "role3", AccountType.Role),
                               new Account(new IdentityId(), "nativeId-ROLE-4", "role4", AccountType.Role)
                              }).Verifiable();
     mock.Setup(m=>m.GetGroups(It.IsAny<IdentityId>())).Verifiable();
     _container.Register(Component.For(typeof(IAccountFactory)).UsingFactoryMethod(() => mock.Object));
     IdentitySurrogate surrogate = new IdentitySurrogate(id);
     IEnumerable<IIdentity> roles = surrogate.InRoles();
     Assert.IsNotNull(roles);
     Assert.AreEqual(4,roles.Count());
     foreach (IIdentity identity in roles)
     {
         Assert.IsTrue(identity is IdentitySurrogate);
     }
     mock.Verify(m => m.GetRoles(It.IsAny<IdentityId>()), Times.Once());
     mock.Verify(m => m.GetAccount(It.IsAny<IdentityId>()), Times.Never());
     mock.Verify(m => m.GetGroups(It.IsAny<IdentityId>()), Times.Never());
 }
 public void TestIdentityGetMappedIdFromSurrogate()
 {
     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));
     IdentitySurrogate surrogate = new IdentitySurrogate(id);
     IdentityId mappedId = surrogate.GetMappedId();
     Assert.IsNotNull(mappedId);
     Assert.AreEqual(id,mappedId);
     mock.Verify(m => m.GetAccount(It.IsAny<IdentityId>()), Times.Never());
 }
 public void TestIdentitySurrogateCheckGroupIdentityUserAccount()
 {
     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-user", "test", AccountType.User)).Verifiable();
     _container.Register(Component.For(typeof(IAccountFactory)).UsingFactoryMethod(() => mock.Object));
     IdentitySurrogate surrogate = new IdentitySurrogate(id);
     Assert.IsFalse(surrogate.IsGroupIdentity());
     mock.Verify(m => m.GetAccount(It.IsAny<IdentityId>()),Times.Once());
 }
 public void TestCreateSurrogateGetId()
 {
     IdentityId id=new IdentityId();
     IdentitySurrogate surrogate=new IdentitySurrogate(id);
     IEnumerable<string> values =surrogate.GetValuesOfClaim(ClaimType.MappedId.ToString());
     Assert.IsNotNull(values);
     Assert.AreEqual(1,values.Count());
     Assert.AreEqual(id.ToString(),values.ElementAt(0));
 }