public void FileMemo_CheckMemoOfAddedFileAfterSizeAndLastWriteTimeChange_MemoNotFound() { var memos = new TestFileMemo(); var testFileName = "~/add-me-check-me-write-more-data-and-change-time.dat"; var file = memos.CreateTestFile(testFileName, 64, 12); var memo = TestFileMemo.ComputeMemoValue(file); Assert.True(memos.AddMemo(testFileName, memo)); var originalLastWriteTime = StreamUtilities.LastFileWriteTimeUtc(testFileName, memos.Storage); Thread.Sleep(1); // ugh... but tests can run fast enough to fail w/ equal timestamps var originalSize = StreamUtilities.FileSize(testFileName, memos.Storage); file.Seek(0, SeekOrigin.End); file.WriteByte(0xFF); Assert.NotEqual(originalSize, StreamUtilities.FileSize(testFileName, memos.Storage)); Assert.NotEqual(originalLastWriteTime, StreamUtilities.LastFileWriteTimeUtc(testFileName, memos.Storage)); var returnedMemo = memo; Assert.False(memos.CheckMemo(testFileName, out returnedMemo)); Assert.Equal(TestFileMemo.InitialMemoValue, returnedMemo); file.Dispose(); file = null; }
public void StreamUtilitiesWithTestStorage_CallSizeAfterCreatingSizedStream_ReturnsExpectedSize() { var storage = new TestStorageAccess(); var testPath = @"~/.test_file.dat"; var testSize = 64; using (var testStream = storage.OpenOrCreate(testPath, testSize)) { Assert.Equal(testSize, StreamUtilities.FileSize(testPath, storage)); } }
public void StreamUtilitiesWithTestStorage_CallLastWriteTimeUtcAfterWritingToStream_ReturnsReasonableLastWriteTime() { var storage = new TestStorageAccess(); var testPath = @"~/test_file_to_write.dat"; using (var stream = StreamUtilities.OpenFileStream(testPath, storage)) { var beforeWrite = DateTime.UtcNow; int numBytesToWrite = 128; for (byte i = 0; i < numBytesToWrite; ++i) { stream.WriteByte(i); } Assert.Equal(numBytesToWrite, StreamUtilities.FileSize(testPath, storage)); var afterWrite = DateTime.UtcNow; var lastWrite = StreamUtilities.LastFileWriteTimeUtc(testPath, storage); Assert.True(lastWrite >= beforeWrite); Assert.True(lastWrite <= afterWrite); } }
public void StreamUtilitiesWithTestStorage_CallSizeWithNonexistentPath_ThrowsFileNotFoundException() { var storage = new TestStorageAccess(); Assert.Throws <FileNotFoundException>(() => StreamUtilities.FileSize(@"SomeBogusPathThatHasNoSize", storage)); }