public async void ManyProcess() { var file = new FileInfo(Path.GetTempFileName()); var fileLock = new FileLock(file); await fileLock.TryAcquire(TimeSpan.FromHours(1)); fileLock.AddTime(TimeSpan.FromHours(1)); var fileDate = new DateTime(long.Parse(File.ReadAllText(Path.ChangeExtension(file.FullName, Extension)))); Assert.True(fileDate - DateTime.UtcNow - TimeSpan.FromHours(2) < _timeVariable); }
public async void CannotWriteToFile() { var file = new FileInfo(Path.GetTempFileName()); ILock fileLock = new FileLock(file); if (await fileLock.TryAcquire(TimeSpan.FromHours(1))) { using (fileLock) { string pathToLock = Path.ChangeExtension(file.FullName, Extension); using (FileStream stream = File.Open(pathToLock, FileMode.Open, FileAccess.Write, FileShare.ReadWrite)) { await fileLock.AddTime(TimeSpan.FromHours(1)); Assert.False(await new FileLock(file).TryAcquire(TimeSpan.MaxValue, false)); } } } }