public void can_determine_if_delegate_has_been_disposed() { using(var inner = new MemoryStream()) { var @delegate = new MessageStreamDelegate(inner); Assert.False(@delegate.IsDisposed); ((IDisposable)@delegate).Dispose(); Assert.True(@delegate.IsDisposed); } }
public void fill_delegates_to_inner() { var buffer = new byte[10]; var inner = new Mock<Stream>(MockBehavior.Strict); var @delegate = new MessageStreamDelegate(inner.Object); inner.Setup(x => x.Read(buffer, 0, buffer.Length)) .Returns(buffer.Length) .Verifiable(); @delegate.Fill(buffer, 0, buffer.Length); inner.VerifyAll(); }
public void fill_copies_data_to_buffer() { var actual = new byte[10]; var expected = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; using(var inner = new MemoryStream(expected)) { var @delegate = new MessageStreamDelegate(inner); Assert.True(@delegate.Fill(actual, 0, actual.Length)); Assert.Equal(expected, actual); } }
public void fill_copies_count_elements_to_buffer_starting_at_offset() { var actual = new byte[9]; var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var expected = new byte[] { 0, 1, 2, 3, 4, 5, 6, 0, 0 }; using(var inner = new MemoryStream(data)) { var @delegate = new MessageStreamDelegate(inner); Assert.True(@delegate.Fill(actual, 1, 6)); Assert.Equal(expected, actual); } }
public void fill_returns_false_when_count_has_not_been_read() { var buffer = new byte[10]; using(var inner = new MemoryStream(new byte[5])) { var @delegate = new MessageStreamDelegate(inner); Assert.False(@delegate.Fill(buffer, 0, buffer.Length)); } }
public void inner_is_disposed_when_delegate_is_disposed() { using(var inner = new MemoryStream()) { var @delegate = new MessageStreamDelegate(inner); ((IDisposable)@delegate).Dispose(); Assert.Throws<ObjectDisposedException>(() => inner.ReadByte()); } }
public void fill_throws_if_delegate_has_been_disposed() { using(var inner = new MemoryStream()) { var @delegate = new MessageStreamDelegate(inner); ((IDisposable)@delegate).Dispose(); Assert.Throws<ObjectDisposedException>(() => @delegate.Fill(new byte[1], 0, 1)); } }