public async Task <IActionResult> Index(string name, string countryCode) { var result = await _context.Countries .Where(e => string.IsNullOrEmpty(name) || e.Name.Contains(name)) .ToListAsync(); var model = new SearchCountry { Countries = result }; return(View(model)); }
public void Return_A_Valid_Collection_Of_Countries_That_Contains_The_Keyword() { var keyword = "ia"; var mockLoad = new Mock <ISearchCountry>(); responseRegion.Result = responseAll.Result.Where(country => country.Name.ToLower().Contains(keyword)).ToList(); var countries = new ObservableCollection <Country>(responseAll.Result); var countriesResult = new ObservableCollection <Country>(responseRegion.Result); mockLoad.Setup(sp => sp.SearchCountries(keyword, responseRegion.Result, countries)) .Returns(countriesResult); SearchCountry search = new SearchCountry(mockLoad.Object); var actualResult = search.SearchCountries(keyword, responseRegion.Result, countries); Assert.IsNotNull(actualResult); }
public void Return_The_Same_List_When_The_Keyword_Is_Empty() { var keyword = string.Empty; var mockSearch = new Mock <ISearchCountry>(); responseRegion.Result = responseAll.Result.Where(country => country.Name.ToLower().Contains(keyword)).ToList(); var countries = new ObservableCollection <Country>(responseAll.Result); var countriesResult = new ObservableCollection <Country>(responseRegion.Result); mockSearch.Setup(sp => sp.SearchCountries(keyword, responseRegion.Result, countries)) .Returns(countriesResult); SearchCountry search = new SearchCountry(mockSearch.Object); var actualResult = search.SearchCountries(keyword, responseRegion.Result, countries); var expectedResult = 8; Assert.AreEqual(expectedResult, actualResult.Count); }
public void Returns_The_Total_Number_Of_Countries_That_Contains_The_Keyword() { var keyword = "ia"; var mockSearch = new Mock <ISearchCountry>(); responseRegion.Result = responseAll.Result.Where(country => country.Name.ToLower().Contains(keyword)).ToList(); var countries = new ObservableCollection <Country>(responseAll.Result); var countriesResult = new ObservableCollection <Country>(responseRegion.Result); mockSearch.Setup(sp => sp.SearchCountries(keyword, responseRegion.Result, countries)) .Returns(countriesResult); SearchCountry search = new SearchCountry(mockSearch.Object); var actualResult = search.SearchCountries(keyword, responseRegion.Result, countries); var expectedResult = 3; Assert.AreEqual(expectedResult, actualResult.Count); }
public void FilterEmployees() { if (!string.IsNullOrWhiteSpace(SearchName)) { Employees.RemoveAll(e => !(e.FirstName + " " + e.LastName).ToLower().Contains(SearchName.ToLower())); } if (!string.IsNullOrEmpty(SearchInitials)) { Employees.RemoveAll(e => !e.Initials.ToLower().Contains(SearchInitials.ToLower())); } if (!string.IsNullOrEmpty(SearchTitle)) { Employees.RemoveAll(e => !e.Employments.Any(x => x.Title.ToLower().Contains(SearchTitle.ToLower()))); } if (!string.IsNullOrEmpty(SearchCountry)) { Employees.RemoveAll(e => !e.Country.ToLower().Contains(SearchCountry.ToLower())); } }