public void TestHardDeleteCascadeDeleteCompanySomeQuotesDifferentUserIdOk() { //SETUP var userId = Guid.NewGuid(); var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>(); using (var context = new CascadeSoftDelDbContext(options, userId)) { context.Database.EnsureCreated(); var customer = Customer.SeedCustomerWithQuotes(context, userId); Customer.SeedCustomerWithQuotes(context, Guid.Empty, "Other customer"); context.SaveChanges(); var config = new ConfigCascadeDeleteWithUserId(context); var service = new CascadeSoftDelService <ICascadeSoftDelete>(config); service.SetCascadeSoftDelete(customer).Result.ShouldEqual(1 + 4 + 4 + (4 * 4)); //ATTEMPT var status = service.HardDeleteSoftDeletedEntries(customer); //VERIFY status.IsValid.ShouldBeTrue(status.GetAllErrors()); status.Result.ShouldEqual(1 + 4 + 4 + (4 * 4)); status.Message.ShouldEqual("You have hard deleted an entity and its 24 dependents"); context.Quotes.Count().ShouldEqual(0); context.Quotes.IgnoreQueryFilters().Count().ShouldEqual(4); } }
public void TestHardDeleteCascadeSoftOfPreviousDeleteInfo() { //SETUP var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>(); using (var context = new CascadeSoftDelDbContext(options)) { context.Database.EnsureCreated(); var ceo = Employee.SeedEmployeeSoftDel(context); var config = new ConfigCascadeDeleteWithUserId(context); var service = new CascadeSoftDelService <ICascadeSoftDelete>(config); var numSoftDeleted = service.SetCascadeSoftDelete(context.Employees.Single(x => x.Name == "CTO")).Result; numSoftDeleted.ShouldEqual(7 + 6); Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false); //ATTEMPT var status = service.HardDeleteSoftDeletedEntries(context.Employees.IgnoreQueryFilters().Single(x => x.Name == "CTO")); //VERIFY status.IsValid.ShouldBeTrue(status.GetAllErrors()); status.Result.ShouldEqual(7 + 6); status.Message.ShouldEqual("You have hard deleted an entity and its 12 dependents"); context.Employees.IgnoreQueryFilters().Count().ShouldEqual(4); } }
public void TestHardDeleteCascadeSoftDeleteNoSoftDeleteInfo() { //SETUP var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>(); using (var context = new CascadeSoftDelDbContext(options)) { context.Database.EnsureCreated(); var ceo = Employee.SeedEmployeeSoftDel(context); var config = new ConfigCascadeDeleteWithUserId(context); var service = new CascadeSoftDelService <ICascadeSoftDelete>(config); //ATTEMPT var status = service.HardDeleteSoftDeletedEntries(context.Employees.IgnoreQueryFilters().Single(x => x.Name == "ProjectManager1")); //VERIFY status.IsValid.ShouldBeFalse(); status.Result.ShouldEqual(0); status.GetAllErrors().ShouldEqual("This entry isn't soft deleted."); } }