Represents distibuted lock implementation for MongoDB
Inheritance: IDisposable
 public void Ctor_SetLock_WhenResourceIsNotLocked()
 {
     UseConnection(database =>
     {
         using (MongoDistributedLock @lock = new MongoDistributedLock("resource1", TimeSpan.FromSeconds(1), database, new MongoStorageOptions()))
         {
             var locksCount = AsyncHelper.RunSync(() => database.DistributedLock.CountAsync(Builders<DistributedLockDto>.Filter.Eq(_ => _.Resource, "resource1")));
             Assert.Equal(1, locksCount);
         }
     });
 }
		public void Ctor_SetLock_WhenResourceIsNotLocked()
		{
			UseConnection(database =>
			{
				using (MongoDistributedLock @lock = new MongoDistributedLock("resource1", TimeSpan.FromSeconds(1), database, new MongoStorageOptions()))
				{
					var locksCount = database.DistributedLock.Count(Query<DistributedLockDto>.EQ(_ => _.Resource, "resource1"));
					Assert.Equal(1, locksCount);
				}
			});
		}
        public void Ctor_ThrowsAnException_WhenResourceIsLocked()
        {
            UseConnection(database =>
            {
                using (MongoDistributedLock @lock1 = new MongoDistributedLock("resource1", TimeSpan.FromSeconds(1), database, new MongoStorageOptions()))
                {
                    var locksCount = database.DistributedLock.Count(Builders<DistributedLockDto>.Filter.Eq(_ => _.Resource, "resource1"));
                    Assert.Equal(1, locksCount);

                    Assert.Throws<MongoDistributedLockException>(() => new MongoDistributedLock("resource1", TimeSpan.FromSeconds(1), database, new MongoStorageOptions()));
                }
            });
        }
        public void Ctor_SetReleaseLock_WhenResourceIsNotLocked()
        {
            UseConnection(database =>
            {
                long locksCount;
                using (MongoDistributedLock @lock = new MongoDistributedLock("resource1", TimeSpan.FromSeconds(1), database, new MongoStorageOptions()))
                {
                    locksCount = database.DistributedLock.Count(Builders<DistributedLockDto>.Filter.Eq(_ => _.Resource, "resource1"));
                    Assert.Equal(1, locksCount);
                }

                locksCount = database.DistributedLock.Count(Builders<DistributedLockDto>.Filter.Eq(_ => _.Resource, "resource1"));
                Assert.Equal(0, locksCount);
            });
        }
        public void Ctor_SetLockHeartbeatWorks_WhenResourceIsNotLocked()
        {
            UseConnection(database =>
            {
                using (MongoDistributedLock @lock = new MongoDistributedLock("resource1", TimeSpan.FromSeconds(1), database, new MongoStorageOptions() { DistributedLockLifetime = TimeSpan.FromSeconds(3) }))
                {
                    DateTime initialHeartBeat = database.GetServerTimeUtc();
                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    DistributedLockDto lockEntry = AsyncHelper.RunSync(() => database.DistributedLock.Find(Builders<DistributedLockDto>.Filter.Eq(_ => _.Resource, "resource1")).FirstOrDefaultAsync());
                    Assert.NotNull(lockEntry);
                    Assert.True(lockEntry.Heartbeat > initialHeartBeat);
                }
            });
        }
		public void Ctor_SetLockHeartbeatWorks_WhenResourceIsNotLocked()
		{
			UseConnection(database =>
			{
				using (MongoDistributedLock @lock = new MongoDistributedLock("resource1", TimeSpan.FromSeconds(1), database, new MongoStorageOptions() { DistributedLockLifetime = TimeSpan.FromSeconds(10)}))
				{
					DateTime initialHeartBeat = database.GetServerTimeUtc();
					Thread.Sleep(TimeSpan.FromSeconds(3));
					Thread.Sleep(TimeSpan.FromSeconds(60));

					DistributedLockDto lockEntry = database.DistributedLock.FindOne(Query<DistributedLockDto>.EQ(_ => _.Resource, "resource1"));
					Assert.NotNull(lockEntry);
					Assert.True(lockEntry.Heartbeat > initialHeartBeat);
				}
			});
		}