Assume that you have XYZ interface and it has following declaration of method
with proper implementation:
Task DeleteHelpContent(Guid id);
and you have actual development method like following:
public async Task<IHttpActionResult> Delete([FromUri]Guid id)
{
try
{
await _XYZ.DeleteHelpContent(id);
} ....
}
now I'm preparing unit test using Moq in MS Test Framewrok as per below, it
gives red line error(compilation error):
[TestMethod]
public async Task DeleteTestForOkNegotiatedContentResult()
{
//Arrange Data
mockIHelpContentRepository.Setup(a =>
a.DeleteHelpContent(It.IsAny<Guid>()))
.ReturnsAsync(string.empty);
...
}
But when I write same code with trick as per following, it gives no error as
well, code works well for that async method:
[TestMethod]
public async Task DeleteTestForOkNegotiatedContentResult()
{
//Arrange Data
mockIHelpContentRepository.Setup(a =>
a.DeleteHelpContent(It.IsAny<Guid>()))
.Returns(Task.FromResult(string.Empty));
...
}
=================================
What version of the product are you using? On what operating system?
4.2.1402.2112
Please provide any additional information below.
Please review screenshot of comilation error and valid tricky code. As well,
request to accomodate same feature of tricky code into ReturnAsync extension
method. [ And similar for ThrowsAsync as it will not work for such similar Task
resulted method.]
Original issue reported on code.google.com by mitul.0...@gmail.com on 25 Feb 2014 at 7:17
Original issue reported on code.google.com by
mitul.0...@gmail.com
on 25 Feb 2014 at 7:17Attachments: