public void WrapsIOExceptionsDuringWrite() { MockFileSystem fs = new MockFileSystem(); FileSystemTaskQueue dut = CreateFileBasedQueue(fs, Item1EntryText); dut.IsEmpty.ShouldBeFalse(); 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; FileSystemTaskQueue.TryCreate(null, MockEntryFileName, fs, out dut, out error).ShouldEqual(true); dut.IsEmpty.ShouldBeFalse(); using (dut) { FileSystemTask output; dut.TryPeek(out output).ShouldEqual(true); output.ShouldEqual(Item1Payload); dut.DequeueAndFlush(output); } dut.IsEmpty.ShouldBeTrue(); }
public void StoresDeleteRecord() { const string DeleteRecord = "D 1\r\n"; MockFileSystem fs = new MockFileSystem(); FileSystemTaskQueue dut = CreateFileBasedQueue(fs, Item1EntryText); dut.IsEmpty.ShouldBeFalse(); // Add a second entry to keep FileBasedQueue from setting the stream length to 0 dut.EnqueueAndFlush(Item2Payload); dut.IsEmpty.ShouldBeFalse(); fs.File.ReadAsString().ShouldEqual(Item1EntryText + Item2EntryText); fs.File.ReadAt(fs.File.Length - 2, 2).ShouldEqual("\r\n"); dut.DequeueAndFlush(Item1Payload); dut.IsEmpty.ShouldBeFalse(); dut.Count.ShouldEqual(1); FileSystemTask item; dut.TryPeek(out item).ShouldEqual(true); item.ShouldEqual(Item2Payload); dut.IsEmpty.ShouldBeFalse(); dut.Count.ShouldEqual(1); 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); }
public void StoresAddRecord() { MockFileSystem fs = new MockFileSystem(); FileSystemTaskQueue dut = CreateFileBasedQueue(fs, string.Empty); dut.EnqueueAndFlush(Item1Payload); fs.File.ReadAsString().ShouldEqual(Item1EntryText); }