The below code is part of a solution that is being migrated from asp.net to .netcore and some of the tests are still in asp.net. From what I know is that in .netcore there is no use of DependenceyResolver because we use Microsofts inbuilt Dependency Injection mechanism for injecting Dependencies.
Hence based upon this I have two questions:
- What I wanted to know is below the correct way to dependency inject in a Moq test ASSUMING that the persons code is in asp.net.
- If the below code is not what I said in the 1st point then what is trying to be achieved below?
Thanks Any extra information will also be widely appreciated.
[TestInitialize]
public void Initialise()
{
DependencyResolverSetup();
}
private void DependencyResolverSetup()
{
pizzaAvailibiltyMock = new Mock<IPizzaAvailibiltyMock>();
pizzaClientOrchestrationMock = new Mock<IPizzaClientOrchestrationMock>();
Mock<IDependencyResolver> dr = new Mock<IDependencyResolver>();
dr.Setup(x => x.GetService(typeof(IPizzaAvailibiltyMock))).Returns(pizzaAvailibiltyMock.Object);
dr.Setup(x => x.GetService(typeof(IPizzaClientOrchestrationMock))).Returns(pizzaClientOrchestrationMock.Object);
DependencyResolver.SetResolver(dr.Object);
}
I tried to remove the above code from the test and I can see no apparent errors