// 假设有一个名为mockObject的模拟对象,其中包含一个3参数方法mockObject.Setup(x=>x.MethodWithThreeParameters(It.IsAny<ParameterType1>(),It.IsAny<ParameterType2>(),It.IsAny<ParameterType3>())).Callback((ParameterType1param1,ParameterType2param2,ParameterType3param3)=>{// 在回调中执行自定义逻辑...
System.ArgumentException: Invalid callback. Setup on method with parameters (String&,String) cannot invoke callback with parameters (String,String) 这异常就是说Callback委托执行的方法的参数与Setup方法的参数对应不起来,有人也许马上就想说这样改改不就行了: 复制 mock.Setup((m) => m.TestMethodWithRe...
System.ArgumentException: Invalid callback. Setup on method with parameters (String&,String) cannot invoke callback with parameters (String,String) 这异常就是说Callback委托执行的方法的参数与Setup方法的参数对应不起来,有人也许马上就想说这样改改不就行了: mock.Setup((m) => m.TestMethodWithRef(ref...
System.ArgumentException: Invalid callback. Setup on method with parameters (String&,String) cannot invoke callback with parameters (String,String) 这异常就是说Callback委托执行的方法的参数与Setup方法的参数对应不起来,有人也许马上就想说这样改改不就行了: mock.Setup((m) =>m.TestMethodWithRef(ref ...
System.ArgumentException: Invalid callback. Setup on method with parameters (String&,String) cannot invoke callback with parameters (String,String) 这异常就是说Callback委托执行的方法的参数与Setup方法的参数对应不起来,有人也许马上就想说这样改改不就行了: ...
1.Setup方法:用于设置模拟对象的成员行为。 // 设置方法的返回值 mockObject.Setup(m => m.MethodName()).Returns("mocked result"); // 设置方法的行为 mockObject.Setup(m => m.MethodName()).Callback(() => /* 操作 */); // 设置属性的返回值 ...
mock.Setup(foo => foo.Submit(ref instance)).Returns(true); // access invocation arguments when returning a value mock.Setup(x => x.DoSomething(It.IsAny<string>())) .Returns((string s) => s.ToLower()); // Multiple parameters overloads available ...
Moq1002: Parameters provided into mock do not match any existing constructors Moq1100: Callback signature must match the signature of the mocked method Moq1101: SetupGet/SetupSet should be used for properties, not for methods Moq1200: Setup should be used only for overridable members ...
这应该行得通吧?如果您在一个方法上创建了一个后续的设置,并且它是非条件的(对参数没有约束),那么...
All done. As a small bonus, "any" matching for ref parameters is now also directly supported with .Protected() setups: mock.Protected().Setup("ProtectedMethod",…, ItExpr.Ref<int>.IsAny,…); Well I suppose you could do ItIs.Any<int>.Ref :) Just to answer this, I opted to stay...