public void StreamWrapperShouldCallIStreamSeekWithValidArgumentsWhenSeekCalled(long offset, SeekOrigin origin) { // Arrange int expectedDwOrigin = 0; switch (origin) { case SeekOrigin.Begin: expectedDwOrigin = 0; break; case SeekOrigin.Current: expectedDwOrigin = 1; break; case SeekOrigin.End: expectedDwOrigin = 2; break; } var streamMock = new Mock <IStream>(); using (var streamWrapper = new ReadonlyStream(streamMock.Object)) { // Act streamWrapper.Seek(offset, origin); // Assert streamMock.Verify(_ => _.Seek(It.Is <long>(actualOffset => actualOffset == offset), It.Is <int>(actualDwOrigin => actualDwOrigin == expectedDwOrigin), It.IsAny <IntPtr>()), Times.Once); } }
public void StreamWrapper_ShouldReturnValidPosition_WhenSeekCalled() { // Arrange long position = 5; var stremMock = new Mock <IStream>(); stremMock .Setup(x => x.Seek(It.IsAny <long>(), It.IsAny <int>(), It.IsAny <IntPtr>())) .Callback <long, int, IntPtr>((dlibMove, dwOrigin, plibNewPosition) => { Marshal.WriteInt64(plibNewPosition, position); }); var streamWrapper = new ReadonlyStream(stremMock.Object); // Act var actualPosition = streamWrapper.Seek(0, SeekOrigin.Begin); // Assert Assert.AreEqual(position, actualPosition); }