Skip to content

Instantly share code, notes, and snippets.

@danesparza
Last active June 22, 2018 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danesparza/19a181f81541770e6f7c401577593bf5 to your computer and use it in GitHub Desktop.
Save danesparza/19a181f81541770e6f7c401577593bf5 to your computer and use it in GitHub Desktop.
Handling AggregateExceptions from Task execution
[TestMethod]
public void GetCSRInfo_BadOperation_ThrowsExceptionAndIsHandled()
{
// Arrange
var uscAPI = RestService.For<IUscApi>(_uscapiurl);
string csrCode = "404";
// Act
try
{
CsrInfo item = uscAPI.GetCSRInfo(csrCode).Result.FirstOrDefault();
}
catch (AggregateException ae)
{
ae.Handle((x) =>
{
Debug.WriteLine("There was a problem getting the CSR information: " + x.Message);
// Assert
Assert.IsTrue(x is ApiException);
return true;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment