Exemple #1
0
        public void TestUpdateGood()
        {
            var odmen      = new OdmenAction();
            var store      = new StoreAction();
            var goodUpdate = store.GetAllGoods().FirstOrDefault(s => s.name.Contains("name"));

            if (goodUpdate == null)
            {
                Assert.Pass("Нет тестового товара для изменения");
                return;
            }
            goodUpdate.name     = "name_Updated";
            goodUpdate.info     = "info_Updated";
            goodUpdate.imageUrl = "imageUrl_Updated";
            goodUpdate.discount = 78;
            goodUpdate.price    = 67889.23M;
            goodUpdate.groupId  = store.GetGroups().Last().id;
            goodUpdate.fullInfo = "fullInfo_Updated";
            odmen.ChangeGood(goodUpdate);
            var updated = store.GetAllGoods().FirstOrDefault(s => s.name == goodUpdate.name
                                                             //&& s.fullInfo == goodUpdate.fullInfo
                                                             && s.info == goodUpdate.info && s.imageUrl == goodUpdate.imageUrl &&
                                                             s.price == goodUpdate.price && s.discount == goodUpdate.discount);

            // TODO: Add your test code here
            Assert.IsNotNull(updated);
        }
        private CatalogModel GetCatalogModel(long?groupId)
        {
            var store = new StoreAction();

            if (groupId == null || groupId == 0)
            {
                var modelAll = new CatalogModel
                {
                    goods   = store.GetAllGoods().Select(s => new GoodViewModel(s)).ToList(),
                    groupId = 0,
                };
                modelAll.filter = _filterCatalog(modelAll);
                return(modelAll);
            }
            var allGroups = store.GetGroups();
            var groups    = new List <long>();

            if (!allGroups.Exists(s => s.id == groupId))
            {
                Response.Redirect(Url.Content("~/Error/_404"), true);
                return(null);
            }
            SetPratentGroupLinks(groupId.Value);
            GetChildGroups(groupId.Value, ref groups);
            var goods = store.GetAllGoods().Join(groups, good => good.groupId, group => group, (good, group) => new GoodViewModel(good)).ToList();
            var model = new CatalogModel
            {
                goods = goods
            };

            model.groupId = groupId.Value;
            model.filter  = _filterCatalog(model);
            return(model);
        }
        public ActionResult _partialGoods()
        {
            var store = new StoreAction();
            var model = new GoodsShortViewModel();

            model.goods = store.GetAllGoods().Select(s => new GoodsShortView {
                id = s.id, name = s.name, price = s.price, groupName = s.groupName
            }).ToList();
            return(PartialView(model));
        }
Exemple #4
0
        public void TestDeleteGood()
        {
            var odmen = new OdmenAction();
            var store = new StoreAction();
            var goods = store.GetAllGoods().Where(s => s.name.Contains("name"));

            if (!(goods?.Count() > 0))
            {
                Assert.Pass("Нет тестового товара для удаления");
                return;
            }
            foreach (var goodForDel in goods)
            {
                odmen.DeleteGood(goodForDel.id);
            }

            var deleted = store.GetAllGoods().FirstOrDefault(s => s.name.Contains("name"));

            // TODO: Add your test code here
            Assert.IsNull(deleted);
        }
Exemple #5
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);
        }
        public void GetGoodInfo()
        {
            var  storeAction = new StoreAction();
            var  rand        = new Random();
            Good fullGood    = null;
            var  goods       = storeAction.GetAllGoods();

            for (int i = 0; i < 10; i++)
            {
                var randomGood = goods.ElementAt(rand.Next(goods.Count()));
                fullGood = storeAction.GetGoodInfo(randomGood.id);
            }
            // TODO: Add your test code here
            Assert.IsTrue(fullGood != null);
        }
Exemple #7
0
        public void TestLeaveFeadback_IsNotNull()
        {
            var customer = new CustomerAction(8);
            var store    = new StoreAction();

            var feedback = new FeedBack
            {
                goodId  = store.GetAllGoods().First().id,
                mark    = 3,
                message = Guid.NewGuid().ToString()
            };

            customer.LeaveFeadback(feedback);
            var feeds       = store.GetFeedBack(feedback.goodId);
            var newFeedBack = feeds.FirstOrDefault(s => s.mark == feedback.mark && s.message == feedback.message && s.userId == feedback.userId);

            // TODO: Add your test code here
            Assert.IsNotNull(newFeedBack);
        }
Exemple #8
0
        private static void Updating()
        {
            var store = new StoreAction();
            var goods = store.GetAllGoods().Select(s => new GoodViewModel(s)).ToList();

            sales = goods.Where(s => s.discount > 0).OrderByDescending(s => s.discount).Take(4);

            newes = goods.OrderByDescending(s => s.id).Take(4);
            foreach (var item in newes)
            {
                item.isNew = true;
            }
            var popularsFromAll = store.PopularGoods()?.Take(4).ToList();

            populars = goods.Where(s => popularsFromAll?.Any(w => w.id == s.id) ?? false).ToList();

            foreach (var item in populars)
            {
                item.isBestseller = true;
            }
        }