private void SetupBuffers(params int?[] snapshotSizes) { var buffers = new IBuffer[snapshotSizes.Length]; for (var i = 0; i < snapshotSizes.Length; i++) { buffers[i] = Substitute.For <IBuffer>(); var snapshotSize = snapshotSizes[i]; if (snapshotSize == null) { buffers[i].TryMakeSnapshot().ReturnsNull(); } else { var snapshotData = new byte[snapshotSize.Value]; var snapshotState = new BufferState(snapshotData.Length, RecordsPerBuffer); var snapshot = new BufferSnapshot(buffers[i], snapshotState, snapshotData); buffers[i].TryMakeSnapshot().Returns(snapshot); } } pool.GetEnumerator().Returns(_ => (buffers as IReadOnlyList <IBuffer>).GetEnumerator()); }