public void TestSoftDeleteServiceSetSoftDeleteViaKeysOk() { //SETUP var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>(); using (var context = new SingleSoftDelDbContext(options)) { context.Database.EnsureCreated(); var book = context.AddBookWithReviewToDb(); var config = new ConfigSoftDeleteWithUserId(context); var service = new SingleSoftDeleteService <ISingleSoftDelete>(context, config); //ATTEMPT var status = service.SetSoftDeleteViaKeys <Book>(book.Id); //VERIFY status.IsValid.ShouldBeTrue(status.GetAllErrors()); status.Result.ShouldEqual(1); } using (var context = new SingleSoftDelDbContext(options)) { context.Books.Count().ShouldEqual(0); context.Books.IgnoreQueryFilters().Count().ShouldEqual(1); } }
public void TestSoftDeleteServiceSetSoftDddDeleteViaKeysOk() { //SETUP var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>(); using (var context = new SingleSoftDelDbContext(options)) { context.Database.EnsureCreated(); var bookDdd = new BookDDD("Test"); context.Add(bookDdd); context.SaveChanges(); var config = new ConfigSoftDeleteDDD(); var service = new SingleSoftDeleteService <ISingleSoftDeletedDDD>(context, config); //ATTEMPT var status = service.SetSoftDeleteViaKeys <BookDDD>(bookDdd.Id); //VERIFY status.IsValid.ShouldBeTrue(status.GetAllErrors()); status.Result.ShouldEqual(1); } using (var context = new SingleSoftDelDbContext(options)) { context.BookDdds.Count().ShouldEqual(0); context.BookDdds.IgnoreQueryFilters().Count().ShouldEqual(1); } }
public void TestSoftDeleteOrderWithAddressOk() { //SETUP var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>(); using var context = new SingleSoftDelDbContext(options); context.Database.EnsureCreated(); context.Add(new Order { OrderRef = "123", UserAddress = new Address { FullAddress = "xxx" } }); context.SaveChanges(); context.ChangeTracker.Clear(); var config = new ConfigSoftDeleteWithUserId(context); var service = new SingleSoftDeleteService <ISingleSoftDelete>(config); //ATTEMPT var status = service.SetSoftDeleteViaKeys <Order>(1); //VERIFY status.IsValid.ShouldBeTrue(status.GetAllErrors()); context.Orders.Count().ShouldEqual(0); context.Addresses.Count().ShouldEqual(1); }
public void TestSetSoftDeleteOk() { //SETUP var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>(); using var context = new SingleSoftDelDbContext(options); context.Database.EnsureCreated(); var shadowClass = new ShadowDelClass(); context.Add(shadowClass); context.SaveChanges(); context.ChangeTracker.Clear(); var config = new ConfigSoftDeleteShadowDel(context); var service = new SingleSoftDeleteService <IShadowSoftDelete>(config); //ATTEMPT var status = service.SetSoftDeleteViaKeys <ShadowDelClass>(shadowClass.Id); //VERIFY status.IsValid.ShouldBeTrue(status.GetAllErrors()); status.Result.ShouldEqual(1); context.ShadowDelClasses.Count().ShouldEqual(0); context.ShadowDelClasses.IgnoreQueryFilters().Count().ShouldEqual(1); }
public void TestSoftDeleteServiceSetSoftDeleteViaKeysBadNumberOfKeys() { //SETUP var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>(); using (var context = new SingleSoftDelDbContext(options)) { context.Database.EnsureCreated(); var book = context.AddBookWithReviewToDb(); var config = new ConfigSoftDeleteWithUserId(context); var service = new SingleSoftDeleteService <ISingleSoftDelete>(context, config); //ATTEMPT var ex = Assert.Throws <ArgumentException>(() => service.SetSoftDeleteViaKeys <Book>(1, 2)); //VERIFY ex.Message.ShouldEqual("Mismatch in keys: your provided 2 key(s) and the entity has 1 key(s) (Parameter 'keyValues')"); } }
public void TestSoftDeleteServiceSetSoftDeleteViaKeysBadKeyType() { //SETUP var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>(); using (var context = new SingleSoftDelDbContext(options)) { context.Database.EnsureCreated(); var book = context.AddBookWithReviewToDb(); var config = new ConfigSoftDeleteWithUserId(context); var service = new SingleSoftDeleteService <ISingleSoftDelete>(context, config); //ATTEMPT var ex = Assert.Throws <ArgumentException>(() => service.SetSoftDeleteViaKeys <Book>(book)); //VERIFY ex.Message.ShouldEqual("Mismatch in keys: your provided key 1 (of 1) is of type Book but entity key's type is System.Int32 (Parameter 'keyValues')"); } }
public void TestSoftDeleteServiceSetSoftDeleteOneToOneBad() { //SETUP var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>(); using (var context = new SingleSoftDelDbContext(options)) { context.Database.EnsureCreated(); context.AddBookWithReviewToDb(); var config = new ConfigSoftDeleteWithUserId(context); var service = new SingleSoftDeleteService <ISingleSoftDelete>(config); //ATTEMPT var ex = Assert.Throws <InvalidOperationException>(() => service.SetSoftDeleteViaKeys <OneToOne>(1)); //VERIFY ex.Message.ShouldEqual("You cannot soft delete a one-to-one relationship. It causes problems if you try to create a new version."); } }
public void TestSoftDeleteServiceSetSoftDeleteViaKeysNotFoundBad() { //SETUP var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>(); using (var context = new SingleSoftDelDbContext(options)) { context.Database.EnsureCreated(); var config = new ConfigSoftDeleteWithUserId(context); var service = new SingleSoftDeleteService <ISingleSoftDelete>(context, config); //ATTEMPT var status = service.SetSoftDeleteViaKeys <Book>(123); //VERIFY status.IsValid.ShouldBeFalse(); status.GetAllErrors().ShouldEqual("Could not find the entry you ask for."); status.Result.ShouldEqual(0); } }
public void TestSoftDeleteServiceSetSoftDeleteViaKeysNotFoundReturnsZero() { //SETUP var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>(); using (var context = new SingleSoftDelDbContext(options)) { context.Database.EnsureCreated(); var config = new ConfigSoftDeleteWithUserId(context) { NotFoundIsNotAnError = true }; var service = new SingleSoftDeleteService <ISingleSoftDelete>(context, config); //ATTEMPT var status = service.SetSoftDeleteViaKeys <Book>(123); //VERIFY status.IsValid.ShouldBeTrue(status.GetAllErrors()); status.Result.ShouldEqual(0); } }