diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/RecordingHandlerTests.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/RecordingHandlerTests.cs index 05330b4d519..613ffde1ab0 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/RecordingHandlerTests.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/RecordingHandlerTests.cs @@ -789,7 +789,7 @@ aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in volup [Theory] [InlineData("", 1)] - [InlineData("small body", 10)] + [InlineData("small body", 5)] [InlineData("this is a body", 3)] [InlineData("This is a little bit longer of a body that we are dividing in 2", 2)] [InlineData(longBody, 5)] @@ -803,16 +803,20 @@ public void TestGetBatches(string input, int batchCount) var chunks = testRecordingHandler.GetBatches(bodyData, batchCount); int bodyPosition = 0; + int byteCount = 0; // ensure that all bytes are accounted for across the batches foreach(var chunk in chunks) { - for (int j = 0; j < chunk.Length; j++) + for (int j = 0; j < chunk.Length && bodyPosition < bodyData.Length; j++) { Assert.Equal(chunk[j], bodyData[bodyPosition]); bodyPosition++; + byteCount++; } } + + Assert.Equal(byteCount, bodyData.Length); } #endregion diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs index 2a2db44b813..bfe27e65823 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs @@ -484,13 +484,12 @@ public byte[][] GetBatches(byte[] bodyData, int batchCount) int chunkLength = bodyData.Length / batchCount; int remainder = (bodyData.Length % batchCount); - var batches = new byte[batchCount + remainder > 0 ? 1 : 0][]; + var batches = new byte[batchCount + (remainder > 0 ? 1 : 0)][]; for(int i = 0; i < batches.Length; i++) { var batch = new byte[chunkLength]; - - Array.Copy(bodyData, i * chunkLength, batch, 0, chunkLength); + Array.Copy(bodyData, i * chunkLength, batch, 0, i == batches.Length - 1 && batches.Length > 1 && remainder > 0 ? remainder : chunkLength); batches[i] = batch; }