public async Task SearchAsyncSucceed() { var loggerMock = new Mock <ILogger <BingSearchProvider> >(); var htmlParser = new Mock <IHtmlParser>(); var expectedResult = 123; htmlParser.Setup(x => x.ExtractNumber(It.IsAny <string>())).Returns(expectedResult).Verifiable(); var httpClientFactoryMock = new Mock <IHttpClientFactory>(); var httpHandlerMock = httpClientFactoryMock.SetupHttpClientResponse(KnownHttpClients.Bing); var request = new SearchFightSearchRequestModel("test"); var searchProvider = new BingSearchProvider(loggerMock.Object, httpClientFactoryMock.Object, htmlParser.Object); var result = await searchProvider.SearchAsync(request); htmlParser.VerifyAll(); httpHandlerMock.VerifyAll(); result.SearchEngine.Should().Be(SearchEngine); result.Should().NotBeNull(); result.Request.Should().Be(request); result.ResultCount.Should().Be(expectedResult); result.IsSucceed.Should().BeTrue(); result.Error.Should().BeNull(); }
public async Task SearchAsyncFailed() { var loggerMock = new Mock <ILogger <BingSearchProvider> >(); var htmlParser = new Mock <IHtmlParser>(); htmlParser.Setup(x => x.ExtractNumber(It.IsAny <string>())).Throws <DataSearcherException>(); var httpClientFactoryMock = new Mock <IHttpClientFactory>(); var httpHandlerMock = httpClientFactoryMock.SetupHttpClientResponse(KnownHttpClients.Bing); var request = new SearchFightSearchRequestModel("test"); var searchProvider = new BingSearchProvider(loggerMock.Object, httpClientFactoryMock.Object, htmlParser.Object); var result = await searchProvider.SearchAsync(request); httpClientFactoryMock.VerifyAll(); htmlParser.VerifyAll(); httpHandlerMock.VerifyAll(); result.Should().NotBeNull(); result.SearchEngine.Should().Be(SearchEngine); result.ResultCount.Should().Be(default);