示例#1
0
        public void AddRemoveMember()
        {
            testContext.CreateAdminTeam();
            var            page      = CreateNestedPage();
            PageController pc        = new PageController();
            var            children  = pc.GetChildren(page.Id, testContext.adminUsers[0]);
            var            subPage   = children.Item1[0];
            var            children2 = pc.GetChildren(subPage.Id, testContext.adminUsers[0]);
            var            att       = children2.Item2[0];

            controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.adminUsers[0]);
            var fetchedPage = controller.Get(att.Id, testContext.adminUsers[0]);

            Assert.True(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.adminUsers[0]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[0]);
            Assert.False(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));

            // Admin Team Writer
            controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.adminUsers[1]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[1]);
            Assert.True(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.adminUsers[1]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[1]);
            Assert.False(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));

            // Admin Team Nested reader team writer
            controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.adminUsers[2]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[2]);
            Assert.True(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.adminUsers[2]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[2]);
            Assert.False(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));

            // Admin Team Writer
            controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.adminUsers[3]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[3]);
            Assert.True(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.adminUsers[3]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[3]);
            Assert.False(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));

            // Admin Team Nested reader team writer
            controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.adminUsers[4]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[4]);
            Assert.True(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.adminUsers[4]);
            fetchedPage = controller.Get(att.Id, testContext.adminUsers[4]);
            Assert.False(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));

            // Team Owner reader team writer
            controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.users[0]);
            fetchedPage = controller.Get(att.Id, testContext.users[0]);
            Assert.True(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.users[0]);
            fetchedPage = controller.Get(att.Id, testContext.users[0]);
            Assert.False(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));

            // Team Writer
            controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.users[10]);
            fetchedPage = controller.Get(att.Id, testContext.users[10]);
            Assert.True(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.users[10]);
            fetchedPage = controller.Get(att.Id, testContext.users[10]);
            Assert.False(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));

            // Team Reader
            Assert.Throws <NotAuthorized>(() => controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.users[11]));
            fetchedPage = controller.Get(att.Id, testContext.users[11]);
            Assert.False(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.users[0]);
            Assert.Throws <NotAuthorized>(() => controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.users[11]));
            fetchedPage = controller.Get(att.Id, testContext.users[11]);
            Assert.True(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.users[0]);

            // Nested Team Writer writer
            controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.users[3]);
            fetchedPage = controller.Get(att.Id, testContext.users[3]);
            Assert.True(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.users[3]);
            fetchedPage = controller.Get(att.Id, testContext.users[3]);
            Assert.False(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));

            // Nested Team Writer reader
            controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.users[4]);
            fetchedPage = controller.Get(att.Id, testContext.users[4]);
            Assert.True(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.users[4]);
            fetchedPage = controller.Get(att.Id, testContext.users[4]);
            Assert.False(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));

            // Nested Team Reader writer
            Assert.Throws <NotAuthorized>(() => controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.users[5]));
            fetchedPage = controller.Get(att.Id, testContext.users[5]);
            Assert.False(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.users[0]);
            Assert.Throws <NotAuthorized>(() => controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.users[5]));
            fetchedPage = controller.Get(att.Id, testContext.users[5]);
            Assert.True(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.users[0]);

            // Nested Team reader readerder");
            Assert.Throws <NotAuthorized>(() => controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.users[6]));
            fetchedPage = controller.Get(att.Id, testContext.users[6]);
            Assert.False(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.users[0]);
            Assert.Throws <NotAuthorized>(() => controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.users[6]));
            fetchedPage = controller.Get(att.Id, testContext.users[6]);
            Assert.True(fetchedPage.Acl.admins.ContainsKey(testContext.users[20].Id));
            controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.users[0]);

            Assert.Throws <NotAuthorized>(() => controller.AddAdmin(att.Id, testContext.users[20].Id, testContext.users[7]));
            Assert.Throws <NotAuthorized>(() => fetchedPage = controller.Get(att.Id, testContext.users[7]));
            Assert.Throws <NotAuthorized>(() => controller.RemoveMember(att.Id, testContext.users[20].Id, testContext.users[7]));
        }