public void Test10AddressDeleteNotPossibleViaServiceOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var snap = new CustomerSnapShot(db); var service = new DeleteService(db); var addressUsedInTwoPlaces = db.Addresses.Include(x => x.CustomerAddresses) .AsNoTracking() .OrderByDescending(x => x.AddressID) .First(x => x.CustomerAddresses.Count > 0 && x.SalesOrderHeaders.Count > 0); //ATTEMPT var status = service.DeleteWithRelationships <CustomerAddress>(DeleteHelpers.DeleteAssociatedAddress, addressUsedInTwoPlaces.CustomerAddresses.First().CustomerID, addressUsedInTwoPlaces.AddressID); //VERIFY status.IsValid.ShouldEqual(false, status.Errors); status.Errors.Count.ShouldEqual(1); status.Errors.First().ErrorMessage.ShouldEqual("This operation failed because another data entry uses this entry."); snap.CheckSnapShot(db); } }
public void Test11AddressDeleteViaServiceOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var snap = new CustomerSnapShot(db); var service = new DeleteService(db); var addressUsedInTwoPlaces = db.Addresses.Include(x => x.CustomerAddresses) .AsNoTracking() .OrderByDescending(x => x.AddressID) .First(x => x.CustomerAddresses.Count == 1 && x.SalesOrderHeaders.Count == 0 && x.SalesOrderHeaders1.Count == 0); //ATTEMPT var status = service.DeleteWithRelationships <CustomerAddress>(DeleteHelpers.DeleteAssociatedAddress, addressUsedInTwoPlaces.CustomerAddresses.First().CustomerID, addressUsedInTwoPlaces.AddressID); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); snap.CheckSnapShot(db, 0, -1, -1); } }