示例#1
0
        public void TestLocalGroupDeleteByName()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            NTLocalUser  user  = null;
            NTLocalGroup group = null;

            try {
                group = host.CreateLocalGroup(GenerateGroupName(host), null);
                user  = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");
                group.AddLocalMember(user.Name);
                Assert.IsTrue(ContainsObjectByName(group.GetLocalMembers(), user.Name));
                group.DeleteLocalMember(user.Name);
                CollectionAssert.IsEmpty(group.GetLocalMembers());
            } finally {
                try {
                    if (user != null)
                    {
                        user.Delete();
                    }
                } catch {
                }

                try {
                    if (user != null)
                    {
                        group.Delete();
                    }
                } catch {
                }
            }
        }
示例#2
0
        public void TestLocalGroupDeleteMultipleMembersWithWithUserMembershipVerify()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            NTLocalUser  user1  = null;
            NTLocalUser  user2  = null;
            NTLocalGroup group1 = null;
            NTLocalGroup group2 = null;
            NTLocalGroup group3 = null;

            try {
                group1 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group1);
                group2 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group2);
                group3 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group3);

                user1 = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");
                user2 = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");

                group1.AddLocalMember(user1.Name);
                group1.AddLocalMember(user2.Name);
                group2.AddLocalMember(user1.Name);
                group3.AddLocalMember(user2.Name);

                group1.DeleteLocalMember(user1.Name);
                group1.DeleteLocalMember(user2.Name);
                group2.DeleteLocalMember(user1.Name);
                group3.DeleteLocalMember(user2.Name);


                NTLocalGroup[] user1Membership = user1.GetMembership();
                Assert.IsNotNull(user1Membership);
                Assert.AreEqual(0, user1Membership.Length);

                NTLocalGroup[] user2Membership = user2.GetMembership();
                Assert.IsNotNull(user2Membership);
                Assert.AreEqual(0, user2Membership.Length);
            } finally {
                try {
                    if (user1 != null)
                    {
                        user1.Delete();
                    }
                } catch {
                }

                try {
                    if (user2 != null)
                    {
                        user2.Delete();
                    }
                } catch {
                }

                try {
                    if (group1 != null)
                    {
                        group1.Delete();
                    }
                } catch {
                }


                try {
                    if (group2 != null)
                    {
                        group2.Delete();
                    }
                } catch {
                }


                try {
                    if (group3 != null)
                    {
                        group3.Delete();
                    }
                } catch {
                }
            }
        }
示例#3
0
        public void TestLocalGroupWithMultipleMembersWithWithGroupMembershipVerify()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            NTLocalUser  user1  = null;
            NTLocalUser  user2  = null;
            NTLocalGroup group1 = null;
            NTLocalGroup group2 = null;
            NTLocalGroup group3 = null;

            try {
                group1 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group1);
                group2 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group2);
                group3 = host.CreateLocalGroup(GenerateGroupName(host), "description");
                Assert.IsNotNull(group3);


                user1 = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");
                user2 = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");

                group1.AddLocalMember(user1.Name);
                group1.AddLocalMember(user2.Name);
                group2.AddLocalMember(user1.Name);
                group3.AddLocalMember(user2.Name);

                NTLocalObject[] group1Members = group1.GetLocalMembers();
                Assert.IsNotNull(group1Members);
                Assert.AreEqual(2, group1Members.Length);
                Assert.IsTrue(ContainsObjectByName(group1Members, user1.Name));
                Assert.IsTrue(ContainsObjectByName(group1Members, user2.Name));

                NTLocalObject[] group2Members = group2.GetLocalMembers();
                Assert.IsNotNull(group2Members);
                Assert.AreEqual(1, group2Members.Length);
                Assert.IsTrue(ContainsObjectByName(group2Members, user1.Name));

                NTLocalObject[] group3Members = group3.GetLocalMembers();
                Assert.IsNotNull(group3Members);
                Assert.AreEqual(1, group3Members.Length);
                Assert.IsTrue(ContainsObjectByName(group3Members, user2.Name));
            } finally {
                try {
                    if (user1 != null)
                    {
                        user1.Delete();
                    }
                } catch {
                }

                try {
                    if (user2 != null)
                    {
                        user2.Delete();
                    }
                } catch {
                }

                try {
                    if (group1 != null)
                    {
                        group1.Delete();
                    }
                } catch {
                }


                try {
                    if (group2 != null)
                    {
                        group2.Delete();
                    }
                } catch {
                }


                try {
                    if (group3 != null)
                    {
                        group3.Delete();
                    }
                } catch {
                }
            }
        }