public async void Search_SaveResultsToDBAndReturnCorrectModel_WithNotEmptySearchString() { // Arrange var mockConfiguration = new Mock <IConfiguration>(); var yandexSearchString = "yandexSearchString"; var apiKey = "tempApiKey"; mockConfiguration.Setup(c => c["YandexSearchString"]).Returns(yandexSearchString); mockConfiguration.Setup(c => c["SerpApiKey"]).Returns(apiKey); var context = SearchResultContextMocker.GetSearchResultContext( nameof(Search_SaveResultsToDBAndReturnCorrectModel_WithNotEmptySearchString)); var controller = new SearchController(mockConfiguration.Object, context); const string searchString = " test "; // Act var result = await controller.Search(searchString) as ViewResult; var databaseData = await context.SearchResults.ToListAsync(); context.Dispose(); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <SearchViewModel>(viewResult.ViewData.Model); Assert.Equal("test", model.SearchString); Assert.Equal(10, model.SearchResults.Count); Assert.Equal(12, databaseData.Count); }
SearchResults_ReturnViewResultWithSearchViewModelWithSearchResultsListWithSingleElement_WithSpecificSearchString() { // Arrange var mockConfiguration = new Mock <IConfiguration>(); var context = SearchResultContextMocker.GetSearchResultContext( nameof( SearchResults_ReturnViewResultWithSearchViewModelWithSearchResultsListWithSingleElement_WithSpecificSearchString )); var controller = new SearchController(mockConfiguration.Object, context); const string searchString = "SearchString2"; // Act var result = controller.SearchResults(searchString) as ViewResult; context.Dispose(); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <SearchViewModel>(viewResult.ViewData.Model); Assert.Single(model.SearchResults); }