예제 #1
0
        public void Verify_that_order_of_insert_is_based_on_key_values_and_not_order_of_adding_to_collection()
        {
            using (var context = new GearsOfWarContext())
            {
                var weapon1 = new HeavyWeapon
                    {
                        Id = 10,
                        Name = "Mortar",
                        Overheats = false,
                    };

                var weapon2 = new HeavyWeapon
                    {
                        Id = 11,
                        Name = "Oneshot",
                        Overheats = false,
                    };

                var weapon3 = new StandardWeapon
                    {
                        Id = 12,
                        Name = "Boltok",
                        Specs = new WeaponSpecification
                            {
                                AmmoPerClip = 6,
                                ClipsCount = 9,
                            },
                    };

                context.Weapons.Add(weapon3);
                context.Weapons.Add(weapon1);
                context.Weapons.Add(weapon2);
                context.SaveChanges();

                var newWeapons = context.Weapons.OrderByDescending(t => t.Id).Take(3).ToList();

                Assert.Equal("Boltok", newWeapons[0].Name);
                Assert.Equal("Oneshot", newWeapons[1].Name);
                Assert.Equal("Mortar", newWeapons[2].Name);
            }
        }
예제 #2
0
        public void Saving_null_compex_type_property_throws()
        {
            using (var context = new GearsOfWarContext())
            {
                var secretWeapon = new StandardWeapon
                {
                    Name = "Top Secret",
                    Specs = null,
                };

                context.Weapons.Add(secretWeapon);

                Assert.Throws<DbUpdateException>(() => context.SaveChanges())
                    .ValidateMessage(typeof(DbContext).Assembly(), "Update_NullValue", null, "Specs");
            }
        }
예제 #3
0
        public void Inserting_entities_that_reference_themselves_in_a_cycle_throws()
        {
            using (var context = new GearsOfWarContext())
            {
                var snub = new StandardWeapon
                {
                    Name = "Snub",
                    Specs = new WeaponSpecification
                    {
                        AmmoPerClip = 12,
                        ClipsCount = 11,
                    }
                };

                var sawedoff = new StandardWeapon
                {
                    Name = "Sawed-Off Shotgun",
                    Specs = new WeaponSpecification
                    {
                        AmmoPerClip = 1,
                        ClipsCount = 6,
                    }
                };

                var longshot = new StandardWeapon
                {
                    Name = "Longshot",
                    Specs = new WeaponSpecification
                    {
                        AmmoPerClip = 1,
                        ClipsCount = 24,
                    }
                };

                snub.SynergyWith = sawedoff;
                sawedoff.SynergyWith = longshot;
                longshot.SynergyWith = snub;

                context.Weapons.Add(snub);

                Assert.Throws<DbUpdateException>(() => context.SaveChanges())
                    .InnerException.ValidateMessage(typeof(DbContext).Assembly(), "Update_ConstraintCycle", null);
            }
        }
        protected override void Seed(GearsOfWarContext context)
        {
            var lancer = new StandardWeapon
            {
                Name  = "Lancer",
                Specs = new WeaponSpecification
                {
                    AmmoPerClip = 60,
                    ClipsCount  = 8,
                }
            };

            var gnasher = new StandardWeapon
            {
                Name  = "Gnasher",
                Specs = new WeaponSpecification
                {
                    AmmoPerClip = 8,
                    ClipsCount  = 6,
                },

                SynergyWith = lancer,
            };

            var hammerburst = new StandardWeapon
            {
                Name  = "Hammerburst",
                Specs = new WeaponSpecification
                {
                    AmmoPerClip = 20,
                    ClipsCount  = 7,
                }
            };

            var markza = new StandardWeapon
            {
                Name  = "Markza",
                Specs = new WeaponSpecification
                {
                    AmmoPerClip = 10,
                    ClipsCount  = 12,
                },

                SynergyWith = gnasher,
            };

            var mulcher = new HeavyWeapon
            {
                Name      = "Mulcher",
                Overheats = true,
            };

            context.Weapons.AddRange(new List <Weapon> {
                lancer, gnasher, hammerburst, markza, mulcher,
            });

            var deltaSquad = new Squad
            {
                Id   = 1,
                Name = "Delta",
            };

            var kiloSquad = new Squad
            {
                Id   = 2,
                Name = "Kilo",
            };

            context.Squads.AddRange(new[] { deltaSquad, kiloSquad });

            var jacinto = new City
            {
                Location = DbGeography.FromText("POINT(1 1)", GeographySrid),
                Name     = "Jacinto",
            };

            var ephyra = new City
            {
                Location = DbGeography.FromText("POINT(2 2)", GeographySrid),
                Name     = "Ephyra",
            };

            var hanover = new City
            {
                Location = DbGeography.FromText("POINT(3 3)", GeographySrid),
                Name     = "Hanover",
            };

            context.Cities.AddRange(new[] { jacinto, ephyra, hanover });

            var marcusTag = new CogTag
            {
                Note = "Marcus's Tag",
            };

            var domsTag = new CogTag
            {
                Note = "Dom's Tag",
            };

            var colesTag = new CogTag
            {
                Note = "Cole's Tag",
            };

            var bairdsTag = new CogTag
            {
                Note = "Bairds's Tag",
            };

            var paduksTag = new CogTag
            {
                Note = "Paduk's Tag",
            };

            var kiaTag = new CogTag
            {
                Note = "K.I.A.",
            };

            context.Tags.AddRange(
                new[] { marcusTag, domsTag, colesTag, bairdsTag, paduksTag, kiaTag });

            var marcus = new Gear
            {
                Nickname    = "Marcus",
                FullName    = "Marcus Fenix",
                Squad       = deltaSquad,
                Rank        = MilitaryRank.Sergeant,
                Tag         = marcusTag,
                CityOfBirth = jacinto,
                Weapons     = new List <Weapon> {
                    lancer, gnasher
                },
            };

            var dom = new Gear
            {
                Nickname    = "Dom",
                FullName    = "Dominic Santiago",
                Squad       = deltaSquad,
                Rank        = MilitaryRank.Corporal,
                Tag         = domsTag,
                CityOfBirth = ephyra,
                Weapons     = new List <Weapon> {
                    hammerburst, gnasher
                }
            };

            var cole = new Gear
            {
                Nickname    = "Cole Train",
                FullName    = "Augustus Cole",
                Squad       = deltaSquad,
                Rank        = MilitaryRank.Private,
                Tag         = colesTag,
                CityOfBirth = hanover,
                Weapons     = new List <Weapon> {
                    gnasher, mulcher
                }
            };

            var baird = new Gear
            {
                Nickname = "Baird",
                FullName = "Damon Baird",
                Squad    = deltaSquad,
                Rank     = MilitaryRank.Corporal,
                Tag      = bairdsTag,
                Weapons  = new List <Weapon> {
                    lancer, gnasher
                }
            };

            var paduk = new Gear
            {
                Nickname = "Paduk",
                FullName = "Garron Paduk",
                Squad    = kiloSquad,
                Rank     = MilitaryRank.Private,
                Tag      = paduksTag,
                Weapons  = new List <Weapon> {
                    markza
                },
            };

            marcus.Reports = new List <Gear> {
                dom, cole, baird
            };
            baird.Reports = new List <Gear> {
                paduk
            };

            context.Gears.AddRange(new[] { marcus, dom, cole, baird, paduk });
        }
예제 #5
0
        public void Inserting_entities_that_both_reference_each_other_throws()
        {
            ExtendedSqlAzureExecutionStrategy.ExecuteNew(
                () =>
                {
                    using (new TransactionScope())
                    {
                        using (var context = new GearsOfWarContext())
                        {
                            var snub = new StandardWeapon
                            {
                                Name = "Snub",
                                Specs = new WeaponSpecification
                                {
                                    AmmoPerClip = 12,
                                    ClipsCount = 11,
                                }
                            };

                            var sawedoff = new StandardWeapon
                            {
                                Name = "Sawed-Off Shotgun",
                                Specs = new WeaponSpecification
                                {
                                    AmmoPerClip = 1,
                                    ClipsCount = 6,
                                }
                            };

                            snub.SynergyWith = sawedoff;
                            sawedoff.SynergyWith = snub;

                            context.Weapons.Add(snub);

                            Assert.Throws<DbUpdateException>(() => context.SaveChanges())
                                .InnerException.ValidateMessage(typeof(DbContext).Assembly(), "Update_ConstraintCycle", null);
                        }
                    }
                });
        }
        public void Seed(GearsOfWarContext context)
        {
            var lancer = new StandardWeapon
            {
                Name = "Lancer",
                Specs = new WeaponSpecification
                {
                    AmmoPerClip = 60,
                    ClipsCount = 8,
                }
            };

            var gnasher = new StandardWeapon
            {
                Name = "Gnasher",
                Specs = new WeaponSpecification
                {
                    AmmoPerClip = 8,
                    ClipsCount = 6,
                },

                SynergyWith = lancer,
            };

            var hammerburst = new StandardWeapon
            {
                Name = "Hammerburst",
                Specs = new WeaponSpecification
                {
                    AmmoPerClip = 20,
                    ClipsCount = 7,
                }
            };

            var markza = new StandardWeapon
            {
                Name = "Markza",
                Specs = new WeaponSpecification
                {
                    AmmoPerClip = 10,
                    ClipsCount = 12,
                },

                SynergyWith = gnasher,
            };

            var mulcher = new HeavyWeapon
            {
                Name = "Mulcher",
                Overheats = true,
            };

            context.Weapons.AddRange(new List<Weapon> { lancer, gnasher, hammerburst, markza, mulcher, });

            var deltaSquad = new Squad
            {
                Id = 1,
                Name = "Delta",
            };

            var kiloSquad = new Squad
            {
                Id = 2,
                Name = "Kilo",
            };

            context.Squads.AddRange(new[] { deltaSquad, kiloSquad });

            var jacinto = new City
            {
                Location = DbGeography.FromText("POINT(1 1)", DbGeography.DefaultCoordinateSystemId),
                Name = "Jacinto",
            };

            var ephyra = new City
            {
                Location = DbGeography.FromText("POINT(2 2)", DbGeography.DefaultCoordinateSystemId),
                Name = "Ephyra",
            };

            var hanover = new City
            {
                Location = DbGeography.FromText("POINT(3 3)", DbGeography.DefaultCoordinateSystemId),
                Name = "Hanover",
            };

            context.Cities.AddRange(new[] { jacinto, ephyra, hanover });

            var marcusTag = new CogTag
            {
                Id = Guid.NewGuid(),
                Note = "Marcus's Tag",
            };

            var domsTag = new CogTag
            {
                Id = Guid.NewGuid(),
                Note = "Dom's Tag",
            };

            var colesTag = new CogTag
            {
                Id = Guid.NewGuid(),
                Note = "Cole's Tag",
            };

            var bairdsTag = new CogTag
            {
                Id = Guid.NewGuid(),
                Note = "Bairds's Tag",
            };

            var paduksTag = new CogTag
            {
                Id = Guid.NewGuid(),
                Note = "Paduk's Tag",
            };

            var kiaTag = new CogTag
            {
                Id = Guid.NewGuid(),
                Note = "K.I.A.",
            };

            context.Tags.AddRange(
                new[] { marcusTag, domsTag, colesTag, bairdsTag, paduksTag, kiaTag });

            var marcus = new Gear
            {
                Nickname = "Marcus",
                FullName = "Marcus Fenix",
                Squad = deltaSquad,
                Rank = MilitaryRank.Sergeant,
                Tag = marcusTag,
                CityOfBirth = jacinto,
                Weapons = new List<Weapon> { lancer, gnasher },
            };

            var dom = new Gear
            {
                Nickname = "Dom",
                FullName = "Dominic Santiago",
                Squad = deltaSquad,
                Rank = MilitaryRank.Corporal,
                Tag = domsTag,
                CityOfBirth = ephyra,
                Weapons = new List<Weapon> { hammerburst, gnasher }
            };

            var cole = new Gear
            {
                Nickname = "Cole Train",
                FullName = "Augustus Cole",
                Squad = deltaSquad,
                Rank = MilitaryRank.Private,
                Tag = colesTag,
                CityOfBirth = hanover,
                Weapons = new List<Weapon> { gnasher, mulcher }
            };

            var baird = new Gear
            {
                Nickname = "Baird",
                FullName = "Damon Baird",
                Squad = deltaSquad,
                Rank = MilitaryRank.Corporal,
                Tag = bairdsTag,
                Weapons = new List<Weapon> { lancer, gnasher }
            };

            var paduk = new Gear
            {
                Nickname = "Paduk",
                FullName = "Garron Paduk",
                Squad = kiloSquad,
                Rank = MilitaryRank.Private,
                Tag = paduksTag,
                Weapons = new List<Weapon> { markza },
            };

            marcus.Reports = new List<Gear> { dom, cole, baird };
            baird.Reports = new List<Gear> { paduk };

            context.Gears.AddRange(new[] { marcus, dom, cole, baird, paduk });
            context.SaveChanges();
        }