public void Handle_GivenInvalidId_ThrowsException() { var command = new UpdateProductCommand { Id = 99, Title = "This item doesn't exist.", }; var sut = new UpdateProductCommand.UpdateProductCommandHandler(Context); Should.ThrowAsync <NotFoundException>(() => sut.Handle(command, CancellationToken.None)); }
public async Task Handle_GivenValidId_ShouldUpdatePersistedProduct() { var command = new UpdateProductCommand { Id = 1, Name = "Test", Price = 2, Category = Category.Vegetables, Description = "Test" }; await _handler.Handle(command, CancellationToken.None); var entity = await UnitOfWork.Products.GetByIdAsync(command.Id); entity.ShouldNotBeNull(); entity.Name.ShouldBe(command.Name); entity.Price.ShouldBe(command.Price); entity.Category.ShouldBe(command.Category); entity.Description.ShouldBe(command.Description); }
public async Task Handle_GivenValidId_ShouldUpdatePersistedProduct() { var command = new UpdateProductCommand { Id = 1, Title = "This thing is also done.", }; var handler = new UpdateProductCommand.UpdateProductCommandHandler(Context); await handler.Handle(command, CancellationToken.None); var entity = Context.Products.Find(command.Id); entity.ShouldNotBeNull(); entity.Title.ShouldBe(command.Title); }