Esempio n. 1
0
        public void Can_Perform_Update_On_UserGroupRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

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

                UserGroup userGroup = UserGroupBuilder.CreateUserGroup();
                repository.Save(userGroup);

                // Act
                IUserGroup resolved = repository.Get((int)userGroup.Id);
                resolved.Name        = "New Name";
                resolved.Permissions = new[] { "Z", "Y", "X" };
                repository.Save(resolved);
                scope.Complete();
                IUserGroup updatedItem = repository.Get((int)userGroup.Id);

                // Assert
                Assert.That(updatedItem.Id, Is.EqualTo(resolved.Id));
                Assert.That(updatedItem.Name, Is.EqualTo(resolved.Name));
                Assert.That(updatedItem.Permissions, Is.EqualTo(resolved.Permissions));
            }
        }
Esempio n. 2
0
        public void Can_Update_Section_For_Group()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

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

                IUserGroup[] groups = CreateAndCommitMultipleUserGroups(repository);

                // Act
                groups[0].RemoveAllowedSection("content");
                groups[0].AddAllowedSection("settings");

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

                // Assert
                IUserGroup result = repository.Get(groups[0].Id);
                Assert.AreEqual(2, result.AllowedSections.Count());
                Assert.IsTrue(result.AllowedSections.Contains("settings"));
                Assert.IsTrue(result.AllowedSections.Contains("media"));
            }
        }
Esempio n. 3
0
        public void Can_Perform_Get_On_UserGroupRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

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

                UserGroup userGroup = UserGroupBuilder.CreateUserGroup();
                repository.Save(userGroup);
                scope.Complete();

                // Act
                IUserGroup resolved = repository.Get((int)userGroup.Id);

                // Assert
                Assert.That(resolved.Id, Is.EqualTo(userGroup.Id));
                //// Assert.That(resolved.CreateDate, Is.GreaterThan(DateTime.MinValue));
                //// Assert.That(resolved.UpdateDate, Is.GreaterThan(DateTime.MinValue));
                Assert.That(resolved.Name, Is.EqualTo(userGroup.Name));
                Assert.That(resolved.Alias, Is.EqualTo(userGroup.Alias));
                Assert.That(resolved.Permissions, Is.EqualTo(userGroup.Permissions));
            }
        }
Esempio n. 4
0
        public void Can_Perform_Delete_On_UserGroupRepository()
        {
            IScopeProvider provider = ScopeProvider;

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

                UserGroup userGroup = UserGroupBuilder.CreateUserGroup();

                // Act
                repository.Save(userGroup);

                int id = userGroup.Id;

                var repository2 = new UserGroupRepository((IScopeAccessor)provider, global::Umbraco.Cms.Core.Cache.AppCaches.Disabled, LoggerFactory.CreateLogger <UserGroupRepository>(), LoggerFactory, ShortStringHelper);
                repository2.Delete(userGroup);
                scope.Complete();

                IUserGroup resolved = repository2.Get((int)id);

                // Assert
                Assert.That(resolved, Is.Null);
            }
        }
        public void Can_Perform_Delete_On_UserGroupRepository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = CreateRepository(unitOfWork))
            {
                var userGroup = MockedUserGroup.CreateUserGroup();

                // Act
                repository.AddOrUpdate(userGroup);
                unitOfWork.Commit();
                var id = userGroup.Id;

                using (var repository2 = new UserGroupRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax))
                {
                    repository2.Delete(userGroup);
                    unitOfWork.Commit();

                    var resolved = repository2.Get(id);

                    // Assert
                    Assert.That(resolved, Is.Null);
                }
            }
        }
        public void Can_Perform_Delete_On_UserGroupRepository()
        {
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = ScopeProvider.CreateScope())
            {
                var repository = CreateRepository(provider);

                var userGroup = MockedUserGroup.CreateUserGroup();

                // Act
                repository.Save(userGroup);

                var id = userGroup.Id;

                var repository2 = new UserGroupRepository((IScopeAccessor)provider, Core.Cache.CacheHelper.Disabled, Logger);
                repository2.Delete(userGroup);
                scope.Complete();

                var resolved = repository2.Get(id);

                // Assert
                Assert.That(resolved, Is.Null);
            }
        }
Esempio n. 7
0
        public ActionResult Create(UserModel model)
        {
            if (!ModelState.IsValid)
            {
                return(ReturnView(model));
            }

            var user = new User
            {
                FIO            = model.FIO,
                Age            = model.Age,
                UserName       = model.UserName,
                Email          = model.Email,
                CreationDate   = DateTime.Now,
                BirthDate      = model.BirthDate,
                CreationAuthor = GetCurrentUser(),
                UserGroup      = userGroupRepository.Get(Convert.ToInt64(model.UserGroup)) ?? null,
                AvatarFile     = model.Avatar != null ? model.Avatar.BinaryFile : null
            };
            var res = UserManager.CreateAsync(user, model.Password);

            if (res.Result == IdentityResult.Success)
            {
                if (model.Avatar != null)
                {
                    GetFileProvider().Save(model.Avatar.BinaryFile, model.Avatar.PostedFile.InputStream);
                }
                return(RedirectToAction("List"));
            }
            return(ReturnView(model));
        }
Esempio n. 8
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());
            }
        }
Esempio n. 9
0
        public void Can_Perform_GetByQuery_On_UserGroupRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

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

                CreateAndCommitMultipleUserGroups(repository);

                // Act
                IQuery <IUserGroup>      query  = provider.CreateQuery <IUserGroup>().Where(x => x.Alias == "testGroup1");
                IEnumerable <IUserGroup> result = repository.Get(query);

                // Assert
                Assert.That(result.Count(), Is.GreaterThanOrEqualTo(1));
            }
        }
Esempio n. 10
0
        public void Can_Verify_Fresh_Entity_Is_Not_Dirty()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

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

                UserGroup userGroup = UserGroupBuilder.CreateUserGroup();
                repository.Save(userGroup);
                scope.Complete();

                // Act
                IUserGroup resolved = repository.Get((int)userGroup.Id);
                bool       dirty    = ((UserGroup)resolved).IsDirty();

                // Assert
                Assert.That(dirty, Is.False);
            }
        }