Example #1
0
        public void TestExtendedPrincipal()
        {
            if (DomainContext == null)
            {
                return;
            }

            string name = Guid.NewGuid().ToString();

            byte[] writtenArray = new byte[] { 10, 20, 30 };
            using (Principal principal = CreateExtendedPrincipal(DomainContext, name))
            {
                IExtendedPrincipalTest extendedPrincipal = (IExtendedPrincipalTest)principal;
                extendedPrincipal.ByteArrayExtension = writtenArray;
                principal.Save();
            }

            RefreshContext();
            using (Principal principal = FindExtendedPrincipal(DomainContext, name))
            {
                IExtendedPrincipalTest extendedPrincipal = (IExtendedPrincipalTest)principal;
                byte[] readArray = extendedPrincipal.ByteArrayExtension;
                principal.Delete();
            }
        }
Example #2
0
        public void TestExtendedPrincipal()
        {
            // to improve this, we might want to generate random sequences
            byte[] writtenArray = { 10, 20, 30 };
            byte[] readArray;

            string name = Guid.NewGuid().ToString();

            using (Principal principal = CreateExtendedPrincipal(domainContext, name))
            {
                IExtendedPrincipalTest extendedPrincipal = (IExtendedPrincipalTest)principal;
                extendedPrincipal.ByteArrayExtension = writtenArray;
                principal.Save();
            }

            RefreshContext();

            using (Principal principal = FindExtendedPrincipal(domainContext, name))
            {
                IExtendedPrincipalTest extendedPrincipal = (IExtendedPrincipalTest)principal;
                readArray = extendedPrincipal.ByteArrayExtension;
                principal.Delete();
            }

            CollectionAssert.AreEqual(writtenArray, readArray);
        }
Example #3
0
        public void AddExistingPrincipal()
        {
            if (DomainContext == null)
            {
                return;
            }

            // use new GUID for the user name so we be sure this user does not exist yet
            string name = Guid.NewGuid().ToString();

            using (Principal principal = CreatePrincipal(DomainContext, name))
            {
                principal.Save();
            }

            Assert.NotNull(Principal.FindByIdentity(DomainContext, name));

            // this previously caused the user to be deleted. it is still expected to throw an exception, but not delete the user
            bool exceptionThrown = false;

            try
            {
                using (Principal principal = CreatePrincipal(DomainContext, name))
                {
                    principal.Save();
                }
            }
            catch (PrincipalExistsException)
            {
                exceptionThrown = true;
            }

            // validate that we correctly throw an exception when trying to add an existing principal
            Assert.True(exceptionThrown);

            // validate that we did not delete incorrectly delete the first principal
            using (Principal principal2 = Principal.FindByIdentity(DomainContext, name))
            {
                Assert.NotNull(principal2);

                // explicitly delete the user and check it was really deleted
                principal2.Delete();
            }

            // ensure we cleaned up the test principal
            Assert.Null(Principal.FindByIdentity(DomainContext, name));
        }
Example #4
0
 public void Dispose()
 {
     Principal.Delete();
 }
Example #5
0
 /// <summary>
 /// Delete the ADObject from the AD server
 /// </summary>
 public void Delete()
 {
     _sourceItem.Delete();
 }