public void Resolve_OneGroup()
        {
            //Arrange
            var group1 = new EasyADGroup {
                Id = 1, Name = "Group A", Sections = "content;media;", UserType = 1
            };
            var groups = new List <EasyADGroup> {
                group1
            };
            var expected = new[] { "content", "media" };

            //Act
            var actual = SectionResolver.Resolve(groups);

            //Assert
            Assert.AreEqual(2, actual.Length);
        }
Exemple #2
0
        protected void ConfigureUserRights(IUser backofficeUser, IEnumerable <EasyADGroup> groupsUserIsIn)
        {
            var desiredSections = SectionResolver.Resolve(groupsUserIsIn);
            var newUserType     = UserTypeResolver.Resolve(groupsUserIsIn, AllUserTypes);

            var addSections    = desiredSections.Except(backofficeUser.AllowedSections).ToList();
            var removeSections = backofficeUser.AllowedSections.Except(desiredSections).ToList();

            if (newUserType.Id != backofficeUser.UserType.Id || addSections.Any() || removeSections.Any())
            {
                addSections.ForEach(s => backofficeUser.AddAllowedSection(s));
                removeSections.ForEach(s => backofficeUser.RemoveAllowedSection(s));
                backofficeUser.UserType = newUserType;
            }

            if (backofficeUser.IsDirty())
            {
                _userService.Save(backofficeUser);
            }
        }
        public void Resolve_TwoGroups()
        {
            //Arrange
            var group1 = new EasyADGroup {
                Id = 1, Name = "Group A", Sections = "content;media;", UserType = 1
            };
            var group2 = new EasyADGroup {
                Id = 2, Name = "Group B", Sections = "translation;", UserType = 3
            };
            var groups = new List <EasyADGroup> {
                group1, group2
            };
            var expected = new[] { "content", "media", "translation" };

            //Act
            var actual = SectionResolver.Resolve(groups);

            //Assert
            Assert.AreEqual(3, actual.Length);
            Assert.IsTrue(expected.All(e => actual.Contains(e)));
        }