public void First() { stream = new RequestStream(null, firstSeg, firstSeg.Count); mockObserver.Setup(o => o.OnNext(It.Is<ArraySegment<byte>>(v => v.Equals(firstSeg)))).Verifiable(); mockObserver.Setup(o => o.OnError(It.IsAny<Exception>())).Throws(new Exception("Should not have got error.")); mockObserver.Setup(o => o.OnCompleted()).Verifiable(); stream.ReadAsync().Subscribe(mockObserver.Object); mockObserver.Verify(); }
public void FirstAndOne() { var restSeg = new ArraySegment<byte>(buffer, first.Length, last.Length); stream = new RequestStream(mockSocket.Object, firstSeg, buffer.Length); mockObserver.Setup(o => o.OnNext(It.Is<ArraySegment<byte>>(v => v.Equals(firstSeg)))).Verifiable(); mockObserver.Setup(o => o.OnError(It.IsAny<Exception>())).Throws(new Exception("Should not have got error.")); mockObserver.Setup(o => o.OnCompleted()).Verifiable(); stream.ReadAsync().Subscribe(mockObserver.Object); mockObserver.Verify(); int bufferSize = 1024; mockSocket .Setup(s => s.Read( It.Is<byte[]>(b => b.Length == bufferSize), It.Is<int>(o => o == 0), It.Is<int>(c => c == bufferSize))) .Returns<byte[], int, int>((byte[] b, int o, int c) => Observable.Create<int>(ob => { ob.OnNext(restSeg.Count); ob.OnCompleted(); return () => { }; })) .Verifiable(); mockObserver.Setup(o => o.OnNext(It.Is<ArraySegment<byte>>(v => v.Count == restSeg.Count))).Verifiable(); mockObserver.Setup(o => o.OnError(It.IsAny<Exception>())).Throws(new Exception("Should not have got error.")); mockObserver.Setup(o => o.OnCompleted()).Verifiable(); stream.ReadAsync().Subscribe(mockObserver.Object); mockSocket.Verify(); mockObserver.Verify(); }