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); } }
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); } }
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 Saving_null_compex_type_property_throws() { ExtendedSqlAzureExecutionStrategy.ExecuteNew( () => { using (new TransactionScope()) { 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"); } } }); }