public void TestDeleteWithQueryFilterOk() { //SETUP var options = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options)) { context.Database.EnsureCreated(); var author = new SoftDelEntity { SoftDeleted = true }; context.Add(author); context.SaveChanges(); } using (var context = new TestDbContext(options)) { var utData = context.SetupEntitiesDirect(); var service = new CrudServices(context, utData.ConfigAndMapper); context.SoftDelEntities.Count().ShouldEqual(0); context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(1); //ATTEMPT service.DeleteAndSave <SoftDelEntity>(1); //VERIFY service.IsValid.ShouldBeFalse(); service.GetAllErrors().ShouldEqual("Sorry, I could not find the Soft Del Entity you wanted to delete."); } using (var context = new TestDbContext(options)) { context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(1); } }
public void TestProjectFromEntityToDtoIgnoreQueryFiltersOk() { //SETUP var options = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options)) { context.Database.EnsureCreated(); var author = new SoftDelEntity { SoftDeleted = true }; context.Add(author); context.SaveChanges(); } using (var context = new TestDbContext(options)) { var utData = context.SetupSingleDtoAndEntities <SoftDelEntityDto>(); var service = new CrudServices(context, utData.ConfigAndMapper, new CreateNewDBContextHelper(() => new TestDbContext(options))); context.SoftDelEntities.Count().ShouldEqual(0); context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(1); //ATTEMPT var dto = service.ProjectFromEntityToDto <SoftDelEntity, SoftDelEntityDto>(x => x.IgnoreQueryFilters().Where(y => y.Id == 1)).Single(); //VERIFY service.IsValid.ShouldBeTrue(service.GetAllErrors()); dto.Id.ShouldEqual(1); } }
public async Task TestDeleteWithActionAsyncWithQueryFilterOk() { //SETUP var options = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options)) { context.Database.EnsureCreated(); var author = new SoftDelEntity { SoftDeleted = true }; context.Add(author); context.SaveChanges(); context.ChangeTracker.Clear(); var utData = context.SetupEntitiesDirect(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); context.SoftDelEntities.Count().ShouldEqual(0); context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(1); //ATTEMPT await service.DeleteWithActionAndSaveAsync <SoftDelEntity>(DelHandlerAsync, 1); //VERIFY service.IsValid.ShouldBeTrue(service.GetAllErrors()); service.Message.ShouldEqual("Successfully deleted a Soft Del Entity"); context.ChangeTracker.Clear(); context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(0); } }
public async Task TestDeleteWithActionAsyncWithQueryFilterError() { //SETUP var options = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options)) { context.Database.EnsureCreated(); var author = new SoftDelEntity { SoftDeleted = false }; context.Add(author); context.SaveChanges(); } using (var context = new TestDbContext(options)) { var utData = context.SetupEntitiesDirect(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); context.SoftDelEntities.Count().ShouldEqual(1); context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(1); //ATTEMPT await service.DeleteWithActionAndSaveAsync <SoftDelEntity>(DelHandlerAsync, 1); //VERIFY service.IsValid.ShouldBeFalse(); service.GetAllErrors().ShouldEqual("Can't delete if not already soft deleted."); } using (var context = new TestDbContext(options)) { context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(1); } }
private Task <IStatusGeneric> DelHandlerAsync(DbContext context, SoftDelEntity entity) { var status = new StatusGenericHandler(); if (!entity.SoftDeleted) { status.AddError("Can't delete if not already soft deleted."); } return(Task.FromResult((IStatusGeneric)status)); }
public async Task TestDeleteWithActionAsyncWithQueryFilterOk() { async Task <IStatusGeneric> DelHandlerAsync(DbContext context, SoftDelEntity entity) { var status = new StatusGenericHandler(); if (!entity.SoftDeleted) { status.AddError("Can't delete if not already soft deleted."); } return(status); } //SETUP var options = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options)) { context.Database.EnsureCreated(); var author = new SoftDelEntity { SoftDeleted = true }; context.Add(author); context.SaveChanges(); } using (var context = new TestDbContext(options)) { var utData = context.SetupEntitiesDirect(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); context.SoftDelEntities.Count().ShouldEqual(0); context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(1); //ATTEMPT await service.DeleteWithActionAndSaveAsync <SoftDelEntity>(DelHandlerAsync, 1); //VERIFY service.IsValid.ShouldBeTrue(service.GetAllErrors()); service.Message.ShouldEqual("Successfully deleted a Soft Del Entity"); } using (var context = new TestDbContext(options)) { context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(0); } }
public void TestDeleteWithActionWithQueryFilterError() { //SETUP var options = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options)) { context.Database.EnsureCreated(); var author = new SoftDelEntity { SoftDeleted = false }; context.Add(author); context.SaveChanges(); } using (var context = new TestDbContext(options)) { var utData = context.SetupEntitiesDirect(); var service = new CrudServices(context, utData.ConfigAndMapper); context.SoftDelEntities.Count().ShouldEqual(1); context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(1); //ATTEMPT service.DeleteWithActionAndSave <SoftDelEntity>((dbContext, entity) => { var status = new StatusGenericHandler(); if (!entity.SoftDeleted) { status.AddError("Can't delete if not already soft deleted."); } return(status); }, 1); //VERIFY service.IsValid.ShouldBeFalse(); service.GetAllErrors().ShouldEqual("Can't delete if not already soft deleted."); } using (var context = new TestDbContext(options)) { context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(1); } }