public void Verify_that_order_of_insert_is_based_on_key_values_and_not_order_of_adding_to_collection() { ExtendedSqlAzureExecutionStrategy.ExecuteNew( () => { using (new TransactionScope()) { 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); } } }); }
public void Optimistic_concurrency_error_attempting_to_modify_previously_deleted_entity_when_using_timestamp() { using (var context = new GearsOfWarContext()) { using (var context2 = new GearsOfWarContext()) { var troika = new HeavyWeapon { Name = "Troika", Overheats = true, }; context.Weapons.Add(troika); context.SaveChanges(); var troika2 = context2.Weapons.OfType<HeavyWeapon>().Where(w => w.Name == "Troika").Single(); context.Weapons.Remove(troika); context.SaveChanges(); troika2.Overheats = false; Assert.Throws<DbUpdateConcurrencyException>(() => context2.SaveChanges()) .ValidateMessage(typeof(DbContext).Assembly(), "Update_ConcurrencyError", null); } } }
public void Inserting_entity_that_references_itself_in_one_to_one_relationship_throws() { using (var context = new GearsOfWarContext()) { var hammerOfDawn = new HeavyWeapon { Name = "Hammer of Dawn", Overheats = false, }; hammerOfDawn.SynergyWith = hammerOfDawn; context.Weapons.Add(hammerOfDawn); 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 }); }
public void Optimistic_concurrency_error_attempting_to_delete_previously_modified_entity_when_using_timestamp() { ExtendedSqlAzureExecutionStrategy.ExecuteNew( () => { using (new TransactionScope()) { using (var context = new GearsOfWarContext()) { using (var context2 = new GearsOfWarContext()) { var troika = new HeavyWeapon { Name = "Troika", Overheats = true, }; context.Weapons.Add(troika); context.SaveChanges(); var troika2 = context2.Weapons.Where(w => w.Name == "Troika").Single(); troika.Overheats = false; context.SaveChanges(); context2.Weapons.Remove(troika2); Assert.Throws<DbUpdateConcurrencyException>(() => context2.SaveChanges()) .ValidateMessage(typeof(DbContext).Assembly(), "Update_ConcurrencyError", 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(); }