Ejemplo n.º 1
0
 public void TestIdentitySurrogateGetGroups()
 {
     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>())).
         Returns(() => new[]
                           {
                               new Account(new IdentityId(), "nativeId-ROLE-1", "role1", AccountType.Group),
                               new Account(new IdentityId(), "nativeId-ROLE-2", "role2", AccountType.Group),
                               new Account(new IdentityId(), "nativeId-ROLE-3", "role3", AccountType.Group),
                               new Account(new IdentityId(), "nativeId-ROLE-4", "role4", AccountType.Group)
                              }).Verifiable();
     mock.Setup(m => m.GetRoles(It.IsAny<IdentityId>())).Verifiable();
     _container.Register(Component.For(typeof(IAccountFactory)).UsingFactoryMethod(() => mock.Object));
     IdentitySurrogate surrogate = new IdentitySurrogate(id);
     IEnumerable<IIdentity> groups = surrogate.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.Once());
 }