private void ShouldAssembleTwoPartMessage(IMutableDirectBuffer srcBuffer) { A.CallTo(() => header.Flags).ReturnsNextFromSequence(FrameDescriptor.BEGIN_FRAG_FLAG, FrameDescriptor.END_FRAG_FLAG, FrameDescriptor.END_FRAG_FLAG); // Need to add this twice because FakeItEasy doesn't fall back to the implementation const int offset = 0; var length = srcBuffer.Capacity / 2; srcBuffer.SetMemory(0, length, 65); srcBuffer.SetMemory(length, length, 66); adapter.OnFragment(srcBuffer, offset, length, header); adapter.OnFragment(srcBuffer, length, length, header); Func <UnsafeBuffer, bool> bufferAssertion = capturedBuffer => { for (var i = 0; i < srcBuffer.Capacity; i++) { if (capturedBuffer.GetByte(i) != srcBuffer.GetByte(i)) { return(false); } } return(true); }; Func <Header, bool> headerAssertion = capturedHeader => capturedHeader.SessionId == SESSION_ID && capturedHeader.Flags == FrameDescriptor.END_FRAG_FLAG; A.CallTo(() => delegateFragmentHandler.OnFragment( A <UnsafeBuffer> .That.Matches(bufferAssertion, "buffer"), offset, length * 2, A <Header> .That.Matches(headerAssertion, "header"))) .MustHaveHappened(1, Times.Exactly); }
private void ShouldAssembleFourPartMessage(IMutableDirectBuffer srcBuffer) { A.CallTo(() => header.Flags).ReturnsNextFromSequence <byte>(FrameDescriptor.BEGIN_FRAG_FLAG, 0, 0, FrameDescriptor.END_FRAG_FLAG, FrameDescriptor.END_FRAG_FLAG); const int offset = 0; var length = srcBuffer.Capacity / 4; for (var i = 0; i < 4; i++) { srcBuffer.SetMemory(i * length, length, (byte)(65 + i)); } adapter.OnFragment(srcBuffer, offset, length, header); adapter.OnFragment(srcBuffer, offset + length, length, header); adapter.OnFragment(srcBuffer, offset + (length * 2), length, header); adapter.OnFragment(srcBuffer, offset + (length * 3), length, header); Func <UnsafeBuffer, bool> bufferAssertion = capturedBuffer => { for (var i = 0; i < srcBuffer.Capacity; i++) { if (capturedBuffer.GetByte(i) != srcBuffer.GetByte(i)) { return(false); } } return(true); }; Func <Header, bool> headerAssertion = capturedHeader => capturedHeader.SessionId == SESSION_ID && capturedHeader.Flags == FrameDescriptor.END_FRAG_FLAG; A.CallTo(() => delegateFragmentHandler.OnFragment( A <UnsafeBuffer> .That.Matches(bufferAssertion, "buffer"), offset, length * 4, A <Header> .That.Matches(headerAssertion, "header"))) .MustHaveHappened(1, Times.Exactly); }