The EvaluateText class - API failure and method failure

In the following test case, we arrange to test for the external API failure.

When a server error is returned from the Text Analytics API, our EvaluateText implementation presently fails with an exception, since the HTTP response content is not a valid JSON. The MSTest framework allows us to expect the exception using the ExpectedException attribute, and also to specify whether a specific exception type or any of the derived types are considered valid.

In the "arrange" section of the test, we will create a valid input string, and set up the SendAsync method in the HttpMessageHandler mockup class to return HttpStatusCode.InternalServerError.

In the "act" section, we will execute the

Get Serverless computing in Azure with .NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.