moq.analyzers icon indicating copy to clipboard operation
moq.analyzers copied to clipboard

Add analyzers for strict behavior mode

Open rjmurillo opened this issue 8 months ago • 0 comments

Given

public class TestClass
{
  public virtual Task TaskAsync() => Task.CompletedTask;
}

Two cases:

  1. 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 because MockBehavior.Strict is set but there is no Setup for the method TaskAsync
  2. 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

rjmurillo avatar Jun 25 '24 21:06 rjmurillo