public static void DataSeed(this WorldCupContext context)
        {
            if (context.Teams.Any())
            {
                return;
            }

            var teams = new List <Team>
            {
                new Team
                {
                    Name        = "Belgium",
                    Description = "The one with that big park.",
                    UpdatedOn   = DateTime.Now.AddDays(value: -1),
                    Continent   = ContinentCode.Europe,
                    Players     = new List <Player>
                    {
                        new Player
                        {
                            FirstName   = "Hazard",
                            Description = "He plays in Chelsea.",
                            IsTopPlayer = true
                        },
                        new Player
                        {
                            FirstName   = "De Bruyne",
                            Description = "He scored the last match."
                        }
                    }
                },
                new Team
                {
                    Name        = "France",
                    Description = "One time world cup winner.",
                    Continent   = ContinentCode.Europe,
                    UpdatedOn   = DateTime.Now,
                    Players     = new List <Player>
                    {
                        new Player
                        {
                            FirstName   = "MBappe",
                            Description = "19 years old striker."
                        },
                        new Player
                        {
                            FirstName   = "Pogba",
                            Description = "He plays for MUTD.",
                            IsTopPlayer = true
                        }
                    }
                }
            };

            context.Teams.AddRange(teams);
            context.SaveChanges();
        }
Beispiel #2
0
        public void TestWorldCupContext()
        {
            /* ================== Montando Cenario =================== */
            var options = new DbContextOptionsBuilder <WorldCupContext>()
                          .UseInMemoryDatabase(databaseName: "WorldCupDB").Options;

            /* ================== Execucao =================== */
            using (var ctx = new WorldCupContext(options))
            {
                ctx.Teams.Add(new Team {
                    Name = "Brasil", Flag = "BRA"
                });
                ctx.SaveChanges();

                /* ================== Verificacao =================== */

                // Testando com Assert
                Assert.NotEmpty(ctx.Teams.ToList());

                // Testando com FluentAssertions
                //ctx.Teams.ToList().Should().NotBeEmpty(ctx.Teams.ToList().ToString(),
                //    $"O objeto esperado não corresponde com ao objeto obtido ({ctx.Teams.ToList().ToString()})");
            }
        }
Beispiel #3
0
 public void Add(TEntity obj)
 {
     db.Set <TEntity>().Add(obj);
     db.SaveChanges();
 }
Beispiel #4
0
 public TEntity Add(TEntity obj)
 {
     _ctx.Set <TEntity>().Add(obj);
     _ctx.SaveChanges();
     return(obj);
 }