I am able to do integration tests using TestServer, and I can manually mock methods in any DI injected class by replacing in ConfigureTestServices the class by a mocking one as follows :
var webHostBuilder =
new WebHostBuilder()
.UseEnvironment("Testing")
.UseContentRoot(projectDir)
.ConfigureTestServices(s =>
{
s.TryAddTransient(IMyClass, MyMockMyClass);
})
.UseStartup<Startup>();
Where MyMockMyClass is a remplacement of MyClass, with the purpose of replacing a method (eg: Method1).
Is there an option to use a moq Mock.Of<MyClass> to quickly replace on the fly my Method1, without the need to create a new class MyMockMyClass? Something like :
var mymock = Mock.Of<IMyClass>();
Mock.Get(mymock ).Setup(m => m.Method1(It.IsAny<string>()).Returns(value: whatever);
And then somehow using this mymock with the line s.TryAddTransient(IMyClass, ... in the ConfigureTestServices code above?