hrushi
hrushi

Reputation: 296

How to spy on a virtual method called from ctor

I am new to NSubstitute. I have a class (not Interface, unfortunately this is an existing class) that looks like below:

class A
{
    public A()
    {
        aa();
    }

    public virtual void aa()
    {
       // does something
    }
}

I am wondering how to verify for that aa() was called when A is instantiated?

I tried this but this doesn't seem to work for me:

var substitute = Substitute.ForPartsOf<A>();
substitute.Received().aa(); 

and also,

var substitute = Substitute.For<A>();
substitute.Received().aa(); 

Appreciate insights

Upvotes: 0

Views: 38

Answers (0)

Related Questions