示例#1
0
        public void AlreadyExistingEntityWithUserGeneratedKeyShouldNotBeInserted()
        {
            using (var db = new UserGeneratedTeamContext())
            {
                var team1 = new Team
                {
                    Id   = Guid.NewGuid(),
                    Name = "Team #1",
                };

                db.BulkInsertAll(new BulkInsertRequest <Team>
                {
                    Entities = new[] { team1 }.ToList()
                });


                Assert.AreEqual(1, db.Teams.Count());

                db.BulkInsertAll(new BulkInsertRequest <Team>
                {
                    Entities = new[] { team1 }.ToList()
                });

                Assert.AreEqual(1, db.Teams.Count());
            }
        }
        public void SelectNotExistingFromTableWithUserGeneratedGuidAsPrimaryKeyShouldWork()
        {
            using (var db = new UserGeneratedTeamContext())
            {
                var teams = new List <Team>();
                for (int i = 0; i < 10; i++)
                {
                    teams.Add(new Team {
                        Id = Guid.NewGuid(), Name = $"Team #{i}"
                    });
                }

                db.BulkInsertAll(new BulkInsertRequest <Team>
                {
                    Entities = teams
                });

                for (int i = 10; i < 20; i++)
                {
                    teams.Add(new Team {
                        Id = Guid.NewGuid(), Name = $"Team #{i}"
                    });
                }

                var existingTeams = db.BulkSelectNotExisting <Team, Team>(new BulkSelectRequest <Team>(new [] { "Id" }, teams));
                Assert.AreEqual(10, existingTeams.Count);
                for (int i = 0; i < 10; i++)
                {
                    Assert.AreEqual(teams[i + 10].Id, existingTeams[i].Id);
                    Assert.AreEqual(teams[i + 10].Name, existingTeams[i].Name);
                }
            }
        }
示例#3
0
        public void OrderOfNExpected()
        {
            using (var db = new UserGeneratedTeamContext())
            {
                var coaches = new List <Coach>();
                for (int i = 0; i < 1000; i++)
                {
                    var c = new Coach
                    {
                        Id        = Guid.NewGuid(),
                        Firstname = $"Coach {i}",
                        Lastname  = $"Lastname",
                    };
                    for (int j = 0; j < 25; j++)
                    {
                        var t = new Team
                        {
                            Id   = Guid.NewGuid(),
                            Name = $"Team {j}"
                        };
                        c.Teams.Add(t);
                    }

                    coaches.Add(c);
                }


                db.BulkInsertAll(new BulkInsertRequest <Coach>
                {
                    Entities  = coaches,
                    Recursive = true
                });

                var actual = db.Coaches
                             .Include(c => c.Teams)
                             .ToArray();

                Assert.AreEqual(1000, actual.Count());
                foreach (var coach in actual.ToArray())
                {
                    Assert.AreEqual(25, coach.Teams.Count);
                }
            }
        }
示例#4
0
        public void SelectExistingFromTableWithUserGeneratedGuidAsPrimaryKey()
        {
            using (var db = new UserGeneratedTeamContext())
            {
                var teams = new List <Team>();

                // Add ten teams to the database (Team 0 - Team 9)
                for (int i = 0; i < 10; i++)
                {
                    teams.Add(new Team {
                        Id = Guid.NewGuid(), Name = $"Team #{i}"
                    });
                }

                // Save the ten first teams to the database.
                db.BulkInsertAll(new BulkInsertRequest <Team>
                {
                    Entities = teams,
                });

                // Add another ten teams (Team 10 - Team 19) to
                // the list but not to the database.
                for (int i = 10; i < 20; i++)
                {
                    teams.Add(new Team {
                        Id = Guid.NewGuid(), Name = $"Team #{i}"
                    });
                }

                // The only teams we should get back out of the 20 teams (Team 0 - Team 19)
                // are the first ten that we saved to the database.
                var existingTeams = db.BulkSelectExisting <Team, Team>(new BulkSelectRequest <Team>(new[] { "Id" }, teams));
                existingTeams = existingTeams.OrderBy(t => t.Name).ToList();
                Assert.AreEqual(10, existingTeams.Count);
                for (int i = 0; i < 10; i++)
                {
                    Assert.AreEqual(teams[i].Id, existingTeams[i].Id);
                    Assert.AreEqual(teams[i].Name, existingTeams[i].Name);
                }
            }
        }