public async Task TestUpdatePublicationDateViaAutoMapperOk() { //SETUP var options = SqliteInMemory.CreateOptions <EfCoreContext>(); using (var context = new EfCoreContext(options)) { context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); var utData = context.SetupSingleDtoAndEntities <Dtos.ChangePubDateDto>(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); //ATTEMPT var dto = new Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000, 1, 1) }; await service.UpdateAndSaveAsync(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 void TestBuildCallChangePubDateDto() { //SETUP var prop = new PropertyMatch(true, PropertyMatch.TypeMatchLevels.Match, typeof(Dtos.ChangePubDateDto).GetProperty(nameof(Dtos.ChangePubDateDto.PublishedOn))); var method = typeof(Book).GetMethod(nameof(Book.UpdatePublishedOn)); var dto = new Dtos.ChangePubDateDto { PublishedOn = new DateTime(2000, 1, 1) }; var target = DddEfTestData.CreateDummyBooks(1).Single(); //ATTEMPT var action = BuildCall.CallMethodReturnVoid(method, typeof(Dtos.ChangePubDateDto), typeof(Book), new List <PropertyMatch> { prop }); action.Invoke(dto, target); //VERIFY target.PublishedOn.ShouldEqual(new DateTime(2000, 1, 1)); }
public async Task TestUpdateViaStatedMethodBad() { //SETUP var options = SqliteInMemory.CreateOptions <EfCoreContext>(); using (var context = new EfCoreContext(options)) { context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); var utData = context.SetupSingleDtoAndEntities <Dtos.ChangePubDateDto>(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); //ATTEMPT var dto = new Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000, 1, 1) }; var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => service.UpdateAndSaveAsync(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:"); } }