public async Task InsertGiftVoucher_InovokeExpectedMethods()
        {
            await _service.InsertGiftVoucher(new GiftVoucher()
            {
                Code = "code"
            });

            _repositoryMock.Verify(c => c.InsertAsync(It.IsAny <GiftVoucher>()), Times.Once);
            _mediatorMock.Verify(c => c.Publish(It.IsAny <EntityInserted <GiftVoucher> >(), default(CancellationToken)), Times.Once);
        }
        public virtual async Task <GiftVoucher> InsertGiftVoucherModel(GiftVoucherModel model)
        {
            var giftVoucher = model.ToEntity(_dateTimeService);

            giftVoucher.CreatedOnUtc = DateTime.UtcNow;
            await _giftVoucherService.InsertGiftVoucher(giftVoucher);

            //activity log
            await _customerActivityService.InsertActivity("AddNewGiftVoucher", giftVoucher.Id, _translationService.GetResource("ActivityLog.AddNewGiftVoucher"), giftVoucher.Code);

            return(giftVoucher);
        }
        public async Task <bool> Handle(InsertOrderItemCommand request, CancellationToken cancellationToken)
        {
            if (request.Order == null)
            {
                throw new ArgumentNullException(nameof(request.Order));
            }

            if (request.OrderItem == null)
            {
                throw new ArgumentNullException(nameof(request.OrderItem));
            }

            request.Order.OrderItems.Add(request.OrderItem);
            request.Order.OrderSubtotalExclTax += request.OrderItem.PriceExclTax;
            request.Order.OrderSubtotalInclTax += request.OrderItem.PriceInclTax;
            request.Order.OrderTax             += (request.OrderItem.PriceInclTax - request.OrderItem.PriceExclTax);
            request.Order.OrderTotal           += request.OrderItem.PriceInclTax;

            if (request.Order.ShippingStatusId == ShippingStatus.Delivered &&
                request.OrderItem.IsShipEnabled)
            {
                request.Order.ShippingStatusId = ShippingStatus.PartiallyShipped;
            }

            if (request.Order.ShippingStatusId == ShippingStatus.ShippingNotRequired &&
                request.OrderItem.IsShipEnabled)
            {
                request.Order.ShippingStatusId = ShippingStatus.Pending;
            }

            //TODO
            //request.Order.OrderTaxes

            await _orderService.UpdateOrder(request.Order);

            //adjust inventory
            await _inventoryManageService.AdjustReserved(request.Product, -request.OrderItem.Quantity, request.OrderItem.Attributes, request.OrderItem.WarehouseId);

            //check order status
            await _mediator.Send(new CheckOrderStatusCommand()
            {
                Order = request.Order
            });

            //add a note
            await _orderService.InsertOrderNote(new OrderNote
            {
                Note = "A new order item has been added",
                DisplayToCustomer = false,
                CreatedOnUtc      = DateTime.UtcNow,
                OrderId           = request.Order.Id,
            });

            //gift vouchers
            if (request.Product.IsGiftVoucher)
            {
                for (int i = 0; i < request.OrderItem.Quantity; i++)
                {
                    var gc = new GiftVoucher
                    {
                        GiftVoucherTypeId      = request.Product.GiftVoucherTypeId,
                        PurchasedWithOrderItem = request.OrderItem,
                        Amount                 = request.OrderItem.UnitPriceExclTax,
                        CurrencyCode           = request.Order.CustomerCurrencyCode,
                        IsGiftVoucherActivated = false,
                        Code = _giftVoucherService.GenerateGiftVoucherCode(),

                        //TODO
                        //RecipientName = recipientName,
                        //RecipientEmail = recipientEmail,
                        //SenderName = senderName,
                        //SenderEmail = senderEmail,
                        //Message = giftVoucherMessage,
                        IsRecipientNotified = false,
                        CreatedOnUtc        = DateTime.UtcNow
                    };
                    await _giftVoucherService.InsertGiftVoucher(gc);
                }
            }
            return(true);
        }