Category : Design
Level : Warning
Add an analyzer to check if the optional arguments in the Setup() method has been specified explicitly.
public class UnitTest1
{
[Fact]
public void Test1()
{
var mock = new Mock<ISampleInterface>();
mock.Setup(m => m.TestMethodWithOptionalParam(It.IsAny<int>())); // We should raise a warning for "optionalParam"
}
public interface ISampleInterface
{
void TestMethodWithOptionalParam(int requiredParam, int optionalParam = 42);
}
}
With .NET 10.0 (C# 14.0), the optional and named arguments are supported in expression trees. Before it is raise an error from the compiler, but not is accepted by C#
Problem reported by a developer in the following devlooped/moq#1654 disussion.
Category : Design
Level : Warning
Add an analyzer to check if the optional arguments in the
Setup()method has been specified explicitly.With .NET 10.0 (C# 14.0), the optional and named arguments are supported in expression trees. Before it is raise an error from the compiler, but not is accepted by C#
Problem reported by a developer in the following devlooped/moq#1654 disussion.