I use Moq to fake the repository using the async method. This method should be called 2 times. The first time I call this method, I need to get a null value. Secondly, I need to get some parameter. If this method was not asynchronous, then I can use
autoMockContext
.Mock<IPopulationReadRepository>()
.SetupSequence(method => method.GetCityForNewClients(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns(null)
.Returns(new Population { Id = 100, CityLongName = "Kharkiv, Kharkivska, Slobozhanshina" });
So the error is in the last line. The result should be like this:
autoMockContext
.Mock<IPopulationReadRepository>()
.Setup(method => method.GetCityForNewClients(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns(null);
autoMockContext
.Mock<IPopulationReadRepository>()
.Setup(method => method.GetCityForNewClients(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(new Entities.Zonning.Population { Id = 100, CityLongName = "Kharkiv, Kharkivska, Slobozhanshina" });
But do I need this in one call?
source
share