3 Answers, 1 is accepted
I have the following method:
I want to mock the WorkloadPlannerEntitiesModel in my test so when I call this method it will use my mock instead of the ORM.
this is what I have tried:
but when it trys to instantiate WorkloadPlannerEntitiesModel GetByID method it fails on a conectionstring error
Thanks for reporting the issue. However it looks to me that you are expecting the following line to take the instance from the mock which you have defined using Constructor.Mocked in your test method:
But Mock.Create actually just returned you the fake instance which you can setup in ways you want it to act, not like that it will replace all consecutive calls with fake constructor. The other way to get around this is to define a connection string settings and then mock the expected methods using IgnoreInstance switch or fake the following line itself:
But it’s a great point therefore we can always include:
Mock.ReplaceAll(() => new WorkLoadEntitiesModel()).With(target);
I am adding it as a feature request which you can further follow here:
In addition, in your test method instead of mocking ToList() and Single() separately you can use the ReturnsColleciton() switch that will replace the whole collection with fake one, which you can use in a loop or call Single() , First(), etc on it.
the Telerik team