public void TryObtainLock_InactiveLeaseExistsBySameOwner_LockObtained(
            ILeaseService service,
            ISystemContext ctx,
            ElasticLease inactiveLease,
            TestIndexUtils contactIndex)
        {
            using (contactIndex)
            {
                // write inactive lease
                service.TryObtainLock(inactiveLease, ctx, out inactiveLease).Should().BeTrue();

                var activeLease = new ElasticLease(
                    inactiveLease.ResourceId,
                    DateTime.UtcNow + TimeSpan.FromHours(1),
                    inactiveLease.Owner,
                    inactiveLease.Version);

                ElasticLease winner;
                service.TryObtainLock(activeLease, ctx, out winner).Should().BeTrue();
                activeLease.ShouldBeEquivalentTo(winner);
            }
        }
        public void TryObtainLock_ActiveLeaseExistsBySameOwner_LockObtained(
            ILeaseService service,
            ISystemContext ctx,
            ElasticLease activeLease,
            TestIndexUtils contactIndex,
            IFixture fixture
            )
        {
            using (contactIndex)
            {
                service.TryObtainLock(activeLease, ctx, out activeLease);

                var activeLease2 = new ElasticLease(
                    activeLease.ResourceId,
                    DateTime.UtcNow + TimeSpan.FromHours(2),
                    activeLease.Owner,
                    activeLease.Version);

                ElasticLease winner;
                service.TryObtainLock(activeLease2, ctx, out winner);
                activeLease2.ShouldBeEquivalentTo(winner);
            }
        }
 public void TryObtainLock_NoLeaseExists_LockObtained(
     ILeaseService service,
     ISystemContext ctx,
     ElasticLease lease,
     TestIndexUtils contactIndex)
 {
     using (contactIndex)
     {
         ElasticLease winner;
         service.TryObtainLock(lease, ctx, out winner).Should().BeTrue();
         lease.ShouldBeEquivalentTo(winner);
     }
 }
        public void TryObtainLock_InactiveLeaseExistsByDifferentOwner_LockObtained(
            ILeaseService service,
            ISystemContext ctx,
            ElasticLease owner1InactiveLease,
            TestIndexUtils contactIndex,
            IFixture fixture)
        {
            using (contactIndex)
            {
                service.TryObtainLock(owner1InactiveLease, ctx, out owner1InactiveLease).Should().BeTrue();

                var owner2ActiveLease = new ElasticLease(
                    owner1InactiveLease.ResourceId,
                    DateTime.UtcNow + TimeSpan.FromHours(2),
                    fixture.Create<ElasticLeaseOwner>(),
                    owner1InactiveLease.Version);

                ElasticLease winner;
                service.TryObtainLock(owner2ActiveLease, ctx, out winner).Should().BeTrue();
                owner2ActiveLease.ShouldBeEquivalentTo(winner);
            }
        }