Hi all,
I have a basic Entity Framework code first generated DbContext and a repository with methods which I am trying to test with moq. The method body looks like this: "return _products.AsNoTracking().OrderBy(x
=> x.Name).ToList();
". My tests fail every time, when AsNoTracking() extension is included, since it returns null. Yet, if AsNoTracking() extension is removed tests pass straight away. So far I could not find any way to resolve this issue. Is it even possible? The only thing
I managed to find online, was creating a custom extension method for AsNoTracking(), which would keep it enabled by default, and disable it when user passes a parameter in during testing. But this is not a real solution, since it still does not allow you to
test whole method, and essentially removes AsNoTracking(), during test (cheating).
Therefore, let me refocus my question.
Can a method with AsNoTracking() extension in it be tested? If yes, then how? If no, than what would be the best practice to deal with this issue.
Thank you