public void ShouldThrowExceptionOnNonexistingProduct()
        {
            var nonExistingProductID = Guid.NewGuid();
            var exception            = new ProductNotFoundException();

            repoMock.Setup(x => x.GetByID(nonExistingProductID)).Throws(exception);

            handler.Invoking(async x =>
                             await x.Handle(new SetPriceCommand {
                ProductID = nonExistingProductID, ProductPrice = new SetPriceCommand.Price {
                    Amount = 1m, Currency = "euro"
                }
            }, CancellationToken.None))
            .Should()
            .Throw <SetPriceException>()
            .Where(x => (Guid)x.Data["ProductID"] == nonExistingProductID)
            .WithInnerException <ProductNotFoundException>();
        }
Example #2
0
        public void ShouldThrowExceptionWhenAddingNonexistingItem()
        {
            Cart savedCart = null;
            var  cartID    = Guid.NewGuid();
            var  pID       = Guid.NewGuid();

            cartRepo.Setup(x => x.GetByID(cartID)).Returns(new Cart(cartID));
            cartRepo.Setup(x => x.Save(It.IsAny <Cart>())).Callback <Cart>(x => savedCart = x);

            var exception = new ProductNotFoundException();

            productRepo.Setup(x => x.GetByID(pID)).Throws(exception);

            handler.Invoking(async x => await x.Handle(new AddItemToCartCommand {
                CartID = cartID, ProductID = pID
            }, CancellationToken.None))
            .Should()
            .Throw <AddItemToCartException>()
            .Where(x => (Guid)x.Data["ProductID"] == pID && (Guid)x.Data["CartID"] == cartID)
            .WithInnerException <ProductNotFoundException>();
        }