public void TestConcurrencyLessThenMaxAmount()
        {
            var i1 = 0;
            var i2 = 0;

            var prod = new Product("TestProd1", new decimal(10), "TestDescription", "Oste", "TestPath");
            var s    = new Shop("TestShop1", "TestAddress", "12345678", "OpeningTime", new DbChain().GetChain(1), new List <Warehouse>());

            //add product to database
            int prodId = new DbProduct().AddProduct(prod);

            prod.Id = prodId;
            //add shop to database
            var shopId = new DbShop().AddShop(s);

            s.Id = shopId;

            //add warehouse to databse and add it to shop
            var warehouse = new Warehouse(10, 0, prod, s, null);
            var warId     = new DbWarehouse().AddWarehouse(warehouse);

            warehouse.Id = warId;
            s.Warehouses.Add(warehouse);

            //make cart1 with part order
            var cart1 = new Cart();
            var po1   = new PartOrder(prod, 5, 20);

            cart1.PartOrders.Add(po1);
            cart1.PersonId = _cust.Id;
            cart1.ShopId   = s.Id;

            //make cart2 with part order
            var cart2 = new Cart();
            var po2   = new PartOrder(prod, 2, 20);

            cart2.PartOrders.Add(po2);
            cart2.PersonId = _cust1.Id;
            cart2.ShopId   = s.Id;

            //start 2 parallel queries
            var cartDb = new DbCart();

            Parallel.Invoke(() => { i1 = cartDb.AddCartWithPartOrders(cart1); }, () => { i2 = cartDb.AddCartWithPartOrders(cart2); });
            //var antal = new DbWarehouse().GetWarehouse(warId).Stock;
            var flag = 0;

            if (i1 == 0 || i2 == 0)
            {
                flag = 1;
            }
            Assert.AreEqual(1, flag);
        }
Example #2
0
        public void AddCartWithDb()
        {
            var cartDb = new DbCart();
            var cart   = new Cart
            {
                PersonId   = 1,
                ShopId     = 1,
                TotalPrice = new decimal(5)
            };
            var id = cartDb.AddCart(cart);

            Assert.AreNotEqual(0, id);
        }
Example #3
0
        public Cart ComposeCart(int cartid, string username)
        {
            List <DbPurchaseBasket>            dbBskets = DbManager.Instance.GetCartBaskets(cartid);
            Dictionary <Store, PurchaseBasket> baskets  = new Dictionary <Store, PurchaseBasket>();

            foreach (DbPurchaseBasket dbPurBasket in dbBskets)
            {
                Store store = StoreManagment.Instance.getStore(dbPurBasket.StoreId);
                baskets.Add(store, ComposeBasket(dbPurBasket, store));
            }
            DbCart dbCart = DbManager.Instance.GetDbCart(cartid);

            return(new Cart(cartid, username, dbCart.Price, baskets, dbCart.IsPurchased));
        }
Example #4
0
        public void GetAllCartsWithDb()
        {
            var cartDb = new DbCart();

            Assert.AreNotEqual(0, cartDb.GetAllCarts().Count);
        }