public virtual void EnsureSeasons(int seriesId, IEnumerable<int> seasons) { var existingSeasons = GetSeasons(seriesId); foreach (var season in seasons) { if (!existingSeasons.Contains(season)) { var newSeason = new Season { SeriesId = seriesId, SeasonNumber = season, Ignored = season == 0 }; _database.Insert(newSeason); } } }
public Season MapIt(Season season, Episode episode, EpisodeFile episodeFile) { // Terminating call. Since we can return null from this function // we need to be ready for PetaPoco to callback later with null // parameters if (season == null) return _current; //Todo: Find a Query that doesn't require this check //Map EpisodeFile to Episode (Map to null if 0, because PetaPoco is returning a POCO when it should be null) episode.EpisodeFile = (episode.EpisodeFileId == 0 ? null : episodeFile); // Is this the same season as the current one we're processing if (_current != null && _current.SeasonId == season.SeasonId) { // Yes, just add this post to the current author's collection of posts _current.Episodes.Add(episode); // Return null to indicate we're not done with this author yet return null; } // This is season different author to the current one, or this is the // first time through and we don't have an season yet // Save the current author var prev = _current; // Setup the new current season _current = season; _current.Episodes = new List<Episode>(); _current.Episodes.Add(episode); // Return the now populated previous season (or null if first time through) return prev; }
public void IgnoreSeason_should_call_SetIgnore_in_season_provider_one_time_only() { WithRealDb(); var episodes = Builder<Episode>.CreateListOfSize(4) .All() .With(c => c.SeriesId = 10) .With(c => c.SeasonNumber = 1) .With(c => c.Ignored = false) .Build().ToList(); var season = new Season { SeriesId = 10, SeasonNumber = 1, Ignored = false }; Db.Insert(season); Db.InsertMany(episodes); Mocker.GetMock<SeasonProvider>().Setup(s => s.SetIgnore(10, 1, true)).Verifiable(); //Act Mocker.Resolve<EpisodeProvider>().SetSeasonIgnore(10, 1, true); //Assert var episodesInDb = Db.Fetch<Episode>(@"SELECT * FROM Episodes"); episodesInDb.Should().HaveCount(4); episodesInDb.Where(e => e.Ignored).Should().HaveCount(4); Mocker.GetMock<SeasonProvider>().Verify(s => s.SetIgnore(10, 1, true), Times.Once()); }