Beispiel #1
0
        public void FileMemo_CheckAndAddMemoAfterRenamingFileThenBack_RemovesThenAddsMemo()
        {
            var memos        = new TestFileMemo();
            var testFileName = "~/check-add-change.dat";
            var file         = memos.CreateTestFile(testFileName, 99, 10);
            var expectedMemo = TestFileMemo.ComputeMemoValue(file);

            Assert.NotEqual(TestFileMemo.InitialMemoValue, expectedMemo);

            int memo = 1;

            Assert.True(memos.CheckAddMemo(testFileName, null, out memo));
            Assert.True(memos.CalledGetMemo);
            Assert.Equal(expectedMemo, memo);

            var newTestFileName = "~/check-add-change.dat~";

            memos.Storage.Rename(testFileName, newTestFileName);

            var updatedMemo = memo;

            Assert.False(memos.CheckAddMemo(testFileName, null, out updatedMemo));
            Assert.NotEqual(expectedMemo, updatedMemo);
            Assert.Equal(TestFileMemo.InitialMemoValue, updatedMemo);

            memos.Storage.Rename(newTestFileName, testFileName);
            Assert.True(memos.CheckAddMemo(testFileName, null, out updatedMemo));
            Assert.Equal(expectedMemo, updatedMemo);

            file.Dispose();
            file = null;
        }
Beispiel #2
0
        public void FileMemo_CheckAndAddMemoAfterChangingFile_UpdatesMemo()
        {
            var memos               = new TestFileMemo();
            var testFileName        = "~/check-add-change.dat";
            var file                = memos.CreateTestFile(testFileName, 69, 5);
            var expectedInitialMemo = TestFileMemo.ComputeMemoValue(file);

            Assert.NotEqual(TestFileMemo.InitialMemoValue, expectedInitialMemo);

            int memo = 1;

            Assert.True(memos.CheckAddMemo(testFileName, null, out memo));
            Assert.True(memos.CalledGetMemo);
            Assert.Equal(expectedInitialMemo, memo);

            file.Seek(0, SeekOrigin.End);
            file.WriteByte(0x69);

            var updatedMemo = memo;

            Assert.True(memos.CheckAddMemo(testFileName, null, out updatedMemo));
            Assert.NotEqual(expectedInitialMemo, updatedMemo);
            file.Dispose();
            file = null;
        }
Beispiel #3
0
        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;
        }
Beispiel #4
0
        public void FileMemo_AddMemoOfValidFile_MemoAdded()
        {
            var memos        = new TestFileMemo();
            var testFileName = "~/test-file.dat";
            var file         = memos.CreateTestFile(testFileName, 123, 21);

            var memo = TestFileMemo.ComputeMemoValue(file);

            Assert.True(memos.AddMemo(testFileName, memo));
            file.Dispose();
            file = null;
        }
Beispiel #5
0
        public void FileMemo_CheckMemoOfAddedFile_GetsCorrectMemo()
        {
            var memos        = new TestFileMemo();
            var testFileName = "~/add-me-check-me.dat";
            var file         = memos.CreateTestFile(testFileName, 123, 21);
            var memo         = TestFileMemo.ComputeMemoValue(file);

            Assert.True(memos.AddMemo(testFileName, memo));

            var storedMemo = TestFileMemo.InitialMemoValue;

            Assert.True(memos.CheckMemo(testFileName, out storedMemo));
            Assert.Equal(memo, storedMemo);
            file.Dispose();
            file = null;
        }
Beispiel #6
0
        public void FileMemo_CheckAddMemoOfValidFile_AddsMemo()
        {
            var memos        = new TestFileMemo();
            var testFileName = "~/check-and-add-me.dat";
            var file         = memos.CreateTestFile(testFileName, 97, 5);
            var expectedMemo = TestFileMemo.ComputeMemoValue(file);

            Assert.NotEqual(TestFileMemo.InitialMemoValue, expectedMemo);

            int memo = 1;

            Assert.True(memos.CheckAddMemo(testFileName, null, out memo));
            Assert.True(memos.CalledGetMemo);
            Assert.Equal(expectedMemo, memo);
            file.Dispose();
            file = null;
        }
Beispiel #7
0
        public void FileMemo_CheckMemoOfAddedFileAfterRenaming_MemoNotFound()
        {
            var memos        = new TestFileMemo();
            var testFileName = "~/add-me-check-me-rename-me.dat";
            var file         = memos.CreateTestFile(testFileName, 64, 12);
            var memo         = TestFileMemo.ComputeMemoValue(file);

            Assert.True(memos.AddMemo(testFileName, memo));
            var returnedMemo = memo;

            Assert.True(memos.CheckMemo(testFileName, out returnedMemo));

            var newTestFileName = "~/add-me-check-me-rename-me.dat~";

            memos.Storage.Rename(testFileName, newTestFileName);

            Assert.False(memos.CheckMemo(testFileName, out returnedMemo));
            Assert.Equal(TestFileMemo.InitialMemoValue, returnedMemo);
            file.Dispose();
            file = null;
        }
Beispiel #8
0
        public void FileMemo_CheckMemoOfAddedFileAfterLastWriteTimeChanges_MemoNotFound()
        {
            var memos        = new TestFileMemo();
            var testFileName = "~/add-me-check-me-change-write-time.dat";
            var file         = memos.CreateTestFile(testFileName, 64, 12);
            var memo         = TestFileMemo.ComputeMemoValue(file);

            Assert.True(memos.AddMemo(testFileName, memo));

            var originalLastWriteTime = memos.Storage.LastWriteTimeUtc(testFileName);

            Thread.Sleep(1); // ugh... but tests can run fast enough to fail w/ equal timestamps
            var newLastWriteTime = DateTime.UtcNow;

            Assert.NotEqual(originalLastWriteTime, newLastWriteTime);
            memos.Storage.SetLastWriteTimeUtc(testFileName, newLastWriteTime);

            var returnedMemo = memo;

            Assert.False(memos.CheckMemo(testFileName, out returnedMemo));
            Assert.Equal(TestFileMemo.InitialMemoValue, returnedMemo);
            file.Dispose();
            file = null;
        }