public void Insert(IShoppingItemEntity entity, Action <long> success, Action <Exception> error)
        {
            ReactiveFunction(() =>
            {
                var shoppingItem = new ShoppingItem
                {
                    Id         = entity.Id,
                    Discount   = entity.Discount,
                    Favorite   = false,
                    Quantity   = entity.Quantity,
                    ShoppingId = entity.ShoppingId
                };

                simpleDb.SetShoppingItem(entity.ShoppingId, shoppingItem);

                return(shoppingItem.Id);
            }, success, error);
        }
Esempio n. 2
0
        public void IncQuantity_ShouldIncreaseAndStoreTheQuantity()
        {
            var entityFactory           = new EntityFactory();
            IProductAggregation product = entityFactory.NewProduct(productId, productDetailDb[6], productPromotionDb[2], categoryMock.Object, 0, 0, false);

            product.IncQuantity(
                shoppingQueryRepositoryMock.Object,
                shoppingQueryRepositorySpecificationFactoryMock.Object,
                shoppingItemRepositoryMock.Object,
                shoppingItemByIdRepositorySpecificationFactoryMock.Object,
                success =>
            {
            }, err =>
            {
            });

            Assert.AreEqual(1, product.Quantity);
            shoppingItemRepositoryMock
            .Verify(x => x.Insert(It.IsAny <IShoppingItemEntity>(), It.IsAny <Action <long> >(), It.IsAny <Action <Exception> >()), Times.Once());

            product = entityFactory.NewProduct(productId, productDetailDb[6], productPromotionDb[2], categoryMock.Object, 0, productQuantity, false);
            IShoppingItemEntity updatedItem = null;

            // *******************************************************
            updateShoppingItemCallback = (item) => updatedItem = item;

            product.IncQuantity(
                shoppingQueryRepositoryMock.Object,
                shoppingQueryRepositorySpecificationFactoryMock.Object,
                shoppingItemRepositoryWithItemMock.Object,
                shoppingItemByIdRepositorySpecificationFactoryMock.Object,
                success =>
            {
            }, err =>
            {
            });

            Assert.IsNotNull(updatedItem);
            Assert.IsTrue(updatedItem.Quantity > productQuantity);
        }
        public void Update(IShoppingItemEntity entity, IByIdRepositorySpecification <IShoppingItemEntity, long> spec, Action <IShoppingItemEntity> success, Action <Exception> error)
        {
            if (spec is ShoppingItemUpdateByIdRepositorySpecification)
            {
                ReactiveFunction(() =>
                {
                    var shoppingId = (spec as ShoppingItemUpdateByIdRepositorySpecification).ShoppingId;
                    var itemId     = (spec as ShoppingItemUpdateByIdRepositorySpecification).Id;

                    return(ProcessByIdRequest(shoppingId, itemId, (shopping, shoppingItem, product, productDetailValue, promotionValue) =>
                    {
                        shoppingItem.Quantity = entity.Quantity;
                        shoppingItem.Discount = entity.Discount;

                        simpleDb.SetShoppingItem(shoppingId, shoppingItem);
                    }));
                }
                                 , success, error);
            }
            else
            {
                throw new ArgumentException();
            }
        }