mardi 20 septembre 2016

How can I mock-setup asp.net core IConfiguration

I use moq to mock dependencies, and I used to setup service methods. but now I want to mock the IConfiguration injected to my service, and I dont sure how can I do that.

I tried instantiate it without moq. just like IConfiguration mockConfiguration = new foo() but everything I tried to insert in foo (configurationRoot\ dictionary, etc.) didn't work for me ("cannot resolve symbol configurationRoot"\ cannot implicitly convert dictionary to Iconfiguration).

I also tried with moq MockConfiguration = new Mock<IConfiguration>(); then MockConfiguration.Object["X:y:z"] = "t"; also not worked.

thanks!

1 commentaire:

  1. https://dejanstojanovic.net/aspnet/2018/november/mocking-iconfiguration-getvalue-extension-methods-in-unit-test/

    RépondreSupprimer