public async Task TestHardDeleteCascadeDeleteCompanySomeQuotesDifferentUserIdOk() { //SETUP var userId = Guid.NewGuid(); var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>(); using (var context = new CascadeSoftDelDbContext(options, userId)) { context.Database.EnsureCreated(); var company = Customer.SeedCustomerWithQuotes(context, userId); Customer.SeedCustomerWithQuotes(context, Guid.Empty, "Other company"); context.SaveChanges(); var config = new ConfigCascadeDeleteWithUserId(context); var service = new CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config); (await service.SetCascadeSoftDeleteAsync(company)).Result.ShouldEqual(1 + 4 + 4 + (4 * 4)); //ATTEMPT var status = await service.HardDeleteSoftDeletedEntriesAsync(company); //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.ChangeTracker.Clear(); context.Quotes.Count().ShouldEqual(0); context.Quotes.IgnoreQueryFilters().Count().ShouldEqual(4); } }
public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config); var numSoftDeleted = (await service.SetCascadeSoftDeleteAsync(context.Employees.Single(x => x.Name == "CTO"))).Result; numSoftDeleted.ShouldEqual(7 + 6); Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false); //ATTEMPT var status = await service.HardDeleteSoftDeletedEntriesAsync(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.ChangeTracker.Clear(); context.Employees.IgnoreQueryFilters().Count().ShouldEqual(4); } }
public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config); //ATTEMPT var status = await service.HardDeleteSoftDeletedEntriesAsync(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."); } }