예제 #1
0
        public void WhenPriceAlreadyApproved_ShouldThrowException()
        {
            var product = ProductFactory.Create();
            var command = new ApproveProductPrice();

            Assert.That(() => product.ApprovePrice(command), Throws.TypeOf <PriceAlreadyApproved>());
        }
예제 #2
0
        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);
        }
예제 #3
0
        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>());
        }
예제 #5
0
        public async Task <IActionResult> ConfirmPrice([FromRoute] ApproveProductPrice request)
        {
            var result = await _whenApproveProductPrice.Handle(request);

            return(Ok(result));
        }