Exemplo n.º 1
0
 public void Deleting_last_record_truncates_file()
 {
     AppendRecord(1, false);
     AppendRecord(2, true);
     AppendRecord(3, false);
     var queueStream = new SingleFileQueueStream(_stream);
     var handle1 = queueStream.ReadNextRecord().Handle;
     var handle2 = queueStream.ReadNextRecord().Handle;
     queueStream.DeleteRecord(handle1);
     queueStream.DeleteRecord(handle2);
     Assert.AreEqual(0, _stream.Length);
 }
Exemplo n.º 2
0
 public void Corrupt_record_is_ignored_at_initialization()
 {
     var v1 = "asdsdasdasdasdasd";
     var v2 = "asdasdsadasdwwdsdw";
     AppendRecord(v1, false);
     for(byte i = 0; i < 6; i++) {
         _stream.WriteByte(i);
     }
     AppendRecord(v2, false);
     var queueStream = new SingleFileQueueStream(_stream);
     Assert.AreEqual(2,queueStream.UnreadCount);
     Assert.AreEqual(v1, GetStringValue(queueStream.ReadNextRecord().Stream));
     Assert.AreEqual(v2, GetStringValue(queueStream.ReadNextRecord().Stream));
 }
Exemplo n.º 3
0
 public void Corrupt_record_does_not_stop_further_appending_dequeueing()
 {
     var v1 = "asdsdasdasdasdasd";
     var v2 = "asdasdsadasdwwdsdw";
     AppendRecord(v1, false);
     for(byte i = 0; i < 6; i++) {
         _stream.WriteByte(i);
     }
     var position = _stream.Position;
     var queueStream = new SingleFileQueueStream(_stream);
     Assert.AreEqual(1, queueStream.UnreadCount);
     using(var stream = new MemoryStream()) {
         stream.Write(Encoding.UTF8.GetBytes(v2));
         stream.Seek(0, SeekOrigin.Begin);
         queueStream.AppendRecord(stream, stream.Length);
         AssertRecord(v2, position, false);
         Assert.AreEqual(2, queueStream.UnreadCount);
     }
     Assert.AreEqual(v1, GetStringValue(queueStream.ReadNextRecord().Stream));
     Assert.AreEqual(v2, GetStringValue(queueStream.ReadNextRecord().Stream));
 }
Exemplo n.º 4
0
 public void Can_read_consecutive_records()
 {
     AppendRecord(1, false);
     AppendRecord(2, true);
     AppendRecord(3, false);
     var queueStream = new SingleFileQueueStream(_stream);
     Assert.AreEqual(1, GetIntValue(queueStream.ReadNextRecord().Stream));
     Assert.AreEqual(3, GetIntValue(queueStream.ReadNextRecord().Stream));
     Assert.AreEqual(0, queueStream.UnreadCount);
 }
Exemplo n.º 5
0
 public void Can_delete_record()
 {
     AppendRecord(1, false);
     AppendRecord(2, false);
     var queueStream = new SingleFileQueueStream(_stream);
     var handle = queueStream.ReadNextRecord().Handle;
     queueStream.DeleteRecord(handle);
     AssertRecord(1, 0, true);
 }
Exemplo n.º 6
0
 public void Can_append_record_to_truncated_file()
 {
     AppendRecord(1, false);
     var queueStream = new SingleFileQueueStream(_stream);
     var handle = queueStream.ReadNextRecord().Handle;
     queueStream.DeleteRecord(handle);
     using(var stream = new MemoryStream()) {
         stream.Write(BitConverter.GetBytes(10));
         stream.Seek(0, SeekOrigin.Begin);
         queueStream.AppendRecord(stream, stream.Length);
         AssertRecord(10, 0, false);
         Assert.AreEqual(1, queueStream.UnreadCount);
     }
 }