Moq class with constructors ILogger and options netcore 2.1 vs2017 getting error
Moq class with constructors ILogger and options netcore 2.1 vs2017 getting error I need to mock a class that has parameters in the constructor by I cannot figure out how you do it using moq. It crashes Constructor arguments cannot be passed for interface mocks. See my attempt below: [Fact] public async Task MyTest() { var mySettings= GetMySettings(); var mySettingsOptions = Options.Create(mySettings); var mockLogger = Mock.Of<ILogger<MyClass>>(); var mock=new Mock<IMyClass>(mySettings,mockLogger); mock.Setup(x=>x.DoSomething(It.IsAny<string>().Returns("todo"); } public class MyClass : IMyClass { private readonly ILogger<MyClass> logger; private readonly MySettings mySettings; public MyClass(IOptions<MySettings> settings,ILogger<MyClass>logger) { this.logger = logger; this.mySettings = settings.Value; } ...