public void SaveContact_ContactDoesntExist_ContactSave(
            DataAdapterProvider provider,
            IContactFactory contactFactory,
            IContact contact,
            LeaseOwner leaseOwner,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                provider.SaveContact(contact, new ContactSaveOptions(true, leaseOwner)).Should().BeTrue();

                var actual = provider.LoadContactReadOnly(contact.Id, contactFactory);

                AssertContactsEqual(actual, contact);
            }
        }
        public void TryExtendLock_ContactExistsLockedBySameOwner_LeaseExtended(
            DataAdapterProvider provider,
            IContact contact,
            LeaseOwner leaseOwner,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                provider.SaveContact(contact, new ContactSaveOptions(false, leaseOwner, TimeSpan.FromMinutes(1)))
                    .Should().Be(true);

                contact.Lease.Owner = leaseOwner;
                var res = provider.TryExtendContactLockLease(contact, TimeSpan.FromHours(1));

                res.Should().BeTrue();
                contact.Lease.Owner.Identifier.Should().Be(leaseOwner.Identifier);
            }
        }
        public void TryExtendLock_ContactExistsLockedByDifferentOwner_NotExtended(
            DataAdapterProvider provider,
            IContact contact,
            LeaseOwner them,
            LeaseOwner us,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                // lock by a different owner
                provider.SaveContact(contact, new ContactSaveOptions(false, them, TimeSpan.FromMinutes(1)))
                    .Should().Be(true);

                // extend it
                contact.Lease.Owner = us;
                var res = provider.TryExtendContactLockLease(contact, TimeSpan.FromHours(1));

                res.Should().BeFalse();
                // In Andes, owner is not updated to reflect the persistence layer, so we do the same here.
                contact.Lease.Owner.Identifier.Should().Be(us.Identifier);
            }
        }
        public void ObsoleteContact_ContactExistsAndNotLocked_ContactObsoleted(
            DataAdapterProvider provider,
            IContactFactory contactFactory,
            IContact contact,
            IContact successor,
            LeaseOwner leaseOwner,
            LeaseOwner us,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                // lock contact for 'them'
                provider.SaveContact(contact, new ContactSaveOptions(true, leaseOwner)).Should().BeTrue();

                provider.ObsoleteContact(contact.Id, leaseOwner, successor.Id);
                provider.SaveContact(successor, new ContactSaveOptions(true, leaseOwner)).Should().BeTrue();

                var actual = provider.LoadContactReadOnly(contact.Id, contactFactory);
                AssertContactsEqual(actual, successor);
            }
        }
        public void ReleaseContact_ContactExistsAndLocked_ContactReleased(
            DataAdapterProvider provider,
            IContactFactory contactFactory,
            IContact contact,
            LeaseOwner them,
            LeaseOwner us,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                // lock contact for 'them'
                provider.SaveContact(contact, new ContactSaveOptions(false, them)).Should().BeTrue();

                provider.ReleaseContact(contact.Id, them);

                var actual = provider.TryLoadContact(contact.Id, contactFactory, us, TimeSpan.FromMinutes(1));
                actual.Status.Should().Be(LockAttemptStatus.Success);
                AssertContactsEqual(actual.Object, contact, l => l.Owner == us && l.ExpirationTime > DateTime.UtcNow);
            }
        }
        public void DeleteContact_ContactExists_ContactRemoved(
            DataAdapterProvider provider,
            IContactFactory contactFactory,
            IContact contact,
            LeaseOwner leaseOwner,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                provider.SaveContact(contact, new ContactSaveOptions(true, leaseOwner)).Should().BeTrue();

                provider.DeleteContact(contact.Id);

                var actual = provider.TryLoadContact(contact.Id, contactFactory, leaseOwner, TimeSpan.FromMinutes(1));
                actual.Status.Should().Be(LockAttemptStatus.NotFound);
                actual.Object.Should().BeNull();
            }
        }
        public void TryLoadContactById_ContactDoesntExist_NullReturned(
            DataAdapterProvider provider,
            IContactFactory contactFactory,
            IContact contact,
            LeaseOwner leaseOwner,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                var actual = provider.TryLoadContact(contact.Id, contactFactory, leaseOwner, TimeSpan.FromMinutes(1));

                actual.Status.Should().Be(LockAttemptStatus.NotFound);
                actual.Object.Should().BeNull();
            }
        }
        public void TryLoadContactById_ContactExistsAndNotLocked_ContactReturned(
            DataAdapterProvider provider,
            IContactFactory contactFactory,
            IContact contact,
            LeaseOwner leaseOwner,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                provider.SaveContact(contact, new ContactSaveOptions(true, leaseOwner)).Should().BeTrue();

                var actual = provider.TryLoadContact(contact.Id, contactFactory, leaseOwner, TimeSpan.FromMinutes(1));

                actual.Status.Should().Be(LockAttemptStatus.Success);
                AssertContactsEqual(actual.Object, contact, l => l.Owner == leaseOwner && l.ExpirationTime > DateTime.UtcNow);
            }
        }