diff --git a/TUnit.Mocks.Benchmarks/CallbackBenchmarks.cs b/TUnit.Mocks.Benchmarks/CallbackBenchmarks.cs index 55b460abb4..9831a29169 100644 --- a/TUnit.Mocks.Benchmarks/CallbackBenchmarks.cs +++ b/TUnit.Mocks.Benchmarks/CallbackBenchmarks.cs @@ -100,7 +100,7 @@ public string TUnitMocks_CallbackWithArgs() var lastMessage = ""; var mock = Mock.Of(); mock.Log(TUnitArg.Any(), TUnitArg.Any()) - .Callback(args => lastMessage = (string)args[1]!); + .Callback((string _, string msg) => lastMessage = msg); var logger = mock.Object; logger.Log("INFO", "Test message 1"); diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_Inheriting_Multiple_Interfaces.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_Inheriting_Multiple_Interfaces.verified.txt index c3c0cd5fe2..82b9cccfc0 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_Inheriting_Multiple_Interfaces.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_Inheriting_Multiple_Interfaces.verified.txt @@ -139,14 +139,6 @@ namespace TUnit.Mocks.Generated /// public IReadWriter_Write_M2_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IReadWriter_Write_M2_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IReadWriter_Write_M2_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IReadWriter_Write_M2_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IReadWriter_Write_M2_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IReadWriter_Write_M2_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IReadWriter_Write_M2_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Async_Methods.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Async_Methods.verified.txt index 3fbb33bd3b..4afd405253 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Async_Methods.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Async_Methods.verified.txt @@ -219,16 +219,6 @@ namespace TUnit.Mocks.Generated /// public IAsyncService_GetValueAsync_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IAsyncService_GetValueAsync_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IAsyncService_GetValueAsync_M0_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public IAsyncService_GetValueAsync_M0_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IAsyncService_GetValueAsync_M0_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IAsyncService_GetValueAsync_M0_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IAsyncService_GetValueAsync_M0_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IAsyncService_GetValueAsync_M0_MockCall Then() { EnsureSetup().Then(); return this; } @@ -311,14 +301,6 @@ namespace TUnit.Mocks.Generated /// public IAsyncService_DoWorkAsync_M1_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IAsyncService_DoWorkAsync_M1_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IAsyncService_DoWorkAsync_M1_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IAsyncService_DoWorkAsync_M1_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IAsyncService_DoWorkAsync_M1_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IAsyncService_DoWorkAsync_M1_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IAsyncService_DoWorkAsync_M1_MockCall Then() { EnsureSetup().Then(); return this; } @@ -383,16 +365,6 @@ namespace TUnit.Mocks.Generated /// public IAsyncService_ComputeAsync_M2_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IAsyncService_ComputeAsync_M2_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IAsyncService_ComputeAsync_M2_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public IAsyncService_ComputeAsync_M2_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IAsyncService_ComputeAsync_M2_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IAsyncService_ComputeAsync_M2_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IAsyncService_ComputeAsync_M2_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IAsyncService_ComputeAsync_M2_MockCall Then() { EnsureSetup().Then(); return this; } @@ -477,14 +449,6 @@ namespace TUnit.Mocks.Generated /// public IAsyncService_InitializeAsync_M3_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IAsyncService_InitializeAsync_M3_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IAsyncService_InitializeAsync_M3_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IAsyncService_InitializeAsync_M3_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IAsyncService_InitializeAsync_M3_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IAsyncService_InitializeAsync_M3_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IAsyncService_InitializeAsync_M3_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Events.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Events.verified.txt index bf271369ae..20bda06dce 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Events.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Events.verified.txt @@ -174,14 +174,6 @@ namespace TUnit.Mocks.Generated /// public INotifier_Notify_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public INotifier_Notify_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public INotifier_Notify_M0_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public INotifier_Notify_M0_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public INotifier_Notify_M0_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public INotifier_Notify_M0_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public INotifier_Notify_M0_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Keyword_Parameter_Names.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Keyword_Parameter_Names.verified.txt index 252bf30236..02476f37d4 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Keyword_Parameter_Names.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Keyword_Parameter_Names.verified.txt @@ -150,14 +150,6 @@ namespace TUnit.Mocks.Generated /// public ITest_Test_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public ITest_Test_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public ITest_Test_M0_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public ITest_Test_M0_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public ITest_Test_M0_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public ITest_Test_M0_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public ITest_Test_M0_MockCall Then() { EnsureSetup().Then(); return this; } @@ -231,16 +223,6 @@ namespace TUnit.Mocks.Generated /// public ITest_Get_M1_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public ITest_Get_M1_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public ITest_Get_M1_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public ITest_Get_M1_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public ITest_Get_M1_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public ITest_Get_M1_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public ITest_Get_M1_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public ITest_Get_M1_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Mixed_Members.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Mixed_Members.verified.txt index cdfbee5c1f..be73cae2d2 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Mixed_Members.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Mixed_Members.verified.txt @@ -228,16 +228,6 @@ namespace TUnit.Mocks.Generated /// public IService_GetAsync_M3_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IService_GetAsync_M3_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IService_GetAsync_M3_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public IService_GetAsync_M3_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IService_GetAsync_M3_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IService_GetAsync_M3_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IService_GetAsync_M3_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IService_GetAsync_M3_MockCall Then() { EnsureSetup().Then(); return this; } @@ -323,14 +313,6 @@ namespace TUnit.Mocks.Generated /// public IService_Process_M4_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IService_Process_M4_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IService_Process_M4_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IService_Process_M4_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IService_Process_M4_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IService_Process_M4_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IService_Process_M4_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Nullable_Reference_Type_Parameters.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Nullable_Reference_Type_Parameters.verified.txt index e038c061a1..4ed333d5cb 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Nullable_Reference_Type_Parameters.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Nullable_Reference_Type_Parameters.verified.txt @@ -258,14 +258,6 @@ namespace TUnit.Mocks.Generated /// public IFoo_Bar_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IFoo_Bar_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IFoo_Bar_M0_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IFoo_Bar_M0_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IFoo_Bar_M0_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IFoo_Bar_M0_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IFoo_Bar_M0_MockCall Then() { EnsureSetup().Then(); return this; } @@ -339,16 +331,6 @@ namespace TUnit.Mocks.Generated /// public IFoo_GetValue_M1_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IFoo_GetValue_M1_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IFoo_GetValue_M1_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public IFoo_GetValue_M1_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IFoo_GetValue_M1_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IFoo_GetValue_M1_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IFoo_GetValue_M1_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IFoo_GetValue_M1_MockCall Then() { EnsureSetup().Then(); return this; } @@ -426,14 +408,6 @@ namespace TUnit.Mocks.Generated /// public IFoo_Process_M2_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IFoo_Process_M2_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IFoo_Process_M2_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IFoo_Process_M2_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IFoo_Process_M2_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IFoo_Process_M2_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IFoo_Process_M2_MockCall Then() { EnsureSetup().Then(); return this; } @@ -507,16 +481,6 @@ namespace TUnit.Mocks.Generated /// public IFoo_GetAsync_M3_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IFoo_GetAsync_M3_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IFoo_GetAsync_M3_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public IFoo_GetAsync_M3_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IFoo_GetAsync_M3_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IFoo_GetAsync_M3_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IFoo_GetAsync_M3_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IFoo_GetAsync_M3_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Out_Ref_Parameters.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Out_Ref_Parameters.verified.txt index b3767dabd4..9df925e012 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Out_Ref_Parameters.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Out_Ref_Parameters.verified.txt @@ -144,17 +144,6 @@ namespace TUnit.Mocks.Generated /// public IDictionary_TryGetValue_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IDictionary_TryGetValue_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IDictionary_TryGetValue_M0_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public IDictionary_TryGetValue_M0_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IDictionary_TryGetValue_M0_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public IDictionary_TryGetValue_M0_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IDictionary_TryGetValue_M0_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IDictionary_TryGetValue_M0_MockCall Then() { EnsureSetup().Then(); return this; } @@ -235,15 +224,6 @@ namespace TUnit.Mocks.Generated /// public IDictionary_Swap_M1_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IDictionary_Swap_M1_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IDictionary_Swap_M1_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IDictionary_Swap_M1_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public IDictionary_Swap_M1_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IDictionary_Swap_M1_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IDictionary_Swap_M1_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Overloaded_Methods.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Overloaded_Methods.verified.txt index 7716bf0dc4..882877794f 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Overloaded_Methods.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Overloaded_Methods.verified.txt @@ -236,16 +236,6 @@ namespace TUnit.Mocks.Generated /// public IFormatter_Format_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IFormatter_Format_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IFormatter_Format_M0_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public IFormatter_Format_M0_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IFormatter_Format_M0_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IFormatter_Format_M0_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IFormatter_Format_M0_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IFormatter_Format_M0_MockCall Then() { EnsureSetup().Then(); return this; } @@ -326,16 +316,6 @@ namespace TUnit.Mocks.Generated /// public IFormatter_Format_M1_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IFormatter_Format_M1_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IFormatter_Format_M1_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public IFormatter_Format_M1_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IFormatter_Format_M1_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IFormatter_Format_M1_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IFormatter_Format_M1_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IFormatter_Format_M1_MockCall Then() { EnsureSetup().Then(); return this; } @@ -416,16 +396,6 @@ namespace TUnit.Mocks.Generated /// public IFormatter_Format_M2_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IFormatter_Format_M2_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IFormatter_Format_M2_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public IFormatter_Format_M2_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IFormatter_Format_M2_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IFormatter_Format_M2_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IFormatter_Format_M2_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IFormatter_Format_M2_MockCall Then() { EnsureSetup().Then(); return this; } @@ -506,16 +476,6 @@ namespace TUnit.Mocks.Generated /// public IFormatter_Format_M3_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IFormatter_Format_M3_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IFormatter_Format_M3_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public IFormatter_Format_M3_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IFormatter_Format_M3_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IFormatter_Format_M3_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IFormatter_Format_M3_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IFormatter_Format_M3_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Static_Abstract_Transitive_Return_Type.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Static_Abstract_Transitive_Return_Type.verified.txt index b66a48bf84..82ccade369 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Static_Abstract_Transitive_Return_Type.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Interface_With_Static_Abstract_Transitive_Return_Type.verified.txt @@ -137,16 +137,6 @@ namespace TUnit.Mocks.Generated /// public IMyService_GetValue_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IMyService_GetValue_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IMyService_GetValue_M0_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public IMyService_GetValue_M0_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IMyService_GetValue_M0_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IMyService_GetValue_M0_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IMyService_GetValue_M0_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IMyService_GetValue_M0_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Multi_Method_Interface.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Multi_Method_Interface.verified.txt index 58122d02a5..2d1a2606f9 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Multi_Method_Interface.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Multi_Method_Interface.verified.txt @@ -179,16 +179,6 @@ namespace TUnit.Mocks.Generated /// public ICalculator_Add_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public ICalculator_Add_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public ICalculator_Add_M0_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public ICalculator_Add_M0_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public ICalculator_Add_M0_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public ICalculator_Add_M0_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public ICalculator_Add_M0_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public ICalculator_Add_M0_MockCall Then() { EnsureSetup().Then(); return this; } @@ -269,16 +259,6 @@ namespace TUnit.Mocks.Generated /// public ICalculator_Subtract_M1_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public ICalculator_Subtract_M1_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public ICalculator_Subtract_M1_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public ICalculator_Subtract_M1_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public ICalculator_Subtract_M1_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public ICalculator_Subtract_M1_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public ICalculator_Subtract_M1_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public ICalculator_Subtract_M1_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Internal_Virtual_Members_From_External_Assembly.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Internal_Virtual_Members_From_External_Assembly.verified.txt index bf0e926885..2ea578e32d 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Internal_Virtual_Members_From_External_Assembly.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Internal_Virtual_Members_From_External_Assembly.verified.txt @@ -163,16 +163,6 @@ namespace TUnit.Mocks.Generated /// public ExternalLib_ExternalClient_PublicMethod_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public ExternalLib_ExternalClient_PublicMethod_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public ExternalLib_ExternalClient_PublicMethod_M0_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public ExternalLib_ExternalClient_PublicMethod_M0_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public ExternalLib_ExternalClient_PublicMethod_M0_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public ExternalLib_ExternalClient_PublicMethod_M0_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public ExternalLib_ExternalClient_PublicMethod_M0_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public ExternalLib_ExternalClient_PublicMethod_M0_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Members_With_Internal_Signature_Types.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Members_With_Internal_Signature_Types.verified.txt index 90035b2400..e3d133dc80 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Members_With_Internal_Signature_Types.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Partial_Mock_Filters_Members_With_Internal_Signature_Types.verified.txt @@ -123,16 +123,6 @@ namespace TUnit.Mocks.Generated /// public ExternalLib_ServiceClient_GetValue_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public ExternalLib_ServiceClient_GetValue_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public ExternalLib_ServiceClient_GetValue_M0_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public ExternalLib_ServiceClient_GetValue_M0_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public ExternalLib_ServiceClient_GetValue_M0_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public ExternalLib_ServiceClient_GetValue_M0_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public ExternalLib_ServiceClient_GetValue_M0_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public ExternalLib_ServiceClient_GetValue_M0_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Simple_Interface_With_One_Method.verified.txt b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Simple_Interface_With_One_Method.verified.txt index f3654e5425..89b4928cbd 100644 --- a/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Simple_Interface_With_One_Method.verified.txt +++ b/TUnit.Mocks.SourceGenerator.Tests/Snapshots/Simple_Interface_With_One_Method.verified.txt @@ -120,16 +120,6 @@ namespace TUnit.Mocks.Generated /// public IGreeter_Greet_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } /// - public IGreeter_Greet_M0_MockCall Callback(global::System.Action callback) { EnsureSetup().Callback(callback); return this; } - /// - public IGreeter_Greet_M0_MockCall Returns(global::System.Func factory) { EnsureSetup().Returns(factory); return this; } - /// - public IGreeter_Greet_M0_MockCall Throws(global::System.Func exceptionFactory) { EnsureSetup().Throws(exceptionFactory); return this; } - /// - public IGreeter_Greet_M0_MockCall Raises(string eventName, object? args = null) { EnsureSetup().Raises(eventName, args); return this; } - /// - public IGreeter_Greet_M0_MockCall SetsOutParameter(int paramIndex, object? value) { EnsureSetup().SetsOutParameter(paramIndex, value); return this; } - /// public IGreeter_Greet_M0_MockCall TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); return this; } /// public IGreeter_Greet_M0_MockCall Then() { EnsureSetup().Then(); return this; } diff --git a/TUnit.Mocks.SourceGenerator/Builders/MockMembersBuilder.cs b/TUnit.Mocks.SourceGenerator/Builders/MockMembersBuilder.cs index 71a857d0bc..dc4943edee 100644 --- a/TUnit.Mocks.SourceGenerator/Builders/MockMembersBuilder.cs +++ b/TUnit.Mocks.SourceGenerator/Builders/MockMembersBuilder.cs @@ -195,20 +195,6 @@ private static void GenerateReturnUnifiedClass(CodeWriter writer, string wrapper writer.AppendLine($"/// "); writer.AppendLine($"public {wrapperName} Callback(global::System.Action callback) {{ EnsureSetup().Callback(callback); return this; }}"); writer.AppendLine($"/// "); - writer.AppendLine($"public {wrapperName} Callback(global::System.Action callback) {{ EnsureSetup().Callback(callback); return this; }}"); - writer.AppendLine($"/// "); - writer.AppendLine($"public {wrapperName} Returns(global::System.Func factory) {{ EnsureSetup().Returns(factory); return this; }}"); - writer.AppendLine($"/// "); - writer.AppendLine($"public {wrapperName} Throws(global::System.Func exceptionFactory) {{ EnsureSetup().Throws(exceptionFactory); return this; }}"); - writer.AppendLine($"/// "); - writer.AppendLine($"public {wrapperName} Raises(string eventName, object? args = null) {{ EnsureSetup().Raises(eventName, args); return this; }}"); - writer.AppendLine($"/// "); - if (hasOutRef) - { - writer.AppendLine("[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]"); - } - writer.AppendLine($"public {wrapperName} SetsOutParameter(int paramIndex, object? value) {{ EnsureSetup().SetsOutParameter(paramIndex, value); return this; }}"); - writer.AppendLine($"/// "); writer.AppendLine($"public {wrapperName} TransitionsTo(string stateName) {{ EnsureSetup().TransitionsTo(stateName); return this; }}"); writer.AppendLine($"/// "); writer.AppendLine($"public {wrapperName} Then() {{ EnsureSetup().Then(); return this; }}"); @@ -331,18 +317,6 @@ private static void GenerateVoidUnifiedClass(CodeWriter writer, string wrapperNa writer.AppendLine($"/// "); writer.AppendLine($"public {wrapperName} Callback(global::System.Action callback) {{ EnsureSetup().Callback(callback); return this; }}"); writer.AppendLine($"/// "); - writer.AppendLine($"public {wrapperName} Callback(global::System.Action callback) {{ EnsureSetup().Callback(callback); return this; }}"); - writer.AppendLine($"/// "); - writer.AppendLine($"public {wrapperName} Throws(global::System.Func exceptionFactory) {{ EnsureSetup().Throws(exceptionFactory); return this; }}"); - writer.AppendLine($"/// "); - writer.AppendLine($"public {wrapperName} Raises(string eventName, object? args = null) {{ EnsureSetup().Raises(eventName, args); return this; }}"); - writer.AppendLine($"/// "); - if (hasOutRef) - { - writer.AppendLine("[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]"); - } - writer.AppendLine($"public {wrapperName} SetsOutParameter(int paramIndex, object? value) {{ EnsureSetup().SetsOutParameter(paramIndex, value); return this; }}"); - writer.AppendLine($"/// "); writer.AppendLine($"public {wrapperName} TransitionsTo(string stateName) {{ EnsureSetup().TransitionsTo(stateName); return this; }}"); writer.AppendLine($"/// "); writer.AppendLine($"public {wrapperName} Then() {{ EnsureSetup().Then(); return this; }}"); diff --git a/TUnit.Mocks.Tests/ComprehensiveOutRefSpanTests.cs b/TUnit.Mocks.Tests/ComprehensiveOutRefSpanTests.cs index f1f8a37af5..3e7f085bd2 100644 --- a/TUnit.Mocks.Tests/ComprehensiveOutRefSpanTests.cs +++ b/TUnit.Mocks.Tests/ComprehensiveOutRefSpanTests.cs @@ -401,7 +401,7 @@ public async Task Multiple_Out_Callback_With_Args() string? capturedInput = null; var mock = Mock.Of(); mock.Extract(Any()) - .Callback((Action)(args => capturedInput = (string?)args[0])) + .Callback((string input) => capturedInput = input) .Returns(true) .SetsOutCount(1) .SetsOutData(new ReadOnlySpan([0xDE])); @@ -1262,13 +1262,12 @@ public async Task Out_Span_Chaining_SetsOut_Then_Returns() } [Test] - public async Task Out_Span_Untyped_SetsOutParameter_Still_Works() + public async Task Out_Span_Typed_SetsOutData_With_Array() { - // Backward compat: use index-based API with a byte array var mock = Mock.Of(); mock.TryParse("key") .Returns(true) - .SetsOutParameter(1, new byte[] { 0xDE, 0xAD }); + .SetsOutData(new ReadOnlySpan([0xDE, 0xAD])); var success = mock.Object.TryParse("key", out var data); var len = data.Length; @@ -1343,7 +1342,7 @@ public async Task Out_Span_Callback_With_Args() string? capturedInput = null; var mock = Mock.Of(); mock.TryParse(Any()) - .Callback((Action)(args => capturedInput = (string?)args[0])) + .Callback((string input) => capturedInput = input) .Returns(true) .SetsOutData(new ReadOnlySpan([1])); @@ -1357,8 +1356,8 @@ public async Task Out_Span_Throws_Exception_Factory() { var mock = Mock.Of(); mock.TryParse(Any()) - .Throws((Func)(args => - new ArgumentException($"Bad input: {args[0]}"))); + .Throws((string input) => + new ArgumentException($"Bad input: {input}")); var ex = Assert.Throws(() => mock.Object.TryParse("bad", out _)); diff --git a/TUnit.Mocks.Tests/InParameterTests.cs b/TUnit.Mocks.Tests/InParameterTests.cs index ee5dfd3090..a8815cd2cc 100644 --- a/TUnit.Mocks.Tests/InParameterTests.cs +++ b/TUnit.Mocks.Tests/InParameterTests.cs @@ -166,10 +166,10 @@ public async Task In_Params_Callback_With_Args() int capturedA = 0, capturedB = 0; var mock = Mock.Of(); mock.Add(Any(), Any()) - .Callback((object?[] args) => + .Callback((int a, int b) => { - capturedA = (int)args[0]!; - capturedB = (int)args[1]!; + capturedA = a; + capturedB = b; }) .Returns(0); @@ -199,7 +199,7 @@ public async Task In_String_Param_Matching() { var messages = new List(); var mock = Mock.Of(); - mock.Log(Any()).Callback((object?[] args) => messages.Add((string)args[0]!)); + mock.Log(Any()).Callback((string msg) => messages.Add(msg)); mock.Object.Log("first"); mock.Object.Log("second"); diff --git a/TUnit.Mocks.Tests/OutRefAssignmentTests.cs b/TUnit.Mocks.Tests/OutRefAssignmentTests.cs index f75d741b32..6f5b35c9b7 100644 --- a/TUnit.Mocks.Tests/OutRefAssignmentTests.cs +++ b/TUnit.Mocks.Tests/OutRefAssignmentTests.cs @@ -102,13 +102,13 @@ public async Task Ref_Parameter_Can_Be_Set_Via_Typed_Api() } [Test] - public async Task Untyped_SetsOutParameter_Still_Works() + public async Task Typed_SetsOutValue_Works() { - // Arrange — backward compatibility with untyped API + // Arrange var mock = Mock.Of(); mock.TryGet("key") .Returns(true) - .SetsOutParameter(1, "untyped-value"); + .SetsOutValue("untyped-value"); IDictionary dict = mock.Object; diff --git a/TUnit.Mocks.Tests/TypedCallbackTests.cs b/TUnit.Mocks.Tests/TypedCallbackTests.cs index 1b229f7fa3..4336cb384e 100644 --- a/TUnit.Mocks.Tests/TypedCallbackTests.cs +++ b/TUnit.Mocks.Tests/TypedCallbackTests.cs @@ -12,10 +12,10 @@ public class TypedCallbackTests public async Task Callback_With_Args_Receives_Arguments() { // Arrange - object?[]? capturedArgs = null; + (int a, int b)? capturedArgs = null; var mock = Mock.Of(); mock.Add(Any(), Any()) - .Callback((Action)(args => capturedArgs = args)); + .Callback((int a, int b) => capturedArgs = (a, b)); ICalculator calc = mock.Object; @@ -24,19 +24,18 @@ public async Task Callback_With_Args_Receives_Arguments() // Assert await Assert.That(capturedArgs).IsNotNull(); - await Assert.That(capturedArgs!.Length).IsEqualTo(2); - await Assert.That(capturedArgs[0]).IsEqualTo(3); - await Assert.That(capturedArgs[1]).IsEqualTo(7); + await Assert.That(capturedArgs!.Value.a).IsEqualTo(3); + await Assert.That(capturedArgs!.Value.b).IsEqualTo(7); } [Test] public async Task Callback_With_Args_On_Void_Method() { // Arrange - object?[]? capturedArgs = null; + string? capturedMsg = null; var mock = Mock.Of(); mock.Log(Any()) - .Callback((Action)(args => capturedArgs = args)); + .Callback((string msg) => capturedMsg = msg); ICalculator calc = mock.Object; @@ -44,9 +43,7 @@ public async Task Callback_With_Args_On_Void_Method() calc.Log("hello"); // Assert - await Assert.That(capturedArgs).IsNotNull(); - await Assert.That(capturedArgs!.Length).IsEqualTo(1); - await Assert.That(capturedArgs[0]).IsEqualTo("hello"); + await Assert.That(capturedMsg).IsEqualTo("hello"); } [Test] @@ -55,7 +52,7 @@ public async Task Returns_With_Args_Computes_From_Arguments() // Arrange var mock = Mock.Of(); mock.Add(Any(), Any()) - .Returns((Func)(args => (int)args[0]! + (int)args[1]!)); + .Returns((int a, int b) => a + b); ICalculator calc = mock.Object; @@ -71,7 +68,7 @@ public async Task Returns_With_Args_String_Concatenation() // Arrange var mock = Mock.Of(); mock.Greet(Any()) - .Returns((Func)(args => $"Hello, {args[0]}!")); + .Returns((string name) => $"Hello, {name}!"); IGreeter greeter = mock.Object; @@ -86,8 +83,8 @@ public async Task Computed_Throw_With_Args() // Arrange var mock = Mock.Of(); mock.Add(Any(), Any()) - .Throws((Func)(args => - new ArgumentException($"Bad args: {args[0]}, {args[1]}"))); + .Throws((int a, int b) => + new ArgumentException($"Bad args: {a}, {b}")); ICalculator calc = mock.Object; @@ -102,8 +99,8 @@ public async Task Computed_Throw_On_Void_Method() // Arrange var mock = Mock.Of(); mock.Log(Any()) - .Throws((Func)(args => - new InvalidOperationException($"Cannot log: {args[0]}"))); + .Throws((string msg) => + new InvalidOperationException($"Cannot log: {msg}")); ICalculator calc = mock.Object; @@ -116,10 +113,10 @@ public async Task Computed_Throw_On_Void_Method() public async Task Callback_With_Args_Then_Returns() { // Arrange - object?[]? capturedArgs = null; + (int a, int b)? capturedArgs = null; var mock = Mock.Of(); mock.Add(Any(), Any()) - .Callback((Action)(args => capturedArgs = args)) + .Callback((int a, int b) => capturedArgs = (a, b)) .Then() .Returns(42); @@ -128,7 +125,7 @@ public async Task Callback_With_Args_Then_Returns() // Act - first call triggers callback var result1 = calc.Add(5, 10); await Assert.That(capturedArgs).IsNotNull(); - await Assert.That(capturedArgs![0]).IsEqualTo(5); + await Assert.That(capturedArgs!.Value.a).IsEqualTo(5); // Second call returns fixed value var result2 = calc.Add(1, 1); @@ -141,7 +138,7 @@ public async Task Returns_With_Args_Repeats_On_Subsequent_Calls() // Arrange var mock = Mock.Of(); mock.Add(Any(), Any()) - .Returns((Func)(args => (int)args[0]! * (int)args[1]!)); + .Returns((int a, int b) => a * b); ICalculator calc = mock.Object; diff --git a/TUnit.Mocks/MockMethodCall.cs b/TUnit.Mocks/MockMethodCall.cs index 4aae941b8e..2cf0972255 100644 --- a/TUnit.Mocks/MockMethodCall.cs +++ b/TUnit.Mocks/MockMethodCall.cs @@ -79,39 +79,6 @@ public ISetupChain Callback(Action callback) return this; } - [EditorBrowsable(EditorBrowsableState.Never)] - public ISetupChain Callback(Action callback) - { - EnsureSetup().Callback(callback); - return this; - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public ISetupChain Returns(Func factory) - { - EnsureSetup().Returns(factory); - return this; - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public ISetupChain Throws(Func exceptionFactory) - { - EnsureSetup().Throws(exceptionFactory); - return this; - } - - public ISetupChain Raises(string eventName, object? args = null) - { - EnsureSetup().Raises(eventName, args); - return this; - } - - public ISetupChain SetsOutParameter(int paramIndex, object? value) - { - EnsureSetup().SetsOutParameter(paramIndex, value); - return this; - } - public ISetupChain TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName); diff --git a/TUnit.Mocks/Setup/IMethodSetup.cs b/TUnit.Mocks/Setup/IMethodSetup.cs index d16873181d..5225b2cdea 100644 --- a/TUnit.Mocks/Setup/IMethodSetup.cs +++ b/TUnit.Mocks/Setup/IMethodSetup.cs @@ -1,5 +1,3 @@ -using System.ComponentModel; - namespace TUnit.Mocks.Setup; /// @@ -26,24 +24,6 @@ public interface IMethodSetup /// Execute a callback when the method is called. ISetupChain Callback(Action callback); - /// Execute a callback with the method arguments when the method is called. - [EditorBrowsable(EditorBrowsableState.Never)] - ISetupChain Callback(Action callback); - - /// Configure a computed return value based on method arguments. - [EditorBrowsable(EditorBrowsableState.Never)] - ISetupChain Returns(Func factory); - - /// Configure a computed exception based on method arguments to throw. - [EditorBrowsable(EditorBrowsableState.Never)] - ISetupChain Throws(Func exceptionFactory); - - /// Auto-raise the named event when this method is called. - ISetupChain Raises(string eventName, object? args = null); - - /// Assign a value to an out or ref parameter when this setup matches. - ISetupChain SetsOutParameter(int paramIndex, object? value); - /// Transition to the named state after this setup's behavior executes. ISetupChain TransitionsTo(string stateName); } diff --git a/TUnit.Mocks/Setup/ISetupChain.cs b/TUnit.Mocks/Setup/ISetupChain.cs index 681930d2e8..837746a31a 100644 --- a/TUnit.Mocks/Setup/ISetupChain.cs +++ b/TUnit.Mocks/Setup/ISetupChain.cs @@ -8,14 +8,6 @@ public interface ISetupChain /// Chain the next call's behavior. IMethodSetup Then(); - /// Auto-raise the named event when this method is called. - ISetupChain Raises(string eventName, object? args = null); - - /// Assign a value to an out or ref parameter when this setup matches. - /// The zero-based index of the parameter in the method signature. - /// The value to assign. - ISetupChain SetsOutParameter(int paramIndex, object? value); - /// Transition to the named state after this behavior executes. ISetupChain TransitionsTo(string stateName); } @@ -28,14 +20,6 @@ public interface IVoidSetupChain /// Chain the next call's behavior. IVoidMethodSetup Then(); - /// Auto-raise the named event when this method is called. - IVoidSetupChain Raises(string eventName, object? args = null); - - /// Assign a value to an out or ref parameter when this setup matches. - /// The zero-based index of the parameter in the method signature. - /// The value to assign. - IVoidSetupChain SetsOutParameter(int paramIndex, object? value); - /// Transition to the named state after this behavior executes. IVoidSetupChain TransitionsTo(string stateName); } diff --git a/TUnit.Mocks/Setup/IVoidMethodSetup.cs b/TUnit.Mocks/Setup/IVoidMethodSetup.cs index 5554527fab..de9e41827c 100644 --- a/TUnit.Mocks/Setup/IVoidMethodSetup.cs +++ b/TUnit.Mocks/Setup/IVoidMethodSetup.cs @@ -1,5 +1,3 @@ -using System.ComponentModel; - namespace TUnit.Mocks.Setup; /// @@ -19,20 +17,6 @@ public interface IVoidMethodSetup /// Execute a callback when the method is called. IVoidSetupChain Callback(Action callback); - /// Execute a callback with the method arguments when the method is called. - [EditorBrowsable(EditorBrowsableState.Never)] - IVoidSetupChain Callback(Action callback); - - /// Configure a computed exception based on method arguments to throw. - [EditorBrowsable(EditorBrowsableState.Never)] - IVoidSetupChain Throws(Func exceptionFactory); - - /// Auto-raise the named event when this method is called. - IVoidSetupChain Raises(string eventName, object? args = null); - - /// Assign a value to an out or ref parameter when this setup matches. - IVoidSetupChain SetsOutParameter(int paramIndex, object? value); - /// Transition to the named state after this setup's behavior executes. IVoidSetupChain TransitionsTo(string stateName); } diff --git a/TUnit.Mocks/Setup/MethodSetupBuilder.cs b/TUnit.Mocks/Setup/MethodSetupBuilder.cs index 7b51ed052b..0955ac8499 100644 --- a/TUnit.Mocks/Setup/MethodSetupBuilder.cs +++ b/TUnit.Mocks/Setup/MethodSetupBuilder.cs @@ -57,30 +57,35 @@ public ISetupChain Callback(Action callback) return this; } + [EditorBrowsable(EditorBrowsableState.Never)] public ISetupChain Callback(Action callback) { _setup.AddBehavior(new CallbackWithArgsBehavior(callback)); return this; } + [EditorBrowsable(EditorBrowsableState.Never)] public ISetupChain Returns(Func factory) { _setup.AddBehavior(new ComputedReturnWithArgsBehavior(factory)); return this; } + [EditorBrowsable(EditorBrowsableState.Never)] public ISetupChain Throws(Func exceptionFactory) { _setup.AddBehavior(new ComputedThrowBehavior(exceptionFactory)); return this; } + [EditorBrowsable(EditorBrowsableState.Never)] public ISetupChain Raises(string eventName, object? args = null) { _setup.AddEventRaise(new EventRaiseInfo(eventName, args)); return this; } + [EditorBrowsable(EditorBrowsableState.Never)] public ISetupChain SetsOutParameter(int paramIndex, object? value) { _setup.SetOutRefValue(paramIndex, value); diff --git a/TUnit.Mocks/Setup/PropertySetterSetupBuilder.cs b/TUnit.Mocks/Setup/PropertySetterSetupBuilder.cs index 1406e775af..9b0b97afea 100644 --- a/TUnit.Mocks/Setup/PropertySetterSetupBuilder.cs +++ b/TUnit.Mocks/Setup/PropertySetterSetupBuilder.cs @@ -21,10 +21,6 @@ public PropertySetterSetupBuilder(MethodSetup setup) public IVoidSetupChain Throws() where TException : Exception, new() => _inner.Throws(); public IVoidSetupChain Throws(Exception exception) => _inner.Throws(exception); public IVoidSetupChain Callback(Action callback) => _inner.Callback(callback); - public IVoidSetupChain Callback(Action callback) => _inner.Callback(callback); - public IVoidSetupChain Throws(Func exceptionFactory) => _inner.Throws(exceptionFactory); - public IVoidSetupChain Raises(string eventName, object? args = null) => _inner.Raises(eventName, args); - public IVoidSetupChain SetsOutParameter(int paramIndex, object? value) => _inner.SetsOutParameter(paramIndex, value); public IVoidSetupChain TransitionsTo(string stateName) => _inner.TransitionsTo(stateName); public IVoidMethodSetup Then() => _inner.Then(); } diff --git a/TUnit.Mocks/Setup/PropertySetupBuilder.cs b/TUnit.Mocks/Setup/PropertySetupBuilder.cs index 9167b8922c..dd754b5994 100644 --- a/TUnit.Mocks/Setup/PropertySetupBuilder.cs +++ b/TUnit.Mocks/Setup/PropertySetupBuilder.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using TUnit.Mocks.Setup.Behaviors; namespace TUnit.Mocks.Setup; @@ -24,11 +23,6 @@ public PropertySetupBuilder(MethodSetup setup) public ISetupChain Throws() where TException : Exception, new() => _inner.Throws(); public ISetupChain Throws(Exception exception) => _inner.Throws(exception); public ISetupChain Callback(Action callback) => _inner.Callback(callback); - public ISetupChain Callback(Action callback) => _inner.Callback(callback); - public ISetupChain Returns(Func factory) => _inner.Returns(factory); - public ISetupChain Throws(Func exceptionFactory) => _inner.Throws(exceptionFactory); - public ISetupChain Raises(string eventName, object? args = null) => _inner.Raises(eventName, args); - public ISetupChain SetsOutParameter(int paramIndex, object? value) => _inner.SetsOutParameter(paramIndex, value); public ISetupChain TransitionsTo(string stateName) => _inner.TransitionsTo(stateName); public IMethodSetup Then() => _inner.Then(); } diff --git a/TUnit.Mocks/Setup/VoidMethodSetupBuilder.cs b/TUnit.Mocks/Setup/VoidMethodSetupBuilder.cs index aad04447cf..cf602bed48 100644 --- a/TUnit.Mocks/Setup/VoidMethodSetupBuilder.cs +++ b/TUnit.Mocks/Setup/VoidMethodSetupBuilder.cs @@ -41,24 +41,28 @@ public IVoidSetupChain Callback(Action callback) return this; } + [EditorBrowsable(EditorBrowsableState.Never)] public IVoidSetupChain Callback(Action callback) { _setup.AddBehavior(new CallbackWithArgsBehavior(callback)); return this; } + [EditorBrowsable(EditorBrowsableState.Never)] public IVoidSetupChain Throws(Func exceptionFactory) { _setup.AddBehavior(new ComputedThrowBehavior(exceptionFactory)); return this; } + [EditorBrowsable(EditorBrowsableState.Never)] public IVoidSetupChain Raises(string eventName, object? args = null) { _setup.AddEventRaise(new EventRaiseInfo(eventName, args)); return this; } + [EditorBrowsable(EditorBrowsableState.Never)] public IVoidSetupChain SetsOutParameter(int paramIndex, object? value) { _setup.SetOutRefValue(paramIndex, value); diff --git a/TUnit.Mocks/VoidMockMethodCall.cs b/TUnit.Mocks/VoidMockMethodCall.cs index b10f9a261c..9508d448d3 100644 --- a/TUnit.Mocks/VoidMockMethodCall.cs +++ b/TUnit.Mocks/VoidMockMethodCall.cs @@ -79,32 +79,6 @@ public IVoidSetupChain Callback(Action callback) return this; } - [EditorBrowsable(EditorBrowsableState.Never)] - public IVoidSetupChain Callback(Action callback) - { - EnsureSetup().Callback(callback); - return this; - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public IVoidSetupChain Throws(Func exceptionFactory) - { - EnsureSetup().Throws(exceptionFactory); - return this; - } - - public IVoidSetupChain Raises(string eventName, object? args = null) - { - EnsureSetup().Raises(eventName, args); - return this; - } - - public IVoidSetupChain SetsOutParameter(int paramIndex, object? value) - { - EnsureSetup().SetsOutParameter(paramIndex, value); - return this; - } - public IVoidSetupChain TransitionsTo(string stateName) { EnsureSetup().TransitionsTo(stateName);