Beginner's question about the mocking and mocha structure

I used the Moq framework in C # for bullying in unit tests, but there is one thing that I haven't figured out yet. I have this line of code

var feedParserMock = new Mock<ApplicationServices.IFeedParser>();
feedParserMock.Setup(y => y.ParseFeed(csv)).Returns(items).Verifiable();

In the second line, does this mean that it will return a value only if the passed parameter is the same? because the parameter that I pass ParseFeed inside my controller is built into the controller and I do not have access to it in the unit test. Currently the method returns null, is there any way to indicate that I want to return the variable my items no matter what the parameter is?

+3
source share
2 answers

. Moq It, , . :

feedParserMock.Setup(y => y.ParseFeed(It.IsAny<string>())).Returns(items).Verifiable();

Moq , , null ( , , , , ),

, Moq , , . :

feedParserMock.Setup(y => y.ParseFeed(It.Is<string>(s => s.Length > 3));

ParseFeed, 3.

" " Moq Quickstart, .

+7

, It.IsAny()

feedParserMock.Setup(y => y.ParseFeed(It.IsAny<string>())).Returns(items).Verifiable();
+2

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


All Articles