moq.analyzers
moq.analyzers copied to clipboard
Add analyzers for strict behavior mode
Given
public class TestClass
{
public virtual Task TaskAsync() => Task.CompletedTask;
}
Two cases:
- Mock has no setup corresponding to the specified invocation
When
new Mock<TestClass>(MockBehavior.Strict).Object.TaskAsync();
executes it will throw an exception at runtime becauseMockBehavior.Strict
is set but there is noSetup
for the methodTaskAsync
- Mock has no setup that provides a return value for the specified invocation Similar to the first case, if the setup does not include a return, there will be a runtime exception