Exemplo n.º 1
0
        public void Test_EventListener()
        {
            _configuration.RegisterListeners(this);

            var user = new IntegrationUserTest {
                Cn = "eventlistener", Mail = "*****@*****.**"
            };

            var added = _context.AddAndGet(user, user.GetDistinguishedName());

            try
            {
                added.Mail = "*****@*****.**";
                _context.Update(added);
            }
            finally
            {
                _context.Delete(added.DistinguishedName);
            }

            _preAddNotified.Should().Be.True();
            _postAddNotified.Should().Be.True();

            _preUpdateNotified.Should().Be.True();
            _postUpdateNotified.Should().Be.True();

            _preDeleteNotified.Should().Be.True();
            _postDeleteNotified.Should().Be.True();
        }
Exemplo n.º 2
0
        public void Can_Add_Update_Remove_Static()
        {
            var test = new IntegrationUserTest
            {
                Cn             = "IntegrationTest",
                AccountExpires = DateTime.MinValue
            };

            var added = _context.AddAndGet(test, test.GetDistinguishedName());

            added.Should().Not.Be.Null();
            added.AccountExpires.Should().Not.Have.Value();
            added.Cn.Should().Be.EqualTo(test.Cn);
            added.AccountExpires.Should().Not.Have.Value();
            added.ObjectGuid.Should().Not.Be.Null().And.Not.Be.EqualTo(default(Guid));
            added.ObjectSid.Should().Not.Be.Null();
            added.Manager.Should().Be.Null();
            added.Employees.Should().Be.Null();
            added.WhenCreated.Should().Be.GreaterThan(DateTime.Now.Subtract(TimeSpan.FromHours(1)));

            var queryResult = _context.Query <IntegrationUserTest>()
                              .Where(u => u.ObjectGuid == added.ObjectGuid)
                              .Select(u => u.ObjectGuid)
                              .FirstOrDefault();

            queryResult.Should().Be.EqualTo(added.ObjectGuid);

            var now = DateTime.Now;

            added.AccountExpires = now;

            added = _context.UpdateAndGet(added);

            added.AccountExpires.Should().Be.EqualTo(now);

            _context.Delete(added.DistinguishedName);

            Executing.This(() => _context.GetByDN(added.DistinguishedName))
            .Should().Throw <DirectoryOperationException>().And.Exception.Message
            .Should().Contain("does not exist");
        }