public void cancelTransactionTest() { Stream stream = new MemoryStream(); TransactionalStreamReader target = new TransactionalStreamReader(stream); // Przygotuj dane testowe stream.WriteByte(9); stream.WriteByte(20); stream.WriteByte(31); stream.WriteByte(42); stream.Seek(0, SeekOrigin.Begin); target.startTransaction(); Assert.AreEqual(target.ReadByte(), 9); Assert.AreEqual(target.ReadByte(), 20); target.cancelTransaction(); target.startTransaction(); Assert.AreEqual(target.ReadByte(), 9); Assert.AreEqual(target.ReadByte(), 20); Assert.AreEqual(target.ReadByte(), 31); Assert.AreEqual(target.ReadByte(), 42); target.cancelTransaction(); Assert.AreEqual(stream.ReadByte(), -1); // Cały strumien został zjedzony }
public override bool match(TransactionalStreamReader s) { // First, read whatever is in the stream int newValue = 0; s.startTransaction(); for (int i = 0; i < Size; i++) { newValue |= s.ReadByte() << (8*i); } if (MinValue > newValue || newValue > MaxValue) { s.cancelTransaction(); return false; } if (myValue == null) { Value = newValue; s.commitTransaction(); return true; } else // myValue != null if (myValue == newValue) { s.commitTransaction(); return true; } else { s.cancelTransaction(); return false; } }