From da85792defe30b1c684ef6ba654b33e9f37beb18 Mon Sep 17 00:00:00 2001 From: Daniel Woodward <16451892+DrBarnabus@users.noreply.github.com> Date: Fri, 8 Aug 2025 22:10:08 +0100 Subject: [PATCH] feat: Add missed 16-parameter overloads in `ReturnsExtensions` --- .../Extensions/ReturnsExtensionsTests.cs | 64 +++++++++++++++++ src/Mimic/Extensions/ReturnsExtensions.cs | 72 ++++++++++++++++++- 2 files changed, 134 insertions(+), 2 deletions(-) diff --git a/src/Mimic.UnitTests/Extensions/ReturnsExtensionsTests.cs b/src/Mimic.UnitTests/Extensions/ReturnsExtensionsTests.cs index 7b09881..b47179f 100644 --- a/src/Mimic.UnitTests/Extensions/ReturnsExtensionsTests.cs +++ b/src/Mimic.UnitTests/Extensions/ReturnsExtensionsTests.cs @@ -355,6 +355,36 @@ public static async Task Returns_WithFifteenParamsAndValueFunction_ShouldReturnV (await mimic.Object.Task(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15)).ShouldBe(value); } + + [Theory, AutoData] + public static async Task Returns_WithSixteenParamsAndValueFunction_ShouldReturnValue(int value, int t1, int t2, int t3, int t4, int t5, int t6, int t7, int t8, int t9, int t10, int t11, int t12, int t13, int t14, int t15, int t16) + { + var mimic = new Mimic(); + + mimic.Setup(m => m.Task(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16)) + .Returns((int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16) => + { + a1.ShouldBe(t1); + a2.ShouldBe(t2); + a3.ShouldBe(t3); + a4.ShouldBe(t4); + a5.ShouldBe(t5); + a6.ShouldBe(t6); + a7.ShouldBe(t7); + a8.ShouldBe(t8); + a9.ShouldBe(t9); + a10.ShouldBe(t10); + a11.ShouldBe(t11); + a12.ShouldBe(t12); + a13.ShouldBe(t13); + a14.ShouldBe(t14); + a15.ShouldBe(t15); + a16.ShouldBe(t16); + return value; + }); + + (await mimic.Object.Task(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16)).ShouldBe(value); + } } public static class ValueTaskOfT @@ -710,6 +740,36 @@ public static async Task Returns_WithFifteenParamsAndValueFunction_ShouldReturnV (await mimic.Object.ValueTask(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15)).ShouldBe(value); } + + [Theory, AutoData] + public static async Task Returns_WithSixteenParamsAndValueFunction_ShouldReturnValue(int value, int t1, int t2, int t3, int t4, int t5, int t6, int t7, int t8, int t9, int t10, int t11, int t12, int t13, int t14, int t15, int t16) + { + var mimic = new Mimic(); + + mimic.Setup(m => m.ValueTask(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16)) + .Returns((int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16) => + { + a1.ShouldBe(t1); + a2.ShouldBe(t2); + a3.ShouldBe(t3); + a4.ShouldBe(t4); + a5.ShouldBe(t5); + a6.ShouldBe(t6); + a7.ShouldBe(t7); + a8.ShouldBe(t8); + a9.ShouldBe(t9); + a10.ShouldBe(t10); + a11.ShouldBe(t11); + a12.ShouldBe(t12); + a13.ShouldBe(t13); + a14.ShouldBe(t14); + a15.ShouldBe(t15); + a16.ShouldBe(t16); + return value; + }); + + (await mimic.Object.ValueTask(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16)).ShouldBe(value); + } } // ReSharper disable once MemberCanBePrivate.Global @@ -747,6 +807,8 @@ internal interface ISubject public Task Task(int t1, int t2, int t3, int t4, int t5, int t6, int t7, int t8, int t9, int t10, int t11, int t12, int t13, int t14, int t15); + public Task Task(int t1, int t2, int t3, int t4, int t5, int t6, int t7, int t8, int t9, int t10, int t11, int t12, int t13, int t14, int t15, int t16); + public ValueTask ValueTask(); public ValueTask ValueTask(int t); @@ -778,5 +840,7 @@ internal interface ISubject public ValueTask ValueTask(int t1, int t2, int t3, int t4, int t5, int t6, int t7, int t8, int t9, int t10, int t11, int t12, int t13, int t14); public ValueTask ValueTask(int t1, int t2, int t3, int t4, int t5, int t6, int t7, int t8, int t9, int t10, int t11, int t12, int t13, int t14, int t15); + + public ValueTask ValueTask(int t1, int t2, int t3, int t4, int t5, int t6, int t7, int t8, int t9, int t10, int t11, int t12, int t13, int t14, int t15, int t16); } } diff --git a/src/Mimic/Extensions/ReturnsExtensions.cs b/src/Mimic/Extensions/ReturnsExtensions.cs index a027e2a..5c3aa24 100644 --- a/src/Mimic/Extensions/ReturnsExtensions.cs +++ b/src/Mimic/Extensions/ReturnsExtensions.cs @@ -409,13 +409,47 @@ public static IReturnsResult ReturnsAn that can be used to configure additional return behaviours. /// /// This method allows the return value to be computed based on the method's arguments while automatically handling the task wrapping. - /// This is the maximum parameter count supported by these extension methods. + /// The function receives the arguments passed to the mocked method at invocation time. /// public static IReturnsResult Returns(this IReturns> mimic, Func valueFunction) { return mimic.Returns((T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15) => Task.FromResult(valueFunction(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15))); } + /// + /// Configures the setup to return a value computed by the specified function using the method's sixteen arguments, + /// wrapped in a completed . + /// + /// The type of the method's first argument. + /// The type of the method's second argument. + /// The type of the method's third argument. + /// The type of the method's fourth argument. + /// The type of the method's fifth argument. + /// The type of the method's sixth argument. + /// The type of the method's seventh argument. + /// The type of the method's eighth argument. + /// The type of the method's ninth argument. + /// The type of the method's tenth argument. + /// The type of the method's eleventh argument. + /// The type of the method's twelfth argument. + /// The type of the method's thirteenth argument. + /// The type of the method's fourteenth argument. + /// The type of the method's fifteenth argument. + /// The type of the method's sixteenth argument. + /// The type of the value to be returned. + /// The returns configuration instance. + /// A function that takes the method's arguments and computes the return value. + /// An that can be used to configure additional return behaviours. + /// + /// This method allows the return value to be computed based on the method's arguments while automatically handling the task wrapping. + /// The function receives the arguments passed to the mocked method at invocation time. + /// This is the maximum parameter count supported by these extension methods. + /// + public static IReturnsResult Returns(this IReturns> mimic, Func valueFunction) + { + return mimic.Returns((T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15, T16 t16) => Task.FromResult(valueFunction(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16))); + } + #endregion #region ValueTask @@ -821,12 +855,46 @@ public static IReturnsResult ReturnsAn that can be used to configure additional return behaviours. /// /// This method allows the return value to be computed based on the method's arguments while automatically handling the ValueTask wrapping. - /// This is the maximum parameter count supported by these extension methods. + /// The function receives the arguments passed to the mocked method at invocation time. /// public static IReturnsResult Returns(this IReturns> mimic, Func valueFunction) { return mimic.Returns((T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15) => new ValueTask(valueFunction(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15))); } + /// + /// Configures the setup to return a value computed by the specified function using the method's sixteen arguments, + /// wrapped in a . + /// + /// The type of the method's first argument. + /// The type of the method's second argument. + /// The type of the method's third argument. + /// The type of the method's fourth argument. + /// The type of the method's fifth argument. + /// The type of the method's sixth argument. + /// The type of the method's seventh argument. + /// The type of the method's eighth argument. + /// The type of the method's ninth argument. + /// The type of the method's tenth argument. + /// The type of the method's eleventh argument. + /// The type of the method's twelfth argument. + /// The type of the method's thirteenth argument. + /// The type of the method's fourteenth argument. + /// The type of the method's fifteenth argument. + /// The type of the method's sixteenth argument. + /// The type of the value to be returned. + /// The returns configuration instance. + /// A function that takes the method's arguments and computes the return value. + /// An that can be used to configure additional return behaviours. + /// + /// This method allows the return value to be computed based on the method's arguments while automatically handling the ValueTask wrapping. + /// The function receives the arguments passed to the mocked method at invocation time. + /// This is the maximum parameter count supported by these extension methods. + /// + public static IReturnsResult Returns(this IReturns> mimic, Func valueFunction) + { + return mimic.Returns((T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15, T16 t16) => new ValueTask(valueFunction(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16))); + } + #endregion }