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 Test41DeleteWithRelationshipsViaDtoBad() { using (var db = new SampleWebAppDb()) { //SETUP var service = new DeleteService(db); //ATTEMPT var ex = Assert.Throws <InvalidOperationException>(() => service.DeleteWithRelationships <SimplePostDto>(DeleteBloggerWithPost, 0)); //VERIFY ex.Message.ShouldEqual("The entity type SimplePostDto is not part of the model for the current context."); } }
public void Check11DeleteWithRelationshipsDirectOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostUntracked = db.Posts.AsNoTracking().First(); var service = new DeleteService(db); //ATTEMPT var status = service.DeleteWithRelationships <Post>(DeleteBloggerWithPost, firstPostUntracked.PostId); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); status.SuccessMessage.ShouldEqual("Successfully deleted Post and given relationships."); snap.CheckSnapShot(db, -1, -2, -1, 0, -2); } }
public void Test11DeleteLineItemCheckHeaderOk() { using (var db = new AdventureWorksLt2012()) { //SETUP AddLineItem(db, 10); var newOrder = AddLineItem(db, 5); var service = new DeleteService(db); //ATTEMPT var status = service.DeleteWithRelationships <SalesOrderDetail>(DeleteLineItemHelper.UpdateSalesOrderHeader, newOrder.SalesOrderID, newOrder.SalesOrderDetailID); //VERIFY status.ShouldBeValid(); db.SalesOrderDetails.Any(x => x.SalesOrderDetailID == newOrder.SalesOrderDetailID).ShouldEqual(false); CheckTotals(db); } }
public void Check15DeleteWithRelationshipsDirectFailOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostUntracked = db.Posts.AsNoTracking().First(); var service = new DeleteService(db); //ATTEMPT var status = service.DeleteWithRelationships <Post>(FailDeleteRelationships, firstPostUntracked.PostId); //VERIFY status.IsValid.ShouldEqual(false); status.Errors.Count.ShouldEqual(1); status.Errors[0].ErrorMessage.ShouldEqual("I failed."); 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); } }
public void Test11DeleteLineItemCheckHeaderOk() { using (var db = new AdventureWorksLt2012()) { //SETUP AddLineItem(db, 10); var newOrder = AddLineItem(db, 5); var service = new DeleteService(db); //ATTEMPT var status = service.DeleteWithRelationships<SalesOrderDetail>(DeleteLineItemHelper.UpdateSalesOrderHeader, newOrder.SalesOrderID, newOrder.SalesOrderDetailID); //VERIFY status.ShouldBeValid(); db.SalesOrderDetails.Any( x => x.SalesOrderDetailID == newOrder.SalesOrderDetailID).ShouldEqual(false); CheckTotals(db); } }
public void Test41DeleteWithRelationshipsViaDtoBad() { using (var db = new SampleWebAppDb()) { //SETUP var service = new DeleteService(db); //ATTEMPT var ex = Assert.Throws<InvalidOperationException>(() => service.DeleteWithRelationships<SimplePostDto>(DeleteBloggerWithPost, 0)); //VERIFY ex.Message.ShouldEqual("The entity type SimplePostDto is not part of the model for the current context."); } }
public void Test43DeleteWithRelationshipsDirectFailOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostUntracked = db.Posts.AsNoTracking().First(); var service = new DeleteService(db); //ATTEMPT var status = service.DeleteWithRelationships<Post>(FailDeleteRelationships, firstPostUntracked.PostId); //VERIFY status.IsValid.ShouldEqual(false); status.Errors.Count.ShouldEqual(1); status.Errors[0].ErrorMessage.ShouldEqual("I failed."); snap.CheckSnapShot(db); } }
public void Test41DeleteWithRelationshipsDirectOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostUntracked = db.Posts.AsNoTracking().First(); var service = new DeleteService(db); //ATTEMPT var status = service.DeleteWithRelationships<Post>(DeleteBloggerWithPost, firstPostUntracked.PostId); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); status.SuccessMessage.ShouldEqual("Successfully deleted Post and given relationships."); snap.CheckSnapShot(db, -1, -2, -1, 0, -2); } }
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); } }
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); } }