Navigation Properties Not Set Using ADO.NET Mocking Context Generator

I am using ADO.NET Mocking Context Generator for my Entity Framework model. I have not started using mocks yet, just trying to fix the generated objects and context classes so that the application runs as without exception. I have already fixed the T4 template to support the SaveChanges method.

Now I have another problem: when I try to access any navigation property, it is null. All primitive fields inherited from the database table are set and correct.

So what i do the following

using (var context = MyContext()) { var order = context.Orders.Where(p => p.Id == 7); var product = order.Products; } 

in this case, the product is null. But this was not the case when using the default code generator, it was used to return the real product object.

Thanks for any suggestions!

0
source share
1 answer

I tried to fix the t4 template and nothing helped. So I abandoned the ADO.NET Mocking Context Generator pattern and switched to the ADO.NET POCO Entity Generator pattern. I followed the steps described here http://slappyza.wordpress.com/2010/08/08/getting-the-entity-framework-to-generate-an-interface-for-mocking/ But instead of RhinoMock, I used the Moq library for testing .

And it finally worked!

0
source

Source: https://habr.com/ru/post/951742/


All Articles