public void WhenSynchedProcessesMessagesOfExpectedLength200BytesWithStartEndMarkersCopiesToRecvQueue() { //Arrange var hasBeenCalled = false; var commsIter = 0; var mockedMessage = new byte[200]; var mockCommsDevice = new Mock <ICommsDevice>(); mockedMessage[0] = (byte)'<'; mockedMessage[1] = (byte)'<'; mockedMessage[198] = (byte)'>'; mockedMessage[199] = (byte)'>'; mockCommsDevice.SetupSequence(x => x.BytesToRead) .Returns(2); mockCommsDevice.Setup(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>())) .Callback((byte[] buffer, int offset, int count) => { if (!hasBeenCalled) { var synchBytes = System.Text.Encoding.ASCII.GetBytes("##"); buffer[0] = synchBytes[0]; buffer[1] = synchBytes[1]; hasBeenCalled = true; } }); mockCommsDevice.Setup(x => x.ReadByte()).Returns(() => { return(mockedMessage[commsIter]); }); var commsChannel = new BasicChannel(mockCommsDevice.Object); //Act commsChannel.ProcessCommsChannel(); while (commsIter < 200) { commsChannel.ProcessCommsChannel(); commsIter++; } //Assert Assert.AreEqual(commsChannel.DataPcksAvailable(), true); }