Exemplo n.º 1
0
        public void Can_Add_Update_Remove_Dynamic()
        {
            var attributes = new DirectoryAttributes("CN=IntegrationTest," + IntegrationUserTest.NamingContext);

            attributes.SetNull("AccountExpires");
            attributes.Set("objectclass", "user");

            var added = _context.AddAndGet(attributes);

            added.Should().Not.Be.Null();

            added.GetString("cn").Should().Be.EqualTo("IntegrationTest");
            added.GetString("accountexpires").Should().Be.Null();
            added.GetGuid("objectguid").Should().Have.Value();
            added.GetSecurityIdentifier("objectsid").Should().Not.Be.Null();
            added.GetSecurityIdentifiers("objectsid").Should().Not.Be.Empty();
            added.GetStrings("objectclass").Should().Have.Count.GreaterThan(1);

            added.Set("accountExpires", "9223372036854775807").SetNull("manager");

            added = _context.UpdateAndGet(added);

            added.GetString("accountExpires").Should().Be.EqualTo("9223372036854775807");
            added.GetDateTime("accountExpires", null).Should().Not.Have.Value();
            added.GetString("manager").Should().Be.Null();

            var renamed = _context.RenameEntry(added.DistinguishedName, "IntegrationTest2");

            var moved = _context.MoveEntry(renamed, IntegrationUserTest.NamingContext2);

            _context.Delete(moved);

            Executing.This(() => _context.GetByDN(moved))
            .Should().Throw <DirectoryOperationException>().And.Exception.Message
            .Should().Contain("does not exist");
        }
 /// <summary>
 /// Executes <see cref="DirectoryContext.RenameEntry"/> within a <see cref="Task"/>.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="currentDistinguishedName">The entry's current distinguished name</param>
 /// <param name="newName">The new name of the entry</param>
 /// <param name="deleteOldRDN">Maps to <see cref="P:System.DirectoryServices.Protocols.ModifyDNRequest.DeleteOldRdn"/>. Defaults to null to use default behavior from <see cref="P:System.DirectoryServices.Protocols.ModifyDNRequest.DeleteOldRdn"/>.</param>
 /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param>
 /// <exception cref="ArgumentException">
 /// Thrown if <paramref name="currentDistinguishedName"/> has an invalid format.
 /// </exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="currentDistinguishedName"/>
 /// or <paramref name="newName"/> are null, empty or white space.
 /// </exception>
 /// <exception cref="DirectoryOperationException">Thrown if the operation fails.</exception>
 /// <exception cref="LdapConnection">Thrown if the operation fails.</exception>
 public static Task <string> RenameEntryAsync(this IDirectoryContext context, string currentDistinguishedName, string newName,
                                              bool?deleteOldRDN = null, params DirectoryControl[] controls)
 {
     return(Task.Factory.StartNew(() => context.RenameEntry(currentDistinguishedName, newName, deleteOldRDN, controls)));
 }