Example #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 {
                }
            }
        }
Example #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 {
                }
            }
        }