Esempio n. 1
0
        public void TruncatesWhenEmpty()
        {
            MockFileSystem           fs  = new MockFileSystem();
            BackgroundGitUpdateQueue dut = CreateFileBasedQueue(fs, Item1EntryText);

            dut.DequeueAndFlush(Item1Payload);

            fs.File.Length.ShouldEqual(0);
        }
Esempio n. 2
0
        public void WrapsIOExceptionsDuringWrite()
        {
            MockFileSystem           fs  = new MockFileSystem();
            BackgroundGitUpdateQueue dut = CreateFileBasedQueue(fs, Item1EntryText);

            fs.File.TruncateWrites = true;

            Assert.Throws <FileBasedCollectionException>(() => dut.EnqueueAndFlush(Item2Payload));

            fs.File.TruncateWrites = false;
            fs.File.ReadAt(fs.File.Length - 2, 2).ShouldNotEqual("\r\n", "Bad Test: The file is supposed to be corrupt.");

            string error;

            BackgroundGitUpdateQueue.TryCreate(null, MockEntryFileName, fs, out dut, out error).ShouldEqual(true);
            using (dut)
            {
                BackgroundGitUpdate output;
                dut.TryPeek(out output).ShouldEqual(true);
                output.ShouldEqual(Item1Payload);
                dut.DequeueAndFlush(output);
            }
        }
Esempio n. 3
0
        public void StoresDeleteRecord()
        {
            const string DeleteRecord = "D 1\r\n";

            MockFileSystem           fs  = new MockFileSystem();
            BackgroundGitUpdateQueue dut = CreateFileBasedQueue(fs, Item1EntryText);

            // Add a second entry to keep FileBasedQueue from setting the stream length to 0
            dut.EnqueueAndFlush(Item2Payload);

            fs.File.ReadAsString().ShouldEqual(Item1EntryText + Item2EntryText);
            fs.File.ReadAt(fs.File.Length - 2, 2).ShouldEqual("\r\n");

            dut.DequeueAndFlush(Item1Payload);
            dut.Count.ShouldEqual(1);

            BackgroundGitUpdate item;

            dut.TryPeek(out item).ShouldEqual(true);
            item.ShouldEqual(Item2Payload);

            fs.File.Length.ShouldEqual(Encoding.UTF8.GetByteCount(Item1EntryText) + Item2EntryText.Length + DeleteRecord.Length);
            fs.File.ReadAt(Encoding.UTF8.GetByteCount(Item1EntryText) + Item2EntryText.Length, DeleteRecord.Length).ShouldEqual(DeleteRecord);
        }