public void When_receive_ok_response_with_empty_content_from_post_then_return_null(string query) { this._httpMessageHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .Returns(Task.FromResult(new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.OK, Content = new StringContent(string.Empty) })); this._httpClient = new HttpClient(this._httpMessageHandler.Object); IIndexSearch indexSearchOKNoContent = new IndexSearch(null, this._numberOfResults, this._httpClient, "https://localhost:5000", _organizationId); indexSearchOKNoContent.Search(query).Should().BeEquivalentTo((SearchResult)null); }
public void When_receive_not_found_response_from_post_then_throws_exception(string query) { this._httpMessageHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .Returns(Task.FromResult(new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.NotFound, Content = this.GetStringContent() })); this._httpClient = new HttpClient(this._httpMessageHandler.Object); IIndexSearch indexSearchNotFound = new IndexSearch(null, this._numberOfResults, this._httpClient, "https://localhost:5000", _organizationId); Assert.Throws <HttpRequestException>(() => indexSearchNotFound.Search(query)); }