簡體   English   中英

verify with moq 方法被調用一次

[英]verify with moq method is called with argument once

被測類 (A) 調用 Object b 的方法。 我想驗證調用的方法是否使用每個定義的參數組合執行一次。

對於以下代碼,我想驗證 CalledMethod 是否恰好一次。 目前我驗證參數在參數列表中。 但是如何驗證參數是否組合在一起並且只使用一次?

public void CalledMethod(string source, string target);

List<string[]> paths = new()
{
    new string[] { "incomingPath1", "targetPath1"},
    new string[] { "incomingPath2", "targetPath2" },
    new string[] { "incomingPath3", "targetPath3" },
};
// rearrange arguments
List<string> incomingPaths = ...
List<string> targetPaths = ...

// current verification codecode
mock.Setup(foo => foo.CalledMethod(It.IsIn<String>(incomingPaths), It.IsIn<String>(targetPaths), true));

// do stuff
...

// verify method is called once with each argument pair
// How?

只需使用每個確切的參數對調用Verify

foreach (var path in paths) {
  mock.Verify(x => x.CalledMethod(path[0], path[1]), Times.Once());
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM