public void Add_ShowInDB_DoesNotWriteToDB() { var options2 = new DbContextOptionsBuilder <EpisodeContext>() .UseInMemoryDatabase(databaseName: "Add_ShowInDB_DoesNotWriteToDB") .Options; TVShow show = new TVShow() { SeriesId = 281662, SeriesName = "Marvel's Daredevil", SeriesNamePreferred = "Daredevil" }; TVShow sameShow = new TVShow() { SeriesId = 281662, SeriesName = "Marvel's Daredevil", SeriesNamePreferred = "Beastie" }; using (var context = new EpisodeContext(options2)) { var service = new TVShowService(context); service.Add(show); service.Add(sameShow); } using (var context = new EpisodeContext(options2)) { // Assert.Equal("Not real", context.Shows.First().SeriesNamePreferred); var shows = context.Shows.Where(b => b.Id >= 0); foreach (var s in shows) { output.WriteLine($"{s.Id}: SeriesId: {s.SeriesId}; Name: {s.SeriesName}"); } Assert.Equal(1, context.Shows.Count()); Assert.Equal("Daredevil", context.Shows.Single().SeriesNamePreferred); } }
public void FindByName_ShowInDB_ReturnsShow() { var options = new DbContextOptionsBuilder <EpisodeContext>() .UseInMemoryDatabase(databaseName: "FindByName_ShowInDB_ReturnsShow") .Options; TVShow show1 = new TVShow() { SeriesId = 281662, SeriesName = "Marvel's Daredevil", SeriesNamePreferred = "Daredevil" }; TVShow show2 = new TVShow() { SeriesId = 328487, SeriesName = "The Orville" }; using (var context = new EpisodeContext(options)) { var service = new TVShowService(context); context.Database.EnsureCreated(); service.Add(show1); service.Add(show2); } using (var context = new EpisodeContext(options)) { var service = new TVShowService(context); TVShow result = service.FindByName("marvels daredevil"); Assert.Equal(2, context.Shows.Count()); Assert.Equal("Marvel's Daredevil", result.SeriesName); } }
public void GetSeriesIdsNotInDatabase_AllIdsPresent_ReturnsList() { var options = new DbContextOptionsBuilder <EpisodeContext>() .UseInMemoryDatabase(databaseName: "GetSeriesIdsNotInDatabase_AllIdsPresent_ReturnsList") .Options; TVShow show1 = new TVShow() { SeriesId = 281662, SeriesName = "Marvel's Daredevil", SeriesNamePreferred = "Daredevil" }; TVShow show2 = new TVShow() { SeriesId = 328487, SeriesName = "The Orville" }; using (var context = new EpisodeContext(options)) { var service = new TVShowService(context); service.Add(show1); service.Add(show2); } List <int> seriesIdsToCheck = new List <int>() { 281662, 328487 }; int expectedCount = 0; using (var context = new EpisodeContext(options)) { var service = new TVShowService(context); var result = service.GetSeriesIdsNotInDatabase(seriesIdsToCheck); Assert.Equal(expectedCount, result.Count); } }
public void GetSeriesIdsNotInDatabase_IdsNotPresent_ReturnsList() { var options = new DbContextOptionsBuilder <EpisodeContext>() .UseInMemoryDatabase(databaseName: "GetSeriesIdsNotInDatabase_IdsNotPresent_ReturnsList") .Options; TVShow show1 = new TVShow() { SeriesId = 281662, SeriesName = "Marvel's Daredevil", SeriesNamePreferred = "Daredevil" }; using (var context = new EpisodeContext(options)) { var service = new TVShowService(context); service.Add(show1); } List <int> seriesIdsToCheck = new List <int>() { 134, 16690, 281662, 300000 }; int expectedCount = 3; using (var context = new EpisodeContext(options)) { var service = new TVShowService(context); var result = service.GetSeriesIdsNotInDatabase(seriesIdsToCheck); Assert.Equal(expectedCount, result.Count); Assert.Equal(0, result.Find(c => c == 281662)); } }
public void FindByEpisodeForComparingDto_EpInDB_ReturnsEp() { TVShow show = new TVShow() { SeriesId = 328487, SeriesName = "The Orville" }; Episode ep1 = new Episode() { SeriesId = 328487, TVDBEpisodeId = 6089488, Season = 1, AiredEpisodeNumber = 1, EpisodeName = "Old Wounds" }; Episode ep2 = new Episode() { SeriesId = 328487, TVDBEpisodeId = 6123044, Season = 1, AiredEpisodeNumber = 2, EpisodeName = "Command Performance" }; EpisodeForComparingDto epDto = new EpisodeForComparingDto() { SeriesName = "the orville", SeasonNumber = 1, EpisodeNumberInSeason = 1 }; string expectedEpisodeName = "Old Wounds"; var options = new DbContextOptionsBuilder <EpisodeContext>() .UseInMemoryDatabase(databaseName: "FindByEpisodeForComparingDto_EpInDB_ReturnsEp") .Options; using (var context = new EpisodeContext(options)) { var service = new EpisodeService(context); var TVService = new TVShowService(context); TVService.Add(show); service.Add(ep1); service.Add(ep2); } using (var context = new EpisodeContext(options)) { var service = new EpisodeService(context); Episode result = service.FindByEpisodeForComparingDto(epDto); Assert.NotNull(result); Assert.Equal(expectedEpisodeName, result.EpisodeName); } }
public void AddEpisodeToShow_ShowIsInDB_AddsEp() { TVShow show = new TVShow() { SeriesId = 328487, SeriesName = "The Orville" }; Episode ep1 = new Episode() { SeriesId = 328487, TVDBEpisodeId = 6089488, Season = 1, AiredEpisodeNumber = 1, EpisodeName = "Old Wounds", LastUpdated = DateTimeOffset.FromUnixTimeMilliseconds(1527457806).DateTime.ToLocalTime() }; int expectedEpisodeId = 6089488; string expectedEpisodeName = "Old Wounds"; var options = new DbContextOptionsBuilder <EpisodeContext>() .UseInMemoryDatabase(databaseName: "AddEpisodeToShow_ShowIsInDB_AddsEp") .Options; // Act using (var context = new EpisodeContext(options)) { var service = new EpisodeService(context); var TVService = new TVShowService(context); TVService.Add(show); service.AddEpisodeToShow(ep1); } using (var context = new EpisodeContext(options)) { var service = new EpisodeService(context); var result = context.Episodes.FirstOrDefault(e => e.TVDBEpisodeId == expectedEpisodeId); Assert.NotNull(result); Assert.Equal(expectedEpisodeName, result.EpisodeName); } }
public void Add_ShowNotInDB_WritesToDB() { var options = new DbContextOptionsBuilder <EpisodeContext>() .UseInMemoryDatabase(databaseName: "Add_ShowNotInDB_WritesToDB") .Options; TVShow show = new TVShow() { SeriesId = 281662, SeriesName = "The Orville", SeriesNamePreferred = "Orville" }; using (var context = new EpisodeContext(options)) { var service = new TVShowService(context); service.Add(show); } using (var context = new EpisodeContext(options)) { Assert.Equal(1, context.Shows.Count()); Assert.Equal("Orville", context.Shows.Single().SeriesNamePreferred); } }
public void FindByEpisodeForComparingDto_EpNotInDB_ReturnsNull() { TVShow show = new TVShow() { SeriesId = 328487, SeriesName = "The Orville" }; Episode ep1 = new Episode() { SeriesId = 328487, TVDBEpisodeId = 6089488, Season = 1, AiredEpisodeNumber = 1, EpisodeName = "Old Wounds" }; EpisodeForComparingDto epDto = new EpisodeForComparingDto() { SeriesName = "the chilling adventures of sabrina", SeasonNumber = 1, EpisodeNumberInSeason = 1 }; var options = new DbContextOptionsBuilder <EpisodeContext>() .UseInMemoryDatabase(databaseName: "FindByEpisodeForComparingDto_EpNotInDB_ReturnsNull") .Options; using (var context = new EpisodeContext(options)) { var service = new EpisodeService(context); var TVService = new TVShowService(context); TVService.Add(show); service.Add(ep1); } using (var context = new EpisodeContext(options)) { var service = new EpisodeService(context); Episode result = service.FindByEpisodeForComparingDto(epDto); Assert.Null(result); } }
public void FindByName_ShowNotInDB_ReturnsNull() { var options = new DbContextOptionsBuilder <EpisodeContext>() .UseInMemoryDatabase(databaseName: "FindByName_ShowNotInDB_ReturnsNull") .Options; TVShow show1 = new TVShow() { SeriesId = 281662, SeriesName = "Marvel's Daredevil", SeriesNamePreferred = "Daredevil" }; using (var context = new EpisodeContext(options)) { var service = new TVShowService(context); service.Add(show1); } using (var context = new EpisodeContext(options)) { var service = new TVShowService(context); TVShow result = service.FindByName("Counterpart"); Assert.Null(result); } }