public void TestUpdatePublicationDateViaAutoMapperOk() { //SETUP var options = SqliteInMemory.CreateOptions <EfCoreContext>(); using (var context = new EfCoreContext(options)) { context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); var utData = context.SetupSingleDtoAndEntities <Tests.Dtos.ChangePubDateDto>(); var service = new CrudServices(context, utData.Wrapped); //ATTEMPT var dto = new Tests.Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000, 1, 1) }; service.UpdateAndSave(dto, CrudValues.UseAutoMapper); //VERIFY service.IsValid.ShouldBeTrue(service.GetAllErrors()); service.Message.ShouldEqual("Successfully updated the Book"); var entity = context.Books.Find(4); entity.PublishedOn.ShouldEqual(new DateTime(2000, 1, 1)); } }
public async Task TestUpdateViaStatedMethodOk() { //SETUP var options = SqliteInMemory.CreateOptions <EfCoreContext>(); using (var context = new EfCoreContext(options)) { context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); var utData = context.SetupSingleDtoAndEntities <Tests.Dtos.ChangePubDateDto>(); var service = new CrudServicesAsync(context, utData.Wrapped); //ATTEMPT var dto = new Tests.Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000, 1, 1) }; await service.UpdateAndSaveAsync(dto, nameof(Book.RemovePromotion)); //VERIFY service.IsValid.ShouldBeTrue(service.GetAllErrors()); service.Message.ShouldEqual("Successfully updated the Book"); var entity = context.Books.Find(4); entity.ActualPrice.ShouldEqual(220); } }
public void TestBuildCallChangePubDateDto() { //SETUP var prop = new PropertyMatch(true, PropertyMatch.TypeMatchLevels.Match, typeof(Tests.Dtos.ChangePubDateDto).GetProperty(nameof(Tests.Dtos.ChangePubDateDto.PublishedOn))); var method = typeof(Book).GetMethod(nameof(Book.UpdatePublishedOn)); var dto = new Tests.Dtos.ChangePubDateDto { PublishedOn = new DateTime(2000,1,1)}; var target = DddEfTestData.CreateDummyBooks(1).Single(); //ATTEMPT var action = BuildCall.CallMethodReturnVoid(method, typeof(Tests.Dtos.ChangePubDateDto), typeof(Book), new List<PropertyMatch>{prop}); action.Invoke(dto, target); //VERIFY target.PublishedOn.ShouldEqual(new DateTime(2000, 1, 1)); }
public void RunGenericServicePropertyUpdate() { //SETUP using (var context = new EfCoreContext(_options)) { var service = new CrudServices<EfCoreContext>(context, _utData.ConfigAndMapper, new CreateNewDBContextHelper(() => new EfCoreContext(_options))); //ATTEMPT var newDate = new DateTime(2000, 1, 1).AddDays(_incdDay++); var dto = new Tests.Dtos.ChangePubDateDto { BookId = 4, PublishedOn = newDate }; service.UpdateAndSave(dto, CrudValues.UseAutoMapper); //VERIFY service.IsValid.ShouldBeTrue(service.GetAllErrors()); var entity = context.Books.Find(4); entity.PublishedOn.ShouldEqual(newDate); } }
public void RunGenericServiceMethodAccess() { //SETUP using (var context = new EfCoreContext(_options)) { var service = new CrudServices <EfCoreContext>(context, _utData.Wrapped); //ATTEMPT var newDate = new DateTime(2000, 1, 1).AddDays(_incdDay++); var dto = new Tests.Dtos.ChangePubDateDto { BookId = 4, PublishedOn = newDate }; service.UpdateAndSave(dto, nameof(Book.UpdatePublishedOn)); //VERIFY service.IsValid.ShouldBeTrue(service.GetAllErrors()); var entity = context.Books.Find(4); entity.PublishedOn.ShouldEqual(newDate); } }
public void TestUpdateViaStatedMethodBad() { //SETUP var options = SqliteInMemory.CreateOptions <EfCoreContext>(); using (var context = new EfCoreContext(options)) { context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); var utData = context.SetupSingleDtoAndEntities <Tests.Dtos.ChangePubDateDto>(); var service = new CrudServices(context, utData.Wrapped); //ATTEMPT var dto = new Tests.Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000, 1, 1) }; var ex = Assert.Throws <InvalidOperationException>(() => service.UpdateAndSave(dto, nameof(Book.AddReview))); //VERIFY ex.Message.ShouldStartWith("Could not find a method of name AddReview. The method that fit the properties in the DTO/VM are:"); } }