示例#1
0
        public void Test_Inheritance()
        {
            var people = _context.Query <PersonInheritanceTest>().ToList();

            people.Any(x => x is OrgPersonInheritanceTest).Should().Be.True();
            people.Any(x => x is OrgPersonFlattenedInheritanceTest).Should().Be.False();
            people.Any(x => x is UserInheritanceTest).Should().Be.True();

            _context.Query <OrgPersonFlattenedInheritanceTest>().ToList().Should().Not.Be.Empty();

            var utcNow = DateTime.UtcNow.AddDays(50);
            var user   = people.OfType <UserInheritanceTest>().Skip(1).First();

            user.City.Should().Not.Be.NullOrEmpty();
            user.Title.Should().Not.Be.NullOrEmpty();
            user.AccountExpires.Satisfies(x => x == null || x < utcNow);
            user.AccountExpires = utcNow;
            user.WhenCreated.Should().Have.Value();
            _context.Update(user);

            var updatedUser =
                _context.Query <PersonInheritanceTest>().FirstOrDefault(x => x.CommonName == user.CommonName);

            updatedUser.Should().Not.Be.Null();
            updatedUser.As <UserInheritanceTest>().AccountExpires.Should().Have.Value();
        }
 /// <summary>
 /// Executes <see cref="DirectoryContext.Update(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 UpdateAsync(this IDirectoryContext context, IDirectoryAttributes entry,
                                DirectoryControl[] controls)
 {
     return(Task.Factory.StartNew(() => context.Update(entry, controls)));
 }
 /// <summary>
 /// Executes <see cref="DirectoryContext.Update{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 UpdateAsync <T>(this IDirectoryContext context, T entry,
                                    string distinguishedName = null, DirectoryControl[] controls = null)
     where T : class
 {
     return(Task.Factory.StartNew(() => context.Update(entry, distinguishedName, controls)));
 }