The question I would ask is this really a unit test? A unit test will consider scattered instances of Table<TEntity> , because we are not interested in the actual data, rather, the mechanism for creating the elements is correct.
In your snippet above, it seems that you yourself are testing the Linq methods themselves, and not any specific code that you yourself wrote.
As for your last question, one of the fundamental mistakes made with ridicule is the assumption of what to test when it is taunted. As a rule, you will scoff at something consumed by the type you want to test. For instance:.
public ICalculatorService { int Add(int a, int b); } [Test] public void CannAdd() { var mock = Mock<ICalculatorService(); mock.Setup(m => m.Add(It.IsAny<int>(), It.IsAny<int>())) .Returns(100); var service = mock.Object; Assert(service.Add(1, 2) == 100);
The above test is pointless because I verify that it returns exactly what I told him. I do not test the Moq environment here, I need to check my code, so I will need to test the user:
public class Calculator { private readonly ICalculatorService _service; public Calculator(ICalculatorService service) { _service = service; } public int Add(int a, int b) { return _service.Add(a, b); } } [Test] public void CannAdd() { var mock = Mock<ICalculatorService(); mock.Setup(m => m.Add(It.IsAny<int>(), It.IsAny<int>())) .Returns(100); var calculator = new Calculator(mock.Object); Assert(calculator.Add(1, 2) == 100);
This is more like (albeit a simplified example). Now I am testing the consumer Calculator myself, not the consumed one. In your example, even if you mocked the DataContext to return dummy instances of Table<TEntity> , what real benefits do you get?
In fact, you are likely to create a repository, for example. a IInventoryRepository and create a user for this repository (may be a domain model, controller, etc.). Then, through testing, you will mock this repository and test your consumer.