示例#1
0
        public async Task PaymentIntegrity()
        {
            var invoice = await _invoicesRepository.ByShoppingCartID(1);

            AddPaymentDTO addPaymentDTO = new AddPaymentDTO()
            {
                InvoiceID     = invoice.InvoiceID,
                PaymentAmount = invoice.Total
            };

            PaymentDTO paymentDTO = await _paymentService.MakePayment(addPaymentDTO);

            Assert.IsTrue(paymentDTO.PaymentID > 0);
            Assert.AreNotEqual(DateTime.MinValue, paymentDTO.PaidAt);
            Assert.IsTrue(Convert.ToDouble(paymentDTO.PaymentAmount) == addPaymentDTO.PaymentAmount);
        }
示例#2
0
        public async Task <InvoiceDTO> ByUserID(int userID)
        {
            //получаем текущую корзину
            ShoppingCartDTO cartDTO = await _shoppingCartMsClient.GetShoppingCartByUserID(userID);

            //если она существует начинаем создание счета
            if (cartDTO != null && cartDTO.ShoppingCartID > 0 && cartDTO.Items.Count > 0)
            {
                Invoice invoiceFromDb = await _invoicesRepository.ByShoppingCartID(cartDTO.ShoppingCartID);

                if (invoiceFromDb != null)
                {
                    //если актуальная информация не сходится с информацией в бд то удаляем старый счет и создаем новый иначе возвращаем уже имеющийся счет
                    if (invoiceFromDb.Total != cartDTO.Total || invoiceFromDb.CountOfCommodities != cartDTO.Items.Count)
                    {
                        await _invoicesRepository.DeleteByID(invoiceFromDb.InvoiceID);

                        Invoice newInvoice       = CreateInvoiceFromCart(cartDTO);
                        Invoice newInvoiceFromDb = await _invoicesRepository.Add(newInvoice);

                        return(_mapper.Map <InvoiceDTO>(newInvoiceFromDb));
                    }
                    else
                    {
                        return(_mapper.Map <InvoiceDTO>(invoiceFromDb));
                    }
                    //если счета по айди корзины в базе нет то создаем новый
                }
                else
                {
                    Invoice newInvoice       = CreateInvoiceFromCart(cartDTO);
                    Invoice newInvoiceFromDb = await _invoicesRepository.Add(newInvoice);

                    return(_mapper.Map <InvoiceDTO>(newInvoiceFromDb));
                }
            }

            return(new InvoiceDTO());
        }
示例#3
0
        public async Task RewriteInvoice_IfCartInfoChanged()
        {
            Invoice invoice = await _invoicesRepository.ByShoppingCartID(1);

            var rand = new Random();

            var client = (ShoppingCartMsClientMock)_shoppingCartMsClient;

            client.ShoppingCartDTOs[0].Items.Add(new ShoppingCartItemDTO()
            {
                CommodityDetails   = "asdasd",
                ShoppingCartItemID = rand.Next(100),
                CommodityID        = rand.Next(100),
                CommodityPrice     = rand.Next(100),
                Quantity           = rand.Next(10)
            });

            InvoiceDTO invoiceDTO = await _invoicesService.ByUserID(1);

            //проверяем пересоздался ли счет
            Assert.AreNotEqual(invoice.InvoiceID, invoiceDTO.InvoiceID);
        }