예제 #1
0
        public void Insert_update_delete_entity_with_spatial_property()
        {
            using (var context = new GearsOfWarContext())
            {
                var GeographySrid = 4326;
                var halvoBay = new City
                {
                    Name = "Halvo Bay",
                    Location = DbGeography.FromText("POINT(10 10)", GeographySrid),
                };

                context.Cities.Add(halvoBay);
                context.SaveChanges();
                Assert.True(context.Cities.Where(c => c.Name == "Halvo Bay").Any());

                halvoBay.Location = DbGeography.FromText("POINT(20 20)", GeographySrid);
                context.SaveChanges();
                var halvoBaysNewLocation = context.Cities.Where(g => g.Name == "Halvo Bay").Select(g => g.Location).Single();
                Assert.True(halvoBaysNewLocation.SpatialEquals(DbGeography.FromText("POINT(20 20)", GeographySrid)));

                context.Cities.Remove(halvoBay);
                context.SaveChanges();
                Assert.False(context.Cities.Where(g => g.Name == "Halvo Bay").Any());
            }
        }
        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();
        }