Exemplo n.º 1
0
        private async Task SaveShowData(RTLDbContext db, TVShowResponse showItem, CancellationToken cancellationToken)
        {
            var showCast     = new List <ShowCast>();
            var duplicateSet = new HashSet <int>();

            foreach (var cast in showItem.Casts)
            {
                if (duplicateSet.Contains(cast.Id))
                {
                    continue;
                }
                if (await db.Actors.AnyAsync(s => s.Id == cast.Id, cancellationToken))
                {
                    if (!await db.TVShowCast
                        .Where(s => s.CastId == cast.Id && s.ShowId == showItem.Id)
                        .AnyAsync(cancellationToken))
                    {
                        db.TVShowCast.Add(new ShowCast()
                        {
                            CastId = cast.Id, ShowId = showItem.Id
                        });
                    }
                }
                else
                {
                    showCast.Add(new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = cast.Name,
                            Id   = cast.Id,
                            DoB  = cast.DoB
                        }
                    });
                }

                duplicateSet.Add(cast.Id);
            }

            var show = new TVShow()
            {
                Id        = showItem.Id,
                Name      = showItem.Name,
                ShowCasts = showCast
            };

            db.TVShows.Add(show);
            await db.SaveChangesAsync(cancellationToken);
        }
Exemplo n.º 2
0
        public void Create()
        {
            // Arrange
            var show = new TVShow()
            {
                Id        = 1,
                Name      = "Test Show",
                ShowCasts = new List <ShowCast>()
                {
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "John Doe",
                            Id   = 1,
                            DoB  = new DateTime(1990, 01, 08)
                        }
                    },
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "Chris Redfield",
                            Id   = 2,
                            DoB  = new DateTime(1978, 06, 12)
                        }
                    }
                }
            };

            var db = new RTLDbContext(new DbContextOptionsBuilder <RTLDbContext>()
                                      .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);

            // Act
            db.TVShows.Add(show);
            db.SaveChanges();

            // Assert
            var showGet = db.TVShows.FirstOrDefault(e => e.Id == 1);

            showGet.Should().NotBeNull();
            showGet.Name.Should().Be(show.Name);

            var actors = db.Actors.ToArray();

            actors.Should().HaveCount(2);
        }
Exemplo n.º 3
0
 public TvMazeShowCastRepository(RTLDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 4
0
 public TvMazePersonRepository(RTLDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 5
0
 public TvMazeShowIndexRepository(RTLDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 6
0
 public BaseRepository(RTLDbContext dbContext)
 {
     DbContext = dbContext;
 }
Exemplo n.º 7
0
 public DataService(RTLDbContext dbContext, ModelMapper modelMapper)
 {
     _dbContext = dbContext;
     _modelMapper = modelMapper;
 }
Exemplo n.º 8
0
        private void PrepareData(RTLDbContext db)
        {
            var show1 = new TVShow()
            {
                Id        = 1,
                Name      = "Test Show",
                ShowCasts = new List <ShowCast>()
                {
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "John Doe",
                            Id   = 1,
                            DoB  = new DateTime(1990, 01, 08)
                        }
                    },
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "Chris Redfield",
                            Id   = 2,
                            DoB  = new DateTime(1978, 06, 12)
                        }
                    }
                }
            };

            var show2 = new TVShow()
            {
                Id        = 2,
                Name      = "Test Show 2",
                ShowCasts = new List <ShowCast>()
                {
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "John Smith",
                            Id   = 3,
                            DoB  = new DateTime(1980, 08, 08)
                        }
                    },
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "Jill Valentine",
                            Id   = 4,
                            DoB  = new DateTime(1977, 07, 17)
                        }
                    }
                    ,
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "Chris Redfield",
                            Id   = 2,
                            DoB  = new DateTime(1978, 06, 12)
                        }
                    }
                }
            };

            var show3 = new TVShow()
            {
                Id        = 3,
                Name      = "Test Show 3",
                ShowCasts = new List <ShowCast>()
                {
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "Charlie Chaplin",
                            Id   = 5,
                            DoB  = new DateTime(1920, 01, 08)
                        }
                    }
                }
            };

            db.TVShows.Add(show1);
            db.TVShows.Add(show2);
            db.TVShows.Add(show3);
            db.SaveChanges();
        }
Exemplo n.º 9
0
        public void Create2()
        {
            // Arrange
            var show1 = new TVShow()
            {
                Id        = 1,
                Name      = "Test Show",
                ShowCasts = new List <ShowCast>()
                {
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "John Doe",
                            Id   = 1,
                            DoB  = new DateTime(1990, 01, 08)
                        }
                    },
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "Chris Redfield",
                            Id   = 2,
                            DoB  = new DateTime(1978, 06, 12)
                        }
                    }
                }
            };

            var show2 = new TVShow()
            {
                Id        = 2,
                Name      = "Test Show 2",
                ShowCasts = new List <ShowCast>()
                {
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "John Smith",
                            Id   = 3,
                            DoB  = new DateTime(1980, 08, 08)
                        }
                    },
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "Jill Valentine",
                            Id   = 4,
                            DoB  = new DateTime(1977, 07, 17)
                        }
                    }
                    ,
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "Chris Redfield",
                            Id   = 2,
                            DoB  = new DateTime(1978, 06, 12)
                        }
                    }
                }
            };

            var show3 = new TVShow()
            {
                Id        = 3,
                Name      = "Test Show 3",
                ShowCasts = new List <ShowCast>()
                {
                    new ShowCast()
                    {
                        Cast = new Cast()
                        {
                            Name = "Charlie Chaplin",
                            Id   = 5,
                            DoB  = new DateTime(1920, 01, 08)
                        }
                    }
                }
            };

            var db = new RTLDbContext(new DbContextOptionsBuilder <RTLDbContext>()
                                      .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);

            // Act
            db.TVShows.Add(show1);
            db.TVShows.Add(show2);
            db.TVShows.Add(show3);
            db.SaveChanges();

            // Assert
            var actors = db.Actors.ToArray();

            actors.Should().HaveCount(5);
            actors.FirstOrDefault(s => s.Id == 2).ShowCasts.Should().HaveCount(2);
        }