public void WhenPriceAlreadyApproved_ShouldThrowException() { var product = ProductFactory.Create(); var command = new ApproveProductPrice(); Assert.That(() => product.ApprovePrice(command), Throws.TypeOf <PriceAlreadyApproved>()); }
public void WhenPriceNotApproved_ShouldApprove() { var product = ProductFactory.Create(price: 1000); var command = new ApproveProductPrice(); Assert.That(product.PriceApproved, Is.False); product.ApprovePrice(command); Assert.That(product.PriceApproved, Is.True); }
public void ApprovePrice(ApproveProductPrice command) { if (PriceApproved) { throw new PriceAlreadyApproved(); } PriceApproved = command.PriceApproved; LastUpdated = DateTime.UtcNow; Validate(); }
public void WithInvalidProductId_ThrowsNotFoundException() { var productRepositoryMock = new Mock <IProductsRepository>(); var mapperMock = new Mock <IMapper>(); productRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).ReturnsAsync(default(Product)); var service = new API.ApplicationServices.CommandHandlers.WhenApproveProductPrice(productRepositoryMock.Object, mapperMock.Object); var request = new ApproveProductPrice { Id = new Guid() }; Assert.That(async() => await service.Handle(request), Throws.TypeOf <NotFoundException>()); }
public async Task <IActionResult> ConfirmPrice([FromRoute] ApproveProductPrice request) { var result = await _whenApproveProductPrice.Handle(request); return(Ok(result)); }