Provides An AK.F1.Timing.Playback.IRecordedMessageReader which reads AK.F1.Timing.Messages which have been recorded by a AK.F1.Timing.Playback.RecordingMessageReader.
Inheritance: MessageReaderBase, IRecordedMessageReader
        public void reader_closes_path_when_disposed()
        {
            var path = Path.GetTempFileName();

            using(var reader = new RecordedMessageReader(path)) { }

            Assert.DoesNotThrow(() => File.Delete(path));
        }
 public void reader_closes_input_when_disposed_if_it_owns_it()
 {
     using(var input = new MemoryStream())
     {
         using(var reader = new RecordedMessageReader(input, true)) { }
         Assert.Throws<ObjectDisposedException>(() => input.WriteByte(0));
     }
 }
        public void path_be_opened_whilst_reader_has_it_open()
        {
            var path = Path.GetTempFileName();

            using(var reader = new RecordedMessageReader(path))
            {
                Assert.DoesNotThrow(() => File.OpenRead(path).Dispose());
            }

            File.Delete(path);
        }
        public void path_cannot_be_modified_whilst_reader_has_it_open()
        {
            var path = Path.GetTempFileName();

            using(var reader = new RecordedMessageReader(path))
            {
                Assert.Throws<IOException>(() => File.Delete(path));
                Assert.Throws<IOException>(() => File.OpenWrite(path).Dispose());
            }

            File.Delete(path);
        }
        public void can_read_recorded_messages()
        {
            Message actual;
            Message[] messages = CreateMessages();
            Stream stream = RecordMessages(messages);

            using(var reader = new RecordedMessageReader(stream, true))
            {
                foreach(var expected in messages)
                {
                    actual = reader.Read();
                    Assert.IsType(expected.GetType(), actual);
                }
            }
        }
        public void messages_are_played_back_in_real_time()
        {
            Stopwatch sw = new Stopwatch();
            TimeSpan delay = TimeSpan.FromMilliseconds(15);
            TimeSpan delayLow = TimeSpan.FromMilliseconds(14);
            TimeSpan delayHigh = TimeSpan.FromMilliseconds(16);
            Stream stream = RecordMessages(delay, CreateMessages());

            using(var reader = new RecordedMessageReader(stream, true))
            {
                while(reader.Read() != null)
                {
                    // This isn't great, the delay between the first message isn't written.
                    if(sw.IsRunning)
                    {
                        Assert.InRange(sw.Elapsed, delayLow, delayHigh);
                        sw.Reset();
                    }
                    sw.Start();
                }
            }
        }
 public void reader_does_not_close_input_when_disposed_if_it_does_not_own_it()
 {
     using(var input = new MemoryStream())
     {
         using(var reader = new RecordedMessageReader(input, false)) { }
         Assert.DoesNotThrow(() => input.WriteByte(0));
     }
 }