Unit test examples

To demonstrate an example of unit test methods, we will cover a couple of possible test cases for the EvaluateText class.

As you remember from previous chapters, EvaluateText uses dependency injection of the HttpMessageHandler class. The dependency injection will allow us to mock the HttpClient class, and isolate the EvaluateText methods from the dependency on Text Analytics API.

Since the HttpClient class does not derive from an interface, we are, instead, mocking the HttpMessageHandler class. Supplying HttpMessageHandler as a parameter to the HttpClient constructor allows us to mock the SendAsync method, which is then used in the implementation of the PostAsync method of the HttpClient class.

Some of the discussion on ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.