コード例 #1
0
        public void TestConfirmPayForAll(long userId)
        {
            var customer = new CustomerAction(userId);
            var store    = new StoreAction();

            customer.ClearBasket();
            Assert.AreEqual(customer.GetBasket().Count(), 0);
            customer.AddBasket(GenerateBasketElement());
            customer.AddBasket(GenerateBasketElement());

            var fastPayModel = GenerateBasketElement(true);
            var fastPayId    = customer.AddBasket(fastPayModel).packId;
            var packId       = customer.AddBasket(GenerateBasketElement()).packId;
            var price        = store.GetAllGoods().First(s => s.id == fastPayModel.goodId).price;
            var total        = price * fastPayModel.count;
            var payModel     = new PayModel
            {
                packId            = fastPayId,
                countInBasket     = 1,
                payDate           = DateTime.Now,
                transactionNumber = Guid.NewGuid().ToString(),
                totalSumm         = total
            };

            customer.Pay(payModel);
            Assert.AreEqual(customer.GetOrders().Where(s => s.packId == fastPayId).Count(), 1);

            customer.AddBasket(GenerateBasketElement(true));
            customer.AddBasket(GenerateBasketElement());
            customer.AddBasket(GenerateBasketElement(true));
            Assert.AreEqual(customer.GetBasket().Count(), 4);
            Assert.IsTrue(customer.GetOrders().Count() > 0);

            var basket    = customer.GetBasket();
            var payModel2 = new PayModel
            {
                packId            = (long)basket.Select(s => s.packId).Distinct().Single(),
                countInBasket     = 4,
                payDate           = DateTime.Now,
                transactionNumber = Guid.NewGuid().ToString(),
                totalSumm         = basket.Sum(s => s.summTotal).Value
            };

            customer.Pay(payModel2);
            Assert.AreEqual(customer.GetOrders().Where(s => s.packId == packId).Count(), 4);

            customer.AddBasket(GenerateBasketElement());
            customer.AddBasket(GenerateBasketElement(true));
            Assert.IsTrue(customer.GetBasket().Count() == 1);
        }