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.UpdateAndGet(IDirectoryAttributes,DirectoryControl[])"/> within a <see cref="Task"/>. /// </summary> /// <param name="context">The context.</param> /// <param name="entry">The attributes for the entry.</param> /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param> /// <returns></returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="entry"/> is null. /// </exception> /// <exception cref="DirectoryOperationException">Thrown if the operation fails</exception> /// <exception cref="LdapException">Thrown if the operation fails</exception> public static Task <IDirectoryAttributes> UpdateAndGetAsync(this IDirectoryContext context, IDirectoryAttributes entry, DirectoryControl[] controls) { return(Task.Factory.StartNew(() => context.UpdateAndGet(entry, controls))); }
/// <summary> /// Executes <see cref="DirectoryContext.UpdateAndGet{T}"/> within a <see cref="Task"/>. /// </summary> /// <param name="context">The context.</param> /// <param name="entry">The entry to update</param> /// <param name="distinguishedName">The distinguished name for the entry.</param> /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param> /// <typeparam name="T">The type of entry.</typeparam> /// <returns></returns> /// <exception cref="ArgumentNullException">Thrown if entry is null</exception> /// <exception cref="MappingException"> /// Thrown if <paramref name="distinguishedName"/> is null and Distinguished Name is not mapped. /// Thrown if <typeparamref name="T"/> has not been mapped. /// </exception> /// <exception cref="ArgumentException">Thrown if distinguished name is null and there is no mapped distinguished name property.</exception> /// <exception cref="DirectoryOperationException">Thrown if the operation is not successful</exception> /// <exception cref="LdapException">Thrown if the operation is not successful</exception> public static Task <T> UpdateAndGetAsync <T>(this IDirectoryContext context, T entry, string distinguishedName = null, DirectoryControl[] controls = null) where T : class { return(Task.Factory.StartNew(() => context.UpdateAndGet(entry, distinguishedName, controls))); }