Usage of Moq When(Func<bool>) method
问题 I can't find an example of the usage of the When method in Moq When(Func<bool> condition); What is the purpose/usage of the method? Please give a code sample demonstrating a scenario where it would be useful. 回答1: "When" gives you the option to have different setups for the same mocked object, depending on whatever you have to decide. Let's say you want to test a format provider you have written. If the program (= test) runs in the morning a certain function call should return null; in the