public void DeleteFileLocksFile()
        {
            Debug.WriteLine("TEST START: DeleteFileLocksFile");

            using (new FileMutex(FileName))
            {
                ThreadTestUtils.RunActionOnThreadAndJoin(
                    () => { Assert.ThrowsException <InvalidOperationException>(() => _io.DeleteFile(FileName)); });
            }
        }
        public void DeleteFileLocksParentDirectory()
        {
            Debug.WriteLine("TEST START: DeleteFileLocksParentDirectory");

            // Mutex name for the root directory, which is the parent directory for the file we're about to try to delete
            using (new FileMutex(string.Empty))
            {
                ThreadTestUtils.RunActionOnThreadAndJoin(
                    () => Assert.ThrowsException <InvalidOperationException>(() => { _io.DeleteFile(FileName); }));
            }
        }
        public void ReadFileDoesNotLockParentDirectory()
        {
            Debug.WriteLine("TEST START: ReadFileDoesNotLockParentDirectory");

            _io.Write(FileName, _data);

            // Mutex name for the root directory, which is the parent directory for the file we're about to read
            using (new FileMutex(string.Empty))
            {
                ThreadTestUtils.RunActionOnThreadAndJoin(() => { Assert.AreEqual(_data, _io.Read(FileName)); });
            }
        }
        public void DeleteContentLocksParentDirectory()
        {
            Debug.WriteLine("TEST START: DeleteContentLocksParentDirectory");

            _io.Write("x/a.txt", _data);

            // Mutex name for the root directory, which is the parent directory for the directory we're about to try to delete
            using (new FileMutex(string.Empty))
            {
                ThreadTestUtils.RunActionOnThreadAndJoin(
                    () => Assert.ThrowsException <InvalidOperationException>(() => _io.DeleteContent("x")));
            }
        }
        public void WriteDoesNotLockParentDirectory()
        {
            Debug.WriteLine("TEST START: WriteDoesNotLockParentDirectory");

            // Mutex name for the root directory, which is the parent directory for the file we're about to write to
            // Create the file
            _io.Write(FileName, _data);

            using (new FileMutex(string.Empty))
            {
                // Writing into the file should work, because the file already exists and FileIO::Write doesn't need to lock the
                // parent directory
                ThreadTestUtils.RunActionOnThreadAndJoin(() => _io.Write(FileName, _data));
            }
        }
        public void LockFile()
        {
            Debug.WriteLine("TEST START: LockFile");

            using (_io.LockFile(FileName))
            {
                ThreadTestUtils.RunActionOnThreadAndJoin(
                    () =>
                {
                    // Another thread should not be able to acquire mutex with this name because it's being used by fileMutex
                    Assert.ThrowsException <InvalidOperationException>(() => new FileMutex(FileName));
                });
            }

            ThreadTestUtils.RunActionOnThreadAndJoin(
                () =>
            {
                // Now this thread should be able to acquire mutex with this name because fileMutex went out of scope
                Assert.ThrowsException <InvalidOperationException>(() => new FileMutex(FileName));
            });
        }