コード例 #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");
        }
コード例 #2
0
 /// <summary>
 /// Executes <see cref="DirectoryContext.MoveEntry"/> within a <see cref="Task"/>.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="currentDistinguishedName">The entry's current distinguished name</param>
 /// <param name="newNamingContext">The new container for 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="newNamingContext"/> 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> MoveEntryAsync(this IDirectoryContext context, string currentDistinguishedName, string newNamingContext,
                                            bool?deleteOldRDN = null, params DirectoryControl[] controls)
 {
     return(Task.Factory.StartNew(() => context.MoveEntry(currentDistinguishedName, newNamingContext, deleteOldRDN, controls)));
 }