public async void SendGetRequestAndReturnTodoItemsWhenGetTodosAsync() { // Arrange _mockHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ) .ReturnsAsync(new HttpResponseMessage { Content = new StringContent(@"[ { 'id': 1, 'text': 'Learn programming', 'isDone': false }, { 'id': 7, 'text': 'Shopping', 'isDone': false }]") }); var client = new HttpClient(_mockHandler.Object); client.BaseAddress = new Uri("https://localhost:44376"); _mockClientFactory.Setup(x => x.CreateClient("TodoAppClient")).Returns(client); var sut = new TodoItemService(_mockClientFactory.Object); // Act var result = await sut.GetTodosAsync(); // Assert _mockHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get), ItExpr.IsAny <CancellationToken>()); Assert.NotNull(result); Assert.IsType <List <TodoItemDto> >(result); }