示例#1
0
        public void Can_Remove_Section_For_Group()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                UserGroupRepository repository = CreateRepository(provider);

                IUserGroup[] groups = CreateAndCommitMultipleUserGroups(repository);

                // Act

                // add and remove a few times, this tests the internal collection
                groups[0].RemoveAllowedSection("content");
                groups[0].RemoveAllowedSection("content");
                groups[0].AddAllowedSection("content");
                groups[0].RemoveAllowedSection("content");

                groups[1].RemoveAllowedSection("media");
                groups[1].RemoveAllowedSection("media");

                repository.Save(groups[0]);
                repository.Save(groups[1]);
                scope.Complete();

                // Assert
                IUserGroup[] result = repository.GetMany((int)groups[0].Id, (int)groups[1].Id).ToArray();
                Assert.AreEqual(1, result[0].AllowedSections.Count());
                Assert.AreEqual("media", result[0].AllowedSections.First());
                Assert.AreEqual(1, result[1].AllowedSections.Count());
                Assert.AreEqual("content", result[1].AllowedSections.First());
            }
        }
示例#2
0
        public void Can_Add_Section_ForGroup()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                UserGroupRepository repository = CreateRepository(provider);

                IUserGroup[] groups = CreateAndCommitMultipleUserGroups(repository);

                // Act

                // add and remove a few times, this tests the internal collection
                groups[0].ClearAllowedSections();
                groups[0].AddAllowedSection("content");
                groups[0].AddAllowedSection("media");
                groups[0].RemoveAllowedSection("content");
                groups[0].AddAllowedSection("content");
                groups[0].AddAllowedSection("settings");

                // add the same even though it's already there
                groups[0].AddAllowedSection("content");

                groups[1].ClearAllowedSections();
                groups[1].AddAllowedSection("developer");

                groups[2].ClearAllowedSections();

                repository.Save(groups[0]);
                repository.Save(groups[1]);
                repository.Save(groups[2]);
                scope.Complete();

                for (int i = 0; i < 3; i++)
                {
                    Assert.IsNotNull(repository.Get(groups[i].Id));
                }

                // Assert
                IUserGroup[] result = repository.GetMany(groups[0].Id, groups[1].Id, groups[2].Id).ToArray();
                Assert.AreEqual(3, result.Length);

                Assert.AreEqual(3, result[0].AllowedSections.Count());
                Assert.IsTrue(result[0].AllowedSections.Contains("content"));
                Assert.IsTrue(result[0].AllowedSections.Contains("media"));
                Assert.IsTrue(result[0].AllowedSections.Contains("settings"));
                Assert.AreEqual(1, result[1].AllowedSections.Count());
                Assert.IsTrue(result[1].AllowedSections.Contains("developer"));
                Assert.AreEqual(0, result[2].AllowedSections.Count());
            }
        }
示例#3
0
        public void Can_Perform_GetAll_On_UserGroupRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                UserGroupRepository repository = CreateRepository(provider);

                CreateAndCommitMultipleUserGroups(repository);

                // Act
                IEnumerable <IUserGroup> result = repository.GetMany();

                // Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result.Any(), Is.True);
                Assert.That(result.Count(), Is.GreaterThanOrEqualTo(3));
            }
        }
示例#4
0
        public void Can_Perform_GetAll_By_Param_Ids_On_UserGroupRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                UserGroupRepository repository = CreateRepository(provider);

                IUserGroup[] userGroups = CreateAndCommitMultipleUserGroups(repository);

                // Act
                IEnumerable <IUserGroup> result = repository.GetMany(userGroups[0].Id, userGroups[1].Id);

                // Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result.Any(), Is.True);
                Assert.That(result.Count(), Is.EqualTo(2));
            }
        }