public void SearchTest() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <AppDbContext>() .UseSqlite(connection) .Options; AppDbContextTest.SeedTestDataToDbAndTest(options); using (var appDbContext = new AppDbContext(options)) { var repo = new EfRepository(appDbContext); var result = repo.FindSearchResult("cat"); Assert.Equal(1, result.UrlSearchResults.Count); Assert.Equal("cat.com", result.UrlSearchResults.First().Url.UrlString); Assert.Equal(1, result.UrlSearchResults.First().UrlSearchResultSearchEngines.Count); Assert.False(result.UrlSearchResults.First().UrlSearchResultSearchEngines.First().IsNew); Assert.Equal(appDbContext.SearchEngines.First(x => x.Name == "Google").Name, result.UrlSearchResults.First().UrlSearchResultSearchEngines.First().SearchEngine.Name); } } finally { connection.Close(); } }
public void SearchTest() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <AppDbContext>() .UseSqlite(connection) .Options; AppDbContextTest.SeedTestDataToDbAndTest(options); using (var appDbContext = new AppDbContext(options)) { var logger = Mock.Of <ILogger <SearchProcessor> >(); var bingMoq = new Mock <ISearchEngine>(); bingMoq.Setup(x => x.Name).Returns("Bing"); bingMoq.Setup(x => x.Search("cat")).Returns(new List <Url> { new Url() { UrlString = "cat.com" }, new Url() { UrlString = "cat.net" }, new Url() { UrlString = "cat.io" }, }); var googleMoq = new Mock <ISearchEngine>(); googleMoq.Setup(x => x.Name).Returns("Google"); googleMoq.Setup(x => x.Search("cat")).Returns(new List <Url> { new Url() { UrlString = "cat.com" }, new Url() { UrlString = "cat.net" }, new Url() { UrlString = "cat.ru" }, }); var repo = new EfRepository(appDbContext); var processor = new SearchProcessor(new[] { bingMoq.Object, googleMoq.Object }, repo, logger); Assert.Equal(1, processor.Search("cat", true).UrlSearchResults.Count); var result1 = processor.Search("cat", false); Assert.Equal(4, processor.Search("cat", true).UrlSearchResults.Count); Assert.Equal(2, processor.Search("cat", true).UrlSearchResults.First().UrlSearchResultSearchEngines.Count); Assert.Equal(1, processor.Search("cat", true).UrlSearchResults.Last().UrlSearchResultSearchEngines.Count); } } finally { connection.Close(); } }