// ReSharper disable once InconsistentNaming public async Task PopulateGenresAsync_should_add_new_genres() { var genresRepository = Substitute.For<IGenresRepository>(); var names = new[] { "action", "drama", "comedy" }; genresRepository.GetGenresByNamesAsync(names).Returns(new Genre[0]); var fetcher = new GenreFetcher(genresRepository); var show = new Show(); await fetcher.PopulateGenresAsync(show, names); await genresRepository.Received().GetGenresByNamesAsync(names); var relationships = show.ShowsGenres.ToArray(); for (int i = 0; i < names.Length; i++) { Assert.Equal(names[i], relationships[i].Genre.Name); } }
private void MapToShow(Show show, Series data) { show.TheTvDbId = data.Id; show.Name = data.SeriesName; show.Banner = data.Banner; show.ImdbId = data.ImdbId; show.Description = data.Overview; show.LastUpdated = data.LastUpdated.ToDateTime(); AirDay airDay; Enum.TryParse(data.AirsDayOfWeek, out airDay); show.AirDay = airDay; ShowStatus status; Enum.TryParse(data.Status, out status); show.Status = status; if (!string.IsNullOrWhiteSpace(data.FirstAired)) { show.FirstAired = this.DateParser.ParseFirstAired(data.FirstAired); } if (!string.IsNullOrWhiteSpace(data.AirsTime)) { show.AirTime = this.DateParser.ParseAirTime(data.AirsTime); } }
private async Task AddNetworkAsync(Show show, string networkName) { if (!show.HasNetwork() || (show.Network.Name != networkName)) { var existingNetwork = await this.NetworkRepository.GetNetworkByNameAsync(networkName); show.Network = existingNetwork ?? new Network(networkName); } }
public async Task AddNewEpisodesAsync(Show show) { var ids = await this.GetAllEpisodeIdsAsync(show.TheTvDbId); var existingIds = show.Episodes.Select(x => x.TheTvDbId); var newIds = ids.Except(existingIds).ToArray(); await this.AddEpisodesAsync(show, newIds); }
// ReSharper disable once InconsistentNaming public async Task PopulateActorsAsync_should_add_existing_actors() { var repository = Substitute.For<IActorsRepository>(); var client = Substitute.For<ISeriesClient>(); var response = new TvDbResponse<ActorData[]>(); var data = new List<ActorData>(); for (int i = 0; i < 5; i++) { data.Add(new ActorData { Id = i, Name = $"Actor {i}", LastUpdated = $"0001-02-0{i + 1}", Image = $"Image {i}" }); } response.Data = data.ToArray(); var show = new Show { TheTvDbId = 42 }; var actors = response.Data.Select(x => new Actor { TheTvDbId = x.Id }).ToArray(); RigRepository(repository, actors); RigClient(client, show.TheTvDbId, response); var fetcher = new ActorFetcher(repository, client); await fetcher.PopulateActorsAsync(show); var relationships = show.ShowsActors.ToArray(); Assert.Equal(response.Data.Length, relationships.Length); for (int i = 0; i < response.Data.Length; i++) { Assert.Equal(actors[i], relationships[i].Actor); Assert.Equal(response.Data[i].Role, relationships[i].Role); Assert.Equal(response.Data[i].Id, actors[i].TheTvDbId); Assert.Equal(response.Data[i].Name, actors[i].Name); Assert.Equal(response.Data[i].Image, actors[i].Image); Assert.Equal(response.Data[i].LastUpdated, actors[i].LastUpdated.ToString("yyyy-MM-dd")); } }
private static ShowSummary MapToSummary(Show show, IEnumerable<SubscriberSummary> subscriberCounts) { return new ShowSummary { Name = show.Name, Banner = show.Banner, ImdbId = show.ImdbId, Status = show.Status, SubscriberCount = subscriberCounts.First(x => x.ShowId == show.Id).SubscriberCount }; }
private async Task AddEpisodesAsync(Show show, IEnumerable<int> ids) { var records = await this.AdvancedEpisodeClient.GetFullEpisodesAsync(ids); foreach (var record in records) { var episode = new Episode(); this.MapToEpisode(episode, record); show.Episodes.Add(episode); } }
public async Task AddShowAsync(int theTvDbId) { var show = new Show { TheTvDbId = theTvDbId }; await this.PopulateShowAsync(show); await this.EpisodeFetcher.AddAllEpisodesAsync(show); this.Context.Shows.Add(show); await this.Context.SaveChangesAsync(); }
// ReSharper disable once InconsistentNaming public async Task AddAllEpisodesAsync_should_add_all_episodes_to_show() { var episodesClient = Substitute.For<IEpisodesClient>(); var advancedEpisodesClient = Substitute.For<IAdvancedEpisodeClient>(); var advancedSeriesClient = Substitute.For<IAdvancedSeriesClient>(); var fetcher = new EpisodeFetcher(episodesClient, advancedEpisodesClient, advancedSeriesClient); var show = new Show { TheTvDbId = 42 }; var basics = new[] { new BasicEpisode { Id = 1 }, new BasicEpisode { Id = 2 }, new BasicEpisode { Id = 3 } }; var episodeRecords = basics.Select(x => new EpisodeRecord { Id = x.Id, AiredEpisodeNumber = 0, AiredSeason = 0 }); Expression<Predicate<IEnumerable<int>>> isIdsOfBasics = x => x.SequenceEqual(basics.Select(e => e.Id)); advancedSeriesClient.GetBasicEpisodesAsync(show.TheTvDbId).Returns(basics); advancedEpisodesClient.GetFullEpisodesAsync(Arg.Is(isIdsOfBasics)).Returns(episodeRecords); await fetcher.AddAllEpisodesAsync(show); Assert.Equal(basics.Length, show.Episodes.Count); Assert.True(show.Episodes.Select(x => x.TheTvDbId).SequenceEqual(basics.Select(e => e.Id))); }
public async Task PopulateGenresAsync(Show show, string[] genreNames) { if (genreNames.Length == 0) { throw new ArgumentException("The genre names array is empty.", nameof(genreNames)); } var genres = await this.GenresRepository.GetGenresByNamesAsync(genreNames); foreach (string genreName in genreNames) { var genre = GetOrCreateGenre(genres, genreName); if (!show.HasGenre(genre)) { show.ShowsGenres.Add(new ShowsGenres(genre)); } } }
// ReSharper disable once InconsistentNaming public async Task PopulateShowAsync_should_add_new_network() { var repository = Substitute.For<INetworkRepository>(); var data = new Series { Network = "bbc" }; repository.GetNetworkByNameAsync(data.Network).Returns((Network)null); var fetcher = new ShowFetcher(repository); var show = new Show(); await fetcher.PopulateShowAsync(show, data); await repository.Received().GetNetworkByNameAsync(data.Network); Assert.Equal(data.Network, show.Network.Name); }
public async Task PopulateActorsAsync(Show show) { var response = await this.Client.GetActorsAsync(show.TheTvDbId); var ids = response.Data.Select(actor => actor.Id).ToArray(); var actors = await this.ActorsRepository.GetActorsByTheTvDbIdsAsync(ids); foreach (var data in response.Data) { var actor = GetOrCreateActor(actors, data); if (!show.HasActor(actor)) { show.ShowsActors.Add(new ShowsActors(actor, data.Role)); } else { var relationship = show.ShowsActors.FirstOrDefault(x => x.ActorId == actor.Id); UpdateShowActorRelationship(relationship, data); } } }
// ReSharper disable once InconsistentNaming public async Task PopulateGenresAsync_should_attach_existing_and_add_new_genres() { var genresRepository = Substitute.For<IGenresRepository>(); var names = new[] { "action", "comedy", "drama", "Sci-Fi" }; var genres = new[] { new Genre("action"), new Genre("comedy") }; genresRepository.GetGenresByNamesAsync(names).Returns(genres); var fetcher = new GenreFetcher(genresRepository); var show = new Show(); await fetcher.PopulateGenresAsync(show, names); await genresRepository.Received().GetGenresByNamesAsync(names); var relationships = show.ShowsGenres.ToArray(); Assert.Equal(genres[0], relationships[0].Genre); Assert.Equal(genres[1], relationships[1].Genre); Assert.Equal(names[2], relationships[2].Genre.Name); Assert.Equal(names[3], relationships[3].Genre.Name); }
// ReSharper disable once InconsistentNaming public async Task AddNewEpisodesAsync_should_map_episodes() { var episodesClient = Substitute.For<IEpisodesClient>(); var advancedEpisodesClient = Substitute.For<IAdvancedEpisodeClient>(); var advancedSeriesClient = Substitute.For<IAdvancedSeriesClient>(); var fetcher = new EpisodeFetcher(episodesClient, advancedEpisodesClient, advancedSeriesClient); var show = new Show { TheTvDbId = 42, Episodes = { new Episode { TheTvDbId = 1 } } }; var basics = new[] { new BasicEpisode { Id = 1 }, new BasicEpisode { Id = 2 } }; var episodeRecords = new[] { new EpisodeRecord { Id = 2, EpisodeName = "Rose", Overview = "Rose Tyler stumbles across a man called The Doctor...", ImdbId = "tt0562992", AiredEpisodeNumber = 1, AiredSeason = 1, FirstAired = "2005-03-26", LastUpdated = 1477941112 } }; Expression<Predicate<IEnumerable<int>>> isIdsOfBasicsExceptFirst = x => x.SequenceEqual(basics.Skip(1).Select(e => e.Id)); advancedSeriesClient.GetBasicEpisodesAsync(show.TheTvDbId).Returns(basics); advancedEpisodesClient.GetFullEpisodesAsync(Arg.Is(isIdsOfBasicsExceptFirst)).Returns(episodeRecords); await fetcher.AddNewEpisodesAsync(show); var record = episodeRecords.First(); var episode = show.Episodes.Skip(1).First(); Assert.Equal(record.EpisodeName, episode.Title); Assert.Equal(record.Overview, episode.Description); Assert.Equal(record.ImdbId, episode.ImdbId); Assert.Equal(record.AiredEpisodeNumber, episode.Number); Assert.Equal(record.AiredSeason, episode.SeasonNumber); Assert.Equal(new DateTime(2005, 3, 26), episode.FirstAired); Assert.Equal(new DateTime(2016, 10, 31, 19, 11, 52), episode.LastUpdated); }
public async Task AddAllEpisodesAsync(Show show) { var ids = await this.GetAllEpisodeIdsAsync(show.TheTvDbId); await this.AddEpisodesAsync(show, ids); }
// ReSharper disable once InconsistentNaming public async Task PopulateGenresAsync_should_query_the_genres_by_name() { var genresRepository = Substitute.For<IGenresRepository>(); var names = new[] { "action" }; var genres = new[] { new Genre("action") }; genresRepository.GetGenresByNamesAsync(names).Returns(genres); var fetcher = new GenreFetcher(genresRepository); var show = new Show(); await fetcher.PopulateGenresAsync(show, names); await genresRepository.Received().GetGenresByNamesAsync(names); }
public async Task PopulateShowAsync(Show show, Series data) { this.MapToShow(show, data); await this.AddNetworkAsync(show, data.Network); }
private async Task PopulateShowAsync(Show show) { var response = await this.Client.Series.GetAsync(show.TheTvDbId); await this.ShowFetcher.PopulateShowAsync(show, response.Data); await this.GenreFetcher.PopulateGenresAsync(show, response.Data.Genre); await this.ActorFetcher.PopulateActorsAsync(show); }
// ReSharper disable once InconsistentNaming public async Task PopulateShowAsync_should_not_replace_the_network_if_it_has_the_same_name() { var data = new Series { Network = "bbc" }; var fetcher = CreateFetcher(); var network = new Network(data.Network); var show = new Show { Network = network }; await fetcher.PopulateShowAsync(show, data); Assert.Equal(network, show.Network); }
// ReSharper disable once InconsistentNaming public async Task AddNewEpisodesAsync_should_get_full_episodesd_from_the_client() { var episodesClient = Substitute.For<IEpisodesClient>(); var advancedEpisodesClient = Substitute.For<IAdvancedEpisodeClient>(); var advancedSeriesClient = Substitute.For<IAdvancedSeriesClient>(); var fetcher = new EpisodeFetcher(episodesClient, advancedEpisodesClient, advancedSeriesClient); var show = new Show { TheTvDbId = 42, Episodes = { new Episode { TheTvDbId = 1 } } }; var basics = new[] { new BasicEpisode { Id = show.Episodes.First().TheTvDbId }, new BasicEpisode { Id = 2 }, new BasicEpisode { Id = 3 } }; advancedSeriesClient.GetBasicEpisodesAsync(show.TheTvDbId).Returns(basics); Expression<Predicate<IEnumerable<int>>> isIdsOfBasicsExceptFirst = x => x.SequenceEqual(basics.Skip(1).Select(e => e.Id)); advancedEpisodesClient.GetFullEpisodesAsync(Arg.Is(isIdsOfBasicsExceptFirst)).Returns(Array.Empty<EpisodeRecord>()); await fetcher.AddNewEpisodesAsync(show); await advancedEpisodesClient.Received().GetFullEpisodesAsync(Arg.Is(isIdsOfBasicsExceptFirst)); }
// ReSharper disable once InconsistentNaming public async Task PopulateActorsAsync_should_update_role_on_existing_actor() { var repository = Substitute.For<IActorsRepository>(); var client = Substitute.For<ISeriesClient>(); var response = new TvDbResponse<ActorData[]> { Data = new[] { new ActorData { Id = 1, Name = "Actor 1", LastUpdated = "0001-02-01", Image = "Image 1", Role = "Role 1" } } }; var actor = new Actor { TheTvDbId = 1 }; var show = new Show { TheTvDbId = 42, ShowsActors = { new ShowsActors { Actor = actor } } }; var actors = new List<Actor> { actor }; RigRepository(repository, actors.ToArray()); RigClient(client, show.TheTvDbId, response); var fetcher = new ActorFetcher(repository, client); await fetcher.PopulateActorsAsync(show); Assert.Equal(response.Data.First().Role, show.ShowsActors.First().Role); }
// ReSharper disable once InconsistentNaming public async Task PopulateActorsAsync_should_query_actors_from_the_repository() { var repository = Substitute.For<IActorsRepository>(); var client = Substitute.For<ISeriesClient>(); var expectedIds = new[] { 1, 2, 3 }; var actors = new Actor[0]; var show = new Show { TheTvDbId = 42 }; var actorsResponse = new TvDbResponse<ActorData[]> { Data = new[] { new ActorData { Id = 1, LastUpdated = DefaultLastUpdated }, new ActorData { Id = 2, LastUpdated = DefaultLastUpdated }, new ActorData { Id = 3, LastUpdated = DefaultLastUpdated } } }; RigRepository(repository, actors, expectedIds); RigClient(client, show.TheTvDbId, actorsResponse); var fetcher = new ActorFetcher(repository, client); await fetcher.PopulateActorsAsync(show); await repository.Received().GetActorsByTheTvDbIdsAsync(Arg.Is<int[]>(x => x.All(expectedIds.Contains))); }
// ReSharper disable once InconsistentNaming public async Task PopulateShowAsync_should_replace_existing_network() { var data = new Series { Network = "bbc 2" }; var fetcher = CreateFetcher(); var network = new Network("bbc"); var show = new Show { Network = network }; await fetcher.PopulateShowAsync(show, data); Assert.Equal(data.Network, show.Network.Name); }
// ReSharper disable once InconsistentNaming public async Task AddAllEpisodesAsync_should_get_basic_episodesd_from_the_client() { var episodesClient = Substitute.For<IEpisodesClient>(); var advancedEpisodesClient = Substitute.For<IAdvancedEpisodeClient>(); var advancedSeriesClient = Substitute.For<IAdvancedSeriesClient>(); var fetcher = new EpisodeFetcher(episodesClient, advancedEpisodesClient, advancedSeriesClient); var show = new Show { TheTvDbId = 42 }; advancedSeriesClient.GetBasicEpisodesAsync(show.TheTvDbId).Returns(Array.Empty<BasicEpisode>()); advancedEpisodesClient.GetFullEpisodesAsync(Arg.Is<IEnumerable<int>>(x => !x.Any())).Returns(Array.Empty<EpisodeRecord>()); await fetcher.AddAllEpisodesAsync(show); await advancedSeriesClient.Received().GetBasicEpisodesAsync(show.TheTvDbId); }
// ReSharper disable once InconsistentNaming public async Task PopulateShowAsync_should_copy_data_to_the_show() { var data = new Series { Network = "BBC One", SeriesName = "Doctor Who (2005)", AirsTime = "8:30 PM", Banner = "graphical/78804-g51.jpg", FirstAired = "2005-03-26", ImdbId = "tt0436992", LastUpdated = 1477651508, Overview = "The Doctor is an alien Time Lord... ", Status = "Continuing", AirsDayOfWeek = "Monday" }; var fetcher = CreateFetcher(); var show = new Show(); await fetcher.PopulateShowAsync(show, data); Assert.Equal(data.Network, show.Network.Name); Assert.Equal(data.SeriesName, show.Name); Assert.Equal(data.Banner, show.Banner); Assert.Equal(data.Overview, show.Description); Assert.Equal(data.ImdbId, show.ImdbId); Assert.Equal(ShowStatus.Continuing, show.Status); Assert.Equal(AirDay.Monday, show.AirDay); Assert.Equal(new DateTime(2016, 10, 28, 10, 45, 8), show.LastUpdated); // ReSharper disable once PossibleInvalidOperationException Assert.Equal("20:30", show.AirTime.Value.ToString("HH:mm")); // ReSharper disable once PossibleInvalidOperationException Assert.Equal("2005-03-26", show.FirstAired.Value.ToString("yyy-MM-dd")); }
private static void AssertIsFull(Show show) { Assert.NotNull(show.Network); Assert.True(show.Episodes.Any()); Assert.True(show.ShowsGenres.Any()); Assert.True(show.ShowsActors.Any()); Assert.True(show.ShowsUsers.Any()); }