[英]How to fake an object in NSubstitute and ignore its method's internal implementation?
[英]How to configure NSubstitute NOT call internal virtual method
我想要這個班的單元測試
public class Email
{
public async virtual Task<bool> Send( )
{
//code
await Save();
}
internal virtual async Task<bool> Save( )
{
}
}
和這個單元測試代碼
var email = Substitute.ForPartsOf<Email>( );
email.When(x => x.Save( )).DoNotCallBase(); --> why x.Save will call the real implementation code
email.Save( ).ReturnsForAnyArgs(true);
這是單元測試內部方法的正確方法嗎? 因為我嘗試將修改器從內部更改為公共 ,單元測試很好。
請指教。
謝謝
我認為您需要使internal
成員對DynamicProxyGenAssembly2
可見。 此程序集由NSubstitute(以及許多其他.NET模擬庫)使用的Castle DynamicProxy庫創建,以創建替換/模擬類型。
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
如果您安裝NSubstitute.Analyzers包,它應該提示您這種情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.