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);
                }
            }
        }
Пример #2
0
        public void SelectNotExistingFromTableWithUserGeneratedGuidAsPrimaryKeyShouldWork()
        {
            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 last ten that we did not save to the database.
                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);
                }
            }
        }