Esempio n. 1
0
        public void AlreadyExistingEntityWithUserGeneratedKeyShouldNotBeInserted()
        {
            using (var db = new UnitTestsContext())
            {
                var team1 = new TeamWithUserGeneratedGuidKey()
                {
                    Id   = Guid.NewGuid(),
                    Name = "Team #1",
                };

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


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

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

                Assert.AreEqual(1, db.TeamsWithUserGeneratedGuids.Count());
            }
        }
Esempio n. 2
0
        public void OrderOfNExpected()
        {
            using (var db = new UnitTestsContext())
            {
                var coaches = new List <CoachWithUserGeneratedGuidKey>();
                for (int i = 0; i < 1000; i++)
                {
                    var c = new CoachWithUserGeneratedGuidKey
                    {
                        Id        = Guid.NewGuid(),
                        Firstname = $"Coach {i}",
                        Lastname  = $"Lastname",
                    };
                    for (int j = 0; j < 25; j++)
                    {
                        var t = new TeamWithUserGeneratedGuidKey()
                        {
                            Id   = Guid.NewGuid(),
                            Name = $"Team {j}"
                        };
                        c.Teams.Add(t);
                    }

                    coaches.Add(c);
                }


                db.BulkInsertAll(new BulkInsertRequest <CoachWithUserGeneratedGuidKey>
                {
                    Entities = coaches,
                    EnableRecursiveInsert = EnableRecursiveInsert.Yes
                });

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

                Assert.AreEqual(1000, actual.Count());
                foreach (var coach in actual.ToArray())
                {
                    Assert.AreEqual(25, coach.Teams.Count);
                }
            }
        }