最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to spy on a virtual method called from ctor - Stack Overflow

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论