public void DiscDriveFailureDuringOpenWrite()
        {
            var stream = new TestStream();

            using (var tf = TeaFile <int> .Create(stream))
            {
                tf.Write(111);
            }
            stream.Position          = 0;
            stream.FailAfterPosition = 17;
            Executing.This(() => TeaFile <int> .OpenWrite(stream)).Should().Throw <FileFormatException>()
            .Exception.InnerException.Should().Be.OfType <IOException>();
        }
        public void FlushIsCalled()
        {
            var stream = new TestStream();
            var tf     = TeaFile <int> .Create(stream);

            tf.Write(Enumerable.Range(1, 10));
            stream.FlushWasCalled = false; // the header was flushed already, so we reset the flag here

            stream.FlushWasCalled.Should().Be.False();
            tf.Flush(); // we can easily test only that the call does not except
            stream.FlushWasCalled.Should().Be.True();

            tf.Close();
        }
        public void IOException()
        {
            var stream = new TestStream();

            using (var tf = TeaFile <Event <int> > .Create(stream))
            {
                Time t = new Time(2000, 1, 1);
                tf.Write(Enumerable.Range(1, 5).Select(i => new Event <int> {
                    Time = t.AddDays(i), Value = i
                }));
            }
            stream.Position          = 0;
            stream.FailAfterPosition = stream.Length - 2;
            using (var tf = TeaFile <Event <int> > .OpenRead(stream))
            {
                tf.Count.Should().Be(5); // the count is still 5, the stream length has not changed
                tf.Read().Value.Should().Be(1);
                tf.Read().Value.Should().Be(2);
                tf.Read().Value.Should().Be(3);
                tf.Read().Value.Should().Be(4);
                Executing.This(() => tf.Read()).Should().Throw <IOException>();
            }
        }
예제 #4
0
 public void IOException()
 {
     var stream = new TestStream();
     using (var tf = TeaFile<Event<int>>.Create(stream))
     {
         Time t = new Time(2000, 1, 1);
         tf.Write(Enumerable.Range(1, 5).Select(i => new Event<int> {Time = t.AddDays(i), Value = i}));
     }
     stream.Position = 0;
     stream.FailAfterPosition = stream.Length - 2;
     using (var tf = TeaFile<Event<int>>.OpenRead(stream))
     {
         tf.Count.Should().Be(5); // the count is still 5, the stream length has not changed
         tf.Read().Value.Should().Be(1);
         tf.Read().Value.Should().Be(2);
         tf.Read().Value.Should().Be(3);
         tf.Read().Value.Should().Be(4);
         Executing.This(() => tf.Read()).Should().Throw<IOException>();
     }
 }
예제 #5
0
 public void DiscDriveFailureDuringOpenWrite()
 {
     var stream = new TestStream();
     using (var tf = TeaFile<int>.Create(stream))
     {
         tf.Write(111);
     }
     stream.Position = 0;
     stream.FailAfterPosition = 17;
     Executing.This(() => TeaFile<int>.OpenWrite(stream)).Should().Throw<FileFormatException>()
         .Exception.InnerException.Should().Be.OfType<IOException>();
 }
예제 #6
0
 public void DiscDriveFailureDuringCreate()
 {
     var stream = new TestStream();
     stream.FailAfterPosition = 17;
     Executing.This(() => TeaFile<int>.Create(stream)).Should().Throw<IOException>();
 }
예제 #7
0
        public void FlushIsCalled()
        {
            var stream = new TestStream();
            var tf = TeaFile<int>.Create(stream);
            tf.Write(Enumerable.Range(1, 10));
            stream.FlushWasCalled = false; // the header was flushed already, so we reset the flag here

            stream.FlushWasCalled.Should().Be.False();
            tf.Flush(); // we can easily test only that the call does not except
            stream.FlushWasCalled.Should().Be.True();

            tf.Close();
        }
예제 #8
0
 public void TestStreamTest()
 {
     TestStream stream;
     using (stream = new TestStream())
     using (var tf = TeaFile<int>.Create(stream))
     {
     }
     stream.WasDisposed.Should().Be.True();
 }
예제 #9
0
 public void TeaFileDoesNotDisposeExternalStream()
 {
     var stream = new TestStream();
     using (var tf = TeaFile<int>.Create(stream))
     {
     }
     stream.WasDisposed.Should().Be.False();
 }