Пример #1
0
        private static void UpdateActor(Actor actor, ActorData data)
        {
            var lastUpdated = DateTime.Parse(data.LastUpdated);

            if (lastUpdated > actor.LastUpdated)
            {
                actor.LastUpdated = lastUpdated;
                actor.Name = data.Name;
                actor.Image = data.Image;
            }
        }
Пример #2
0
 private static Show CreateShow(string name, int theTvDbId, Network network, Genre genre, Actor actor, User user)
 {
     return new Show
     {
         Name = name,
         TheTvDbId = theTvDbId,
         Network = network,
         ShowsGenres = {
             new ShowsGenres(genre)
         },
         ShowsActors = {
             new ShowsActors
             {
                 Actor = actor
             }
         },
         ShowsUsers = {
             new ShowsUsers
             {
                 User = user
             }
         },
         Episodes = {
             new Episode
             {
                 Title = "Title"
             }
         }
     };
 }
Пример #3
0
        private static async Task SeedGenresAsync(TrackTvDbContext context, IEnumerable<Show> shows = null)
        {
            if (shows == null)
            {
                var network = new Network("bbc");
                var genre = new Genre("action");
                var user = new User
                {
                    Username = "bestOfHumanity"
                };
                var actor = new Actor
                {
                    Name = "Cat"
                };

                shows = new[]
                {
                    CreateShow("Show1", 1000, network, genre, actor, user),
                    CreateShow("Show2", 1001, network, genre, actor, user),
                    CreateShow("Show3", 1002, network, genre, actor, user),
                    CreateShow("Show4", 1003, network, genre, actor, user),
                    CreateShow("Show5", 1004, network, genre, actor, user)
                };
            }

            context.Shows.AddRange(shows);
            await context.SaveChangesAsync();
        }
Пример #4
0
 private static void RigRepository(IActorsRepository repository, Actor[] actors)
 {
     repository.GetActorsByTheTvDbIdsAsync(Arg.Any<int[]>()).Returns(actors);
 }
Пример #5
0
 private static void RigRepository(IActorsRepository repository, Actor[] actors, int[] expectedIds)
 {
     repository.GetActorsByTheTvDbIdsAsync(Arg.Is<int[]>(x => x.All(expectedIds.Contains))).Returns(actors);
 }
Пример #6
0
        // 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);
        }
Пример #7
0
        // 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)));
        }
Пример #8
0
 public bool HasActor(Actor actor)
 {
     return this.ShowsActors.Any(x => (x.Actor == actor) || ((x.ActorId != default(int)) && (x.ActorId == actor.Id)));
 }