title: C# – Mocking a method to return a different value when called a second time using Moq
body: <p>i'm using Moq to mock repository with async method. This method must be called 2 times. In first call of this method i need to get null value. In second i need get some parametr. If this method wasn't async then i can use</p>
  
  <pre><code> autoMockContext
              .Mock&lt;IPopulationReadRepository&gt;()
              .SetupSequence(method =&gt; method.GetCityForNewClients(It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;()))
              .Returns(null)
              .Returns(new Population { Id = 100, CityLongName = "Kharkiv, Kharkivska, Slobozhanshina" });
  </code></pre>
  
  <p>So error in last line. The result must be like this:</p>
  
  <pre><code> autoMockContext
              .Mock&lt;IPopulationReadRepository&gt;()
              .Setup(method =&gt; method.GetCityForNewClients(It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;()))
              .Returns(null);
  
   autoMockContext
              .Mock&lt;IPopulationReadRepository&gt;()
              .Setup(method =&gt; method.GetCityForNewClients(It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;()))
              .ReturnsAsync(new Entities.Zonning.Population { Id = 100, CityLongName = "Kharkiv, Kharkivska, Slobozhanshina" });
  </code></pre>
  
  <p>But i need it in one invokation?</p>