You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Been bashing my head against a desk on this one, cannot seem to figure it out. Essentially I have a method that takes in a Func<T>. I want to be able to define what that func returns and then check if that func has been called in the code. For example:
publicclassDoIt{publicboolExecute(Func<int,int,bool>func){return func(1,2);}}
...[TestMethod]publicvoid TestIt
{
var it =new DoIt();Func<int,int,bool>funcSpy= Substitute.For<Func<int,int,bool>>();
funcSpy.Returns((d,dd)=>true);//When I do this I get a CouldNotSetReturnDueToLastCallException//or
funcSpy.Invoke(Arg.Any<int>(), Arg.Any<int>()).Returns(true);//When I do this I get RedundantArgumentMatcherExceptionvaractual= it.Execute(funcSpy);
actual.Should().BeTrue();
funcSpy.Received(1).Invoke(Arg.Any<int>(), Arg.Any<int>());}
Thanks
Related links
Found some links that helped with the assertion part and another hinted how do do the func but can't get it to work for my scenario
Thank you, so the 2nd way is probably what I need to go for, maybe I need an update.
But yeah you make a good point, I can do all that funky mocking manually and at least I have control and know what it is doing.
Damn I fell back into the "mock all the things" trap.
Question
Hi all,
Been bashing my head against a desk on this one, cannot seem to figure it out. Essentially I have a method that takes in a
Func<T>
. I want to be able to define what that func returns and then check if that func has been called in the code. For example:Thanks
Related links
Found some links that helped with the assertion part and another hinted how do do the func but can't get it to work for my scenario
The text was updated successfully, but these errors were encountered: