public void SomePayload( bool largArrayPool, bool excessSpan, [CombinatorialValues(0, PayloadSize - 1, PayloadSize, PayloadSize + 1)] int sizeHint, [CombinatorialValues(1, 2, 3, PayloadSize)] int stepCount) { this.mockPool.MinArraySizeFactor = largArrayPool ? 2.0 : 1.0; var prefixWriter = new PrefixingBufferWriter <byte>(this.sequence, Prefix.Length, sizeHint); int stepSize = Payload.Length / stepCount; int expectedLength = 0; for (int i = 0; i < stepCount - 1; i++) { var spanToWrite = Payload.Span.Slice(stepSize * i, stepSize); if (excessSpan) { var targetSpan = prefixWriter.GetSpan((int)(spanToWrite.Length * 1.5)); spanToWrite.CopyTo(targetSpan); prefixWriter.Advance(spanToWrite.Length); } else { prefixWriter.Write(spanToWrite); } expectedLength += spanToWrite.Length; Assert.Equal(expectedLength, prefixWriter.Length); } // The last step fills in the remainder as well. prefixWriter.Write(Payload.Span.Slice(stepSize * (stepCount - 1))); this.PayloadCompleteHelper(prefixWriter); }
public void ReuseAfterComplete() { var prefixWriter = new PrefixingBufferWriter <byte>(this.sequence, Prefix.Length, 0); prefixWriter.Write(Payload.Span); Assert.Equal(Payload.Length, prefixWriter.Length); this.PayloadCompleteHelper(prefixWriter); this.sequence.Reset(); Assert.Equal(0, prefixWriter.Length); prefixWriter.Write(Payload.Span); Assert.Equal(Payload.Length, prefixWriter.Length); this.PayloadCompleteHelper(prefixWriter); }