public void TestWriteLock() { var testDir = new DirectoryInfo(Path.Combine(tempDir.FullName, Guid.NewGuid().ToString())); testDir.Create(); var locker = new DirectoryLocker(testDir.FullName); locker.WriteLock(); Assert.AreEqual(1, testDir.GetFiles("write*.lock").Count()); }
public void TestWaitWriteUnlock() { var testDir = new DirectoryInfo(Path.Combine(tempDir.FullName, Guid.NewGuid().ToString())); testDir.Create(); var testLocker = new DirectoryLocker(testDir.FullName); testLocker.WriteLock(); Task.Factory.StartNew(() => { WriteUnLock(testLocker, 10); }); var start = DateTime.Now; testLocker.WaitWriteUnlock(100, 1000); var finish = DateTime.Now; var delta = finish - start; Assert.IsTrue(delta.TotalSeconds > 7); }