سؤال

I have stubbed a method on an interface and want to see with what parameter it was called, but this method is called several times and I'd like to be able to inspect the parameter of each call. is there like a stack of the history of calls made to the stub that I can inspect?

my scenario is something like this:

myStub.AssertWasCalled(stub => stub.SomeMethod(Arg<ISomeInterface>.Matches<ISomeInterface>(p => p.Mode == Mode.SomeEnum)))
هل كانت مفيدة؟

المحلول

You can use GetArgumentsForCallsMadeOn.

GetArgumentsForCallsMadeOn returns a two dimensional array of objects so you will need to cast to get to the types you are expecting.

It works like this:

  public interface IDependency {
      int DoSomething(SomeComplexType someComplexType,
                            int someInteger);
    }

    IList<object[]> argumentsSentToDoSomething = 
dependency.GetArgumentsForCallsMadeOn(x => x.DoSomething(null, 0));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top