Like an auto-mask (e.g. IList) in MOQ without extensions / contrib

I wonder if a container can be self-similar in MOQ without any additions to the MOQ lib. I'm having trouble finding a clean way to automate IList.

Thanks in advance!

+4
source share
1 answer

Answer your question: No.

Do you really need to make fun of IList?

Cats are commonly used for:

  • To test behavior (through expectations), not results.
  • Distract difficult or heavy addictions.
  • To simplify your test code, it is easy to return the desired value.
  • To check only your class in tests.

You could, for example, make fun of a repository accessing a database. Usually your tests will not scoff at the list, but rather will scoff at the object with the data that you need for your test.

t

var aList = new List<int>() { 1, 2, 3, 4, 5 }; var mockService = new Mock<IMyService>(); mockService.Setup(mock => mock.GetFooList()).Returns(aList); 

This can help clarify your question if you indicate why you need to mock the container.

+7
source

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


All Articles