0

I have a subclass that overrides a method:

public class Parent {
  public virtual string Foo(string s) {
    //...
  }
}

public class Child : Parent {
  public override string Foo(string s) {
    s = s + "123";
    return base.Foo(s);           // <---- how do I detect this call?
  }
}

I can test that the overridden method was called:

var mock = Substitute.ForPartsOf<Child>();
mock.Foo("abc");

mock.Received(1).Foo(Arg.Any<string>());

But how can I detect that the BASE method was called?

lonix
  • 14,255
  • 23
  • 85
  • 176
  • 1
    I don't think it is possible to detect the base call itself. You may need to assert on the result of the call instead. There is some [discussion of this here](https://stackoverflow.com/q/36726728/906). – David Tchepak Dec 13 '21 at 01:44
  • @DavidTchepak Follow up if I may? I had an idea that for the above example it should call the method twice. So `mock.ReceivedCalls()` should contain two corresponding calls - but it contains one only. Is that also a limitation of the framework, or is it enforced by the library? – lonix Jan 04 '22 at 08:43
  • For the example above I'd expect only one item in `ReceivedCalls()` (the `mock.Foo("abc")` call. – David Tchepak Jan 12 '22 at 04:30

1 Answers1

0

As per @DavidTchepak's comment, this is a limitation of the underlying framework. Cannot be done, but one can redesign to avoid this issue.

lonix
  • 14,255
  • 23
  • 85
  • 176