Beispiel #1
0
        public void MakeSurePuttingSeveralLocksOnSameThingCleanUpNicelyWhenYouReleaseTheLocks()
        {
            var manager = new FileSystemObjectLockingManager();

            var folderNodes = FakeNodesFactory.CreateFakeFolderNodes(2);

            var fileNode = FakeNodesFactory.CreateFakeFileNode();

            var nodeResolvingResult = new NodeWithSurroundingsResolvingResult <FileNode>(folderNodes, fileNode, FakeNodesFactory.CreateFakeFolderNodes(1).First());

            Guid lockId  = manager.AcquireLock(nodeResolvingResult, LockKind.Read);
            Guid lock2Id = manager.AcquireLock(nodeResolvingResult, LockKind.Read);
            Guid lock3Id = manager.AcquireLock(nodeResolvingResult, LockKind.Read);

            Assert.IsTrue(manager.IsNodeLockedForRenamesAndMoves(folderNodes[0]));
            Assert.IsTrue(manager.IsNodeLockedForRenamesAndMoves(folderNodes[1]));

            manager.ReleaseLock(lockId);
            manager.ReleaseLock(lock3Id);

            Assert.IsTrue(manager.IsNodeLockedForRenamesAndMoves(folderNodes[0]));
            Assert.IsTrue(manager.IsNodeLockedForRenamesAndMoves(folderNodes[1]));

            manager.ReleaseLock(lock2Id);

            Assert.IsFalse(manager.IsNodeLockedForRenamesAndMoves(folderNodes[0]));
            Assert.IsFalse(manager.IsNodeLockedForRenamesAndMoves(folderNodes[1]));
        }
        public void MakeSureYouCanGetSeveralReadersWithoutAnException()
        {
            var fileLock = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), FakeNodesFactory.CreateFakeFolderNodes(1));

            fileLock.LockForReading();
            fileLock.LockForReading();
            fileLock.LockForReading();
        }
        public void MakeSureYouCanGetAWriteLockWithAnotherWriteLockInPlaceIfYouReleaseThatOtherLockFirst()
        {
            var fileLock = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), FakeNodesFactory.CreateFakeFolderNodes(1));

            Guid lockId = fileLock.LockForWriting();

            fileLock.ReleaseLock(lockId);

            fileLock.LockForWriting();
        }
        public void MakeSureYouCannotGetAWriteLockWithAnotherWriteLockInPlace()
        {
            var fileLock = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), FakeNodesFactory.CreateFakeFolderNodes(1));

            fileLock.LockForWriting();

            ExceptionAssert.MakeSureExceptionIsRaisedBy <CannotAcquireLockException>(
                delegate
            {
                fileLock.LockForWriting();
            });
        }
        public void MakeSureYouCanGetAWriteLockAfterReadLocksAreReleased()
        {
            var fileLock = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), FakeNodesFactory.CreateFakeFolderNodes(1));

            Guid lockId  = fileLock.LockForReading();
            Guid lock2Id = fileLock.LockForReading();

            fileLock.ReleaseLock(lockId);
            fileLock.ReleaseLock(lock2Id);

            fileLock.LockForWriting();
        }
        public void MakeSureNodeLockableThrowsWhenBeingAcquiredIfFileLockDoesNotListItAsAssociatedNode()
        {
            FolderNode nodeToLock   = FakeNodesFactory.CreateFakeFolderNodes(1).First();
            var        nodeLockable = new FolderNodeLockable(nodeToLock);

            FileLockable lock1 = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), FakeNodesFactory.CreateFakeFolderNodes(2));

            ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>(
                delegate
            {
                nodeLockable.AddLock(lock1, lock1.LockForWriting());
            });
        }
Beispiel #7
0
        public void MakeSureYouCanAcquireSeveralReadLocksInARow()
        {
            var manager = new FileSystemObjectLockingManager();

            var folderNodes = FakeNodesFactory.CreateFakeFolderNodes(2);

            var fileNode = FakeNodesFactory.CreateFakeFileNode();

            var nodeResolvingResult = new NodeWithSurroundingsResolvingResult <FileNode>(folderNodes, fileNode, FakeNodesFactory.CreateFakeFolderNodes(1).First());

            manager.AcquireLock(nodeResolvingResult, LockKind.Read);
            manager.AcquireLock(nodeResolvingResult, LockKind.Read);
            manager.AcquireLock(nodeResolvingResult, LockKind.Read);
        }
        public void MakeSureYouCannotInitializeFileLockableWithoutAssociatedNodes()
        {
            ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>(
                delegate
            {
                new FileLockable(FakeNodesFactory.CreateFakeFileNode(), FakeNodesFactory.CreateFakeFolderNodes(0));
            });

            ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>(
                delegate
            {
                new FileLockable(FakeNodesFactory.CreateFakeFileNode(), null);
            });
        }
Beispiel #9
0
        public void MakeSureYouCannotAcquireWriteLockOnTheSameThingThatAlreadyHasAReadLock()
        {
            var manager = new FileSystemObjectLockingManager();

            var folderNodes = FakeNodesFactory.CreateFakeFolderNodes(2);

            var fileNode = FakeNodesFactory.CreateFakeFileNode();

            var nodeResolvingResult = new NodeWithSurroundingsResolvingResult <FileNode>(folderNodes, fileNode, FakeNodesFactory.CreateFakeFolderNodes(1).First());

            manager.AcquireLock(nodeResolvingResult, LockKind.Read);

            ExceptionAssert.MakeSureExceptionIsRaisedBy <CannotAcquireLockException>(
                delegate
            {
                manager.AcquireLock(nodeResolvingResult, LockKind.Write);
            });
        }
        public void MakeSureIsLockedPropertyRelfectsLockStateAdequately()
        {
            FolderNode nodeToLock   = FakeNodesFactory.CreateFakeFolderNodes(1).First();
            var        nodeLockable = new FolderNodeLockable(nodeToLock);

            List <FolderNode> nodes = new List <FolderNode> {
                nodeToLock
            };

            FileLockable lock1 = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), nodes);
            FileLockable lock2 = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), nodes);
            FileLockable lock3 = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), nodes);
            FileLockable lock4 = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), nodes);

            Assert.IsFalse(nodeLockable.IsLocked);

            Guid lock1Id = lock1.LockForReading();

            nodeLockable.AddLock(lock1, lock1Id);

            Assert.IsTrue(nodeLockable.IsLocked);

            Guid lock2Id = lock2.LockForReading();

            nodeLockable.AddLock(lock2, lock2Id);

            Guid lock3Id = lock3.LockForReading();

            nodeLockable.AddLock(lock3, lock3Id);

            Guid lock4Id = lock4.LockForReading();

            nodeLockable.AddLock(lock4, lock4Id);

            Assert.IsTrue(nodeLockable.IsLocked);

            nodeLockable.ReleaseLock(lock1Id);
            nodeLockable.ReleaseLock(lock2Id);
            nodeLockable.ReleaseLock(lock3Id);
            nodeLockable.ReleaseLock(lock4Id);

            Assert.IsFalse(nodeLockable.IsLocked);
        }
Beispiel #11
0
        public void MakeSureAcquiringALockDoesLockAppropriateFolders()
        {
            var manager = new FileSystemObjectLockingManager();

            var folderNodes = FakeNodesFactory.CreateFakeFolderNodes(2);

            var fileNode = FakeNodesFactory.CreateFakeFileNode();

            var nodeResolvingResult = new NodeWithSurroundingsResolvingResult <FileNode>(folderNodes, fileNode, FakeNodesFactory.CreateFakeFolderNodes(1).First());

            Guid lockId = manager.AcquireLock(nodeResolvingResult, LockKind.Read);

            Assert.IsTrue(manager.IsNodeLockedForRenamesAndMoves(folderNodes[0]));
            Assert.IsTrue(manager.IsNodeLockedForRenamesAndMoves(folderNodes[1]));

            manager.ReleaseLock(lockId);

            Assert.IsFalse(manager.IsNodeLockedForRenamesAndMoves(folderNodes[0]));
            Assert.IsFalse(manager.IsNodeLockedForRenamesAndMoves(folderNodes[1]));
        }
        public void MakeSureYouCannotAcquireSameLockOnANodeTwice()
        {
            FolderNode nodeToLock   = FakeNodesFactory.CreateFakeFolderNodes(1).First();
            var        nodeLockable = new FolderNodeLockable(nodeToLock);

            List <FolderNode> nodes = new List <FolderNode> {
                nodeToLock
            };
            FileLockable lock1 = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), nodes);

            Guid lockId = lock1.LockForReading();

            nodeLockable.AddLock(lock1, lockId);

            ExceptionAssert.MakeSureExceptionIsRaisedBy <LockAlreadyHeldException>(
                delegate
            {
                nodeLockable.AddLock(lock1, lockId);
            });
        }
        public void MakeSureYouCannotReleaseALockWhichIsNotHeld()
        {
            FolderNode nodeToLock   = FakeNodesFactory.CreateFakeFolderNodes(1).First();
            var        nodeLockable = new FolderNodeLockable(nodeToLock);

            List <FolderNode> nodes = new List <FolderNode> {
                nodeToLock
            };
            FileLockable lock1 = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), nodes);
            FileLockable lock2 = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), nodes);

            Guid lockId = lock1.LockForReading();

            nodeLockable.AddLock(lock1, lockId);

            ExceptionAssert.MakeSureExceptionIsRaisedBy <LockNotFoundException>(
                delegate
            {
                nodeLockable.ReleaseLock(lock2.LockForWriting());
            });
        }
        public void MakeSureYouCannotAcquireALockPassingNullOrEmptyGuidForIt()
        {
            FolderNode nodeToLock   = FakeNodesFactory.CreateFakeFolderNodes(1).First();
            var        nodeLockable = new FolderNodeLockable(nodeToLock);

            List <FolderNode> nodes = new List <FolderNode> {
                nodeToLock
            };
            FileLockable lock1 = new FileLockable(FakeNodesFactory.CreateFakeFileNode(), nodes);

            ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>(
                delegate
            {
                nodeLockable.AddLock(null, Guid.NewGuid());
            });

            ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>(
                delegate
            {
                nodeLockable.AddLock(lock1, Guid.Empty);
            });
        }