Ejemplo n.º 1
0
        public void Can_Modify_Individual_Members_Group()
        {
            var members = _context.Query <IntegrationUserTest>().Select(u => u.DistinguishedName).ToList();

            members.Count.Should().Be.GreaterThan(2);
            var group = new IntegrationGroupTest
            {
                Member = new Collection <string>(members.Skip(1).ToArray())
            };

            group.SetDistinguishedName("TestGroup");

            try
            {
                var added = _context.AddAndGet(group);

                added.Member.Should().Not.Contain(members.First()).And.Have.Count.EqualTo(members.Count - 1);

                _context.AddAttribute(group.DistinguishedName, "member", members.First());

                added = _context.GetByDN <IntegrationGroupTest>(group.DistinguishedName);

                added.Member.Should().Contain(members.First()).And.Have.Count.EqualTo(members.Count);

                _context.DeleteAttribute(group.DistinguishedName, "member", members.First());

                added = _context.GetByDN <IntegrationGroupTest>(group.DistinguishedName);

                added.Member.Should().Not.Contain(members.First()).And.Have.Count.EqualTo(members.Count - 1);
            }
            finally
            {
                try
                {
                    _context.Delete(group.DistinguishedName);
                }
                finally
                {
                }
            }
        }
 /// <summary>
 /// Executes <see cref="DirectoryContext.AddAttribute"/> within a <see cref="Task"/>.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="distinguishedName">The entry</param>
 /// <param name="attributeName">The name of the attribute</param>
 /// <param name="value">The value for the entry.</param>
 /// <param name="controls">Any <see cref="DirectoryControl"/>s to be sent with the request</param>
 /// <exception cref="DirectoryOperationException">Thrown if the operation fails.</exception>
 /// <exception cref="LdapConnection">Thrown if the operation fails.</exception>
 public static Task AddAttributeAsync(this IDirectoryContext context, string distinguishedName, string attributeName, object value = null,
                                      DirectoryControl[] controls = null)
 {
     return(Task.Factory.StartNew(() => context.AddAttribute(distinguishedName, attributeName, value, controls)));
 }