public void Should_Not_Attempt_To_Release_Lock_On_Dispose()
    {
      //mock.Setup(rep => rep.ReleaseReadLock(LockItem.ResourceId, LockItem.LockId)).Returns(true);

      //make sure putting the guard into a using construct eventually releases the lock
      using (var grd = new ResourceLockGuard(Lock, RepositoryMock.Object))
      {
      }

      RepositoryMock.Verify(rep => rep.ReleaseWriteLock(Lock.ResourceId, Lock.LockId), Times.Never());
      RepositoryMock.Verify(rep => rep.ReleaseReadLock(Lock.ResourceId, Lock.LockId), Times.Never());
      RepositoryMock.Verify(rep => rep.ReleaseLock(Lock), Times.Never());
    }
    public void Should_Release_Write_Main_And_Secondardy_Locks()
    {
      bool mainReleased = false;

      RepositoryMock.Setup(rep => rep.ReleaseReadLock("xxx", It.IsAny<string>()))
        .Callback(() => mainReleased = true);

      RepositoryMock.Setup(rep => rep.ReleaseLock(It.IsAny<LockItem>()))
        .Callback(() => Assert.IsTrue(mainReleased));

      //make sure putting the guard into a using construct eventually releases the lock
      using (var grd = new ResourceLockGuard(Lock, RepositoryMock.Object) {SecondaryLocks = SecondaryLocks})
      {
      }


      RepositoryMock.Verify(rep => rep.ReleaseReadLock(Lock.ResourceId, Lock.LockId), Times.Once());
      RepositoryMock.Verify(rep => rep.ReleaseLock(It.IsAny<LockItem>()), Times.Exactly(SecondaryLocks.Count));
      RepositoryMock.Verify(rep => rep.ReleaseWriteLock(Lock.ResourceId, Lock.LockId), Times.Never());
    }
    public void Should_Release_Main_Lock_Before_Secondary_Ones()
    {
      bool mainReleased = false;

      //set the bool to true on release
      RepositoryMock.Setup(rep => rep.ReleaseReadLock(Lock.ResourceId, Lock.LockId))
        .Callback(() => mainReleased = true);

      //verify flag was switched
      RepositoryMock.Setup(rep => rep.ReleaseLock(It.IsAny<LockItem>()))
        .Callback(() => Assert.IsTrue(mainReleased));

      //make sure putting the guard into a using construct eventually releases the lock
      using (var grd = new ResourceLockGuard(Lock, RepositoryMock.Object) { SecondaryLocks = SecondaryLocks })
      {
      }
    }
 public void Should_Contain_Secondary_Locks()
 {
   Guard = new ResourceLockGuard(Lock, Repository) {SecondaryLocks = this.SecondaryLocks};
   Assert.AreSame(SecondaryLocks, Guard.SecondaryLocks);
 }
 public void Init()
 {
   Lock = LockItem.CreateDenied("xxx");
   RepositoryMock = new Mock<IResourceLockRepository>();
   Guard = new ResourceLockGuard(Lock, Repository);
 }
 public void Init()
 {
   Lock = LockItem.CreateWrite("xxx", null);
   RepositoryMock = new Mock<IResourceLockRepository>();
   Guard = new ResourceLockGuard(Lock, Repository);
 }