久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

驗證使用 Moq 調用受保護方法的次數

Verify the number of times a protected method is called using Moq(驗證使用 Moq 調用受保護方法的次數)
本文介紹了驗證使用 Moq 調用受保護方法的次數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在我的單元測試中,我正在使用 Moq 模擬一個受保護的方法,并且想斷言它被調用了一定次數.這個問題描述了與早期版本的 Moq 類似的內容:

In my unit-tests I'm mocking a protected method using Moq, and would like to assert that it is called a certain number of times. This question describes something similar for an earlier version of Moq:

//expect that ChildMethod1() will be called once. (it's protected)
testBaseMock.Protected().Expect("ChildMethod1")
  .AtMostOnce()
  .Verifiable();

...
testBase.Verify();

但這不再有效;從那時起語法發生了變化,我找不到使用 Moq 4.x 的新等效項:

but this no longer works; the syntax has changed since then and I cannot find the new equivalent using Moq 4.x:

testBaseMock.Protected().Setup("ChildMethod1")
  // no AtMostOnce() or related method anymore
  .Verifiable();

...
testBase.Verify();

推薦答案

在 Moq.Protected 命名空間,有一個 IProtectedMock 接口,具有以 Times 作為參數的 Verify 方法.

In the Moq.Protected namespace, there is an IProtectedMock interface that has a Verify method taking Times as a parameter.

編輯這至少從最小起訂量 4.0.10827 開始可用.語法示例:

Edit This is available since at least Moq 4.0.10827. Syntax example:

testBaseMock.Protected().Setup("ChildMethod1");

...
testBaseMock.Protected().Verify("ChildMethod1", Times.Once());

這篇關于驗證使用 Moq 調用受保護方法的次數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登錄使用角色)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
主站蜘蛛池模板: 日韩欧美三区 | 亚洲精品www久久久 www.蜜桃av | 精品av | av毛片| 欧美成人h版在线观看 | 午夜合集 | 欧美精品一区在线发布 | 99免费精品视频 | 紧缚调教一区二区三区视频 | 国产一区二区视频免费在线观看 | 日韩精品专区在线影院重磅 | 不卡一二三区 | 欧美日韩免费一区二区三区 | 国产精品久久国产愉拍 | 欧美日韩精品一区 | www国产成人免费观看视频,深夜成人网 | 天天色天天射天天干 | 黄色在线免费观看视频网站 | 欧美激情一区 | 又爽又黄axxx片免费观看 | 中国一级特黄视频 | 中文字幕在线视频精品 | 精品少妇一区二区三区日产乱码 | 亚洲va国产日韩欧美精品色婷婷 | 伊人网国产| 中国三级黄色录像 | 精品亚洲视频在线 | 毛片毛片毛片毛片毛片 | 91精品国产91久久久久游泳池 | 羞羞视频网站免费观看 | 欧美日韩国产综合在线 | 亚洲一区二区三区免费在线观看 | 老外几下就让我高潮了 | 久久99精品国产 | www国产精品 | 伊人婷婷 | 日韩欧美精品一区 | 精品国产高清一区二区三区 | 波多野结衣电影一区 | 日韩电影一区二区三区 | 中国大陆高清aⅴ毛片 |