Ejemplo n.º 1
0
        public void init()
        {
            CleanDB cDB = new CleanDB();

            cDB.emptyDB();
            ProductManager.restartInstance();
            SalesManager.restartInstance();
            StoreManagement.restartInstance();
            UserManager.restartInstance();
            UserCartsManager.restartInstance();
            BuyHistoryManager.restartInstance();
            CouponsManager.restartInstance();
            DiscountsManager.restartInstance();
            RaffleSalesManager.restartInstance();
            StorePremissionsArchive.restartInstance();
            us   = userServices.getInstance();
            ss   = storeServices.getInstance();
            zahi = us.startSession();
            us.register(zahi, "zahi", "123456");
            us.login(zahi, "zahi", "123456");
            int storeid = ss.createStore("abowim", zahi);

            store = StoreManagement.getInstance().getStore(storeid);
            int c = ss.addProductInStore("cola", 3.2, 10, zahi, storeid, "Drinks");

            cola = ProductManager.getInstance().getProductInStore(c);
        }
        public void SimpleAddStoreManager()
        {
            User aviad = us.startSession();

            us.register(aviad, "aviad", "123456");
            us.login(aviad, "aviad", "123456");

            int   storeid = ss.createStore("abowim", zahi);
            Store store   = StoreManagement.getInstance().getStore(storeid);
            LinkedList <StoreManager> managers = store.getManagers();

            Assert.AreEqual(managers.Count, 0);

            ss.addStoreManager(store.getStoreId(), "aviad", zahi);
            managers = store.getManagers();
            Assert.AreEqual(managers.Count, 1);
            StoreManager SM = managers.First.Value;

            Assert.AreEqual(SM.getUser().getUserName(), aviad.getUserName());
            Assert.AreEqual(SM.getStore(), store);

            Premissions SP = SM.getPremissions(aviad, store);
            Dictionary <string, Boolean> Dict = SP.getPrivileges();

            foreach (KeyValuePair <string, Boolean> entry in Dict)
            {
                Assert.IsFalse(entry.Value);
            }
        }
Ejemplo n.º 3
0
        public void simpleViewUserHistory()
        {
            User aviad = us.startSession();

            Assert.IsNotNull(aviad);
            int   storeId = ss.createStore("abowim", zahi);
            Store store   = StoreManagement.getInstance().getStore(storeId);

            Assert.IsNotNull(store);
            Assert.IsTrue(us.register(aviad, "aviad", "123456") > -1);
            Assert.IsTrue(us.login(aviad, "aviad", "123456") > -1);
            int            pisId = ss.addProductInStore("cola", 3.2, 10, zahi, store.getStoreId(), "Drink");
            ProductInStore pis   = ProductManager.getInstance().getProductInStore(pisId);

            Assert.IsNotNull(pis);
            int saleId = ss.addSaleToStore(zahi, store.getStoreId(), pis.getProductInStoreId(), 1, 8, DateTime.Now.AddDays(10).ToString());
            LinkedList <Sale> sales = ses.viewSalesByProductInStoreId(pis.getProductInStoreId());

            Assert.IsTrue(sales.Count == 1);
            Sale sale = sales.First.Value;

            Assert.IsTrue(ses.addProductToCart(aviad, sale.SaleId, 2) > -1);
            LinkedList <UserCart> sc = ses.viewCart(aviad);

            Assert.IsTrue(sc.Count == 1);
            Assert.IsTrue(sc.First.Value.getSaleId() == saleId);
            Assert.IsTrue(ses.buyProducts(aviad, "1234", ""));
            LinkedList <Purchase> historyList = ss.viewUserHistory(admin, "aviad");

            Assert.IsTrue(historyList.Count == 1);
            Assert.IsTrue(historyList.First.Value.ProductId == pis.getProduct().getProductId());
            Assert.IsTrue(historyList.First.Value.Amount == 2);
        }
Ejemplo n.º 4
0
        public void init()
        {
            WebServices.DAL.CleanDB cDB = new WebServices.DAL.CleanDB();
            cDB.emptyDB();
            ProductManager.restartInstance();
            SalesManager.restartInstance();
            StoreManagement.restartInstance();
            UserManager.restartInstance();
            UserCartsManager.restartInstance();
            BuyHistoryManager.restartInstance();
            CouponsManager.restartInstance();
            DiscountsManager.restartInstance();
            RaffleSalesManager.restartInstance();
            StorePremissionsArchive.restartInstance();
            admin = new User("admin", "123456");
            admin.register("admin", "123456");
            admin.login("admin", "123456");

            admin1 = new User("admin1", "123456");
            admin1.register("admin1", "123456");

            zahi = new User("zahi", "123456");
            zahi.register("zahi", "123456");

            itamar = new User("itamar", "123456");
            itamar.register("itamar", "123456");
            itamar.login("itamar", "123456");
            int storeId = itamar.createStore("Maria&Netta Inc.");

            store = StoreManagement.getInstance().getStore(storeId);
            niv   = new User("niv", "123456");
            niv.register("niv", "123456");
        }
Ejemplo n.º 5
0
        public void createStoreAndOwnerMannegerNotOwner()
        {
            User aviad = new User("aviad", "123456");

            aviad.register("aviad", "123456");
            User zahi = new User("zahi", "123456");

            zahi.register("zahi", "123456");
            User niv = new User("niv", "123456");

            niv.register("niv", "123456");
            aviad.login("aviad", "123456");
            zahi.login("zahi", "123456");
            int   storeId = aviad.createStore("bro burger");
            Store s       = StoreManagement.getInstance().getStore(storeId);

            Assert.AreEqual(s.getStoreName(), "bro burger");
            Assert.AreEqual(s.getOwners().Count, 1);
            StoreRole sr = new StoreOwner(aviad, s);

            sr.addStoreOwner(zahi, s, "niv");
            Assert.AreEqual(s.getOwners().Count, 2);
            sr.addStoreManager(zahi, s, "niv");
            Assert.AreEqual(s.getManagers().Count, 0);
        }
Ejemplo n.º 6
0
        public void createStoreAndOwnerMannegerFromeManegerWioutPremition()
        {
            User aviad = new User("aviad", "123456");

            aviad.register("aviad", "123456");
            User zahi = new User("zahi", "123456");

            zahi.register("zahi", "123456");
            User niv = new User("niv", "123456");

            niv.register("niv", "123456");
            aviad.login("aviad", "123456");
            int   storeId = aviad.createStore("bro burger");
            Store s       = StoreManagement.getInstance().getStore(storeId);

            Assert.AreEqual(s.getStoreName(), "bro burger");
            Assert.AreEqual(s.getOwners().Count, 1);
            StoreRole sr = new StoreOwner(aviad, s);

            sr.addStoreManager(aviad, s, "niv");
            Assert.AreEqual(s.getManagers().Count, 1);
            sr.addManagerPermission(aviad, "removeStoreManager", s, "niv");
            niv.login("niv", "123456");
            sr.addStoreManager(niv, s, "zahi");
            Assert.AreEqual(s.getManagers().Count, 2);
        }
Ejemplo n.º 7
0
 public void init()
 {
     WebServices.DAL.CleanDB cDB = new WebServices.DAL.CleanDB();
     cDB.emptyDB();
     StoreManagement.restartInstance();
     sa = StoreManagement.getInstance();
 }
Ejemplo n.º 8
0
        public void AddSaleWithOwnerOfAnotherStore()
        {
            int            storeid = ss.createStore("admin store", admin);
            Store          store2  = StoreManagement.getInstance().getStore(storeid);
            int            m       = ss.addProductInStore("milk", 3.2, 10, admin, storeid, "Drinks");
            ProductInStore milk    = ProductManager.getInstance().getProductInStore(m);

            Assert.AreEqual(ss.addSaleToStore(admin, store.getStoreId(), milk.getProductInStoreId(), 1, 1, DateTime.Now.AddMonths(1).ToString()), -4);//-4 if don't have premition
        }
Ejemplo n.º 9
0
        public void AddSaleWithProductNotInStore()
        {
            int            storeid = ss.createStore("admin store", admin);
            Store          store2  = StoreManagement.getInstance().getStore(storeid);
            int            m       = ss.addProductInStore("milk", 3.2, 10, admin, storeid, "Drinks");
            ProductInStore milk    = ProductManager.getInstance().getProductInStore(m);

            Assert.AreEqual(ss.addSaleToStore(itamar, store.getStoreId(), milk.getProductInStoreId(), 1, 1, DateTime.Now.AddMonths(1).ToString()), -13); //-13 product not in this store
        }
Ejemplo n.º 10
0
        //req 3.7 and 5.4 a
        public LinkedList <Purchase> viewStoreHistory(User session, int storeId)
        {
            Store store = StoreManagement.getInstance().getStore(storeId);

            if (session == null | store == null)
            {
                return(null);
            }
            return(session.viewStoreHistory(store));
        }
Ejemplo n.º 11
0
        public LinkedList <StoreManager> getManagers(int storeId)
        {
            Store s = StoreManagement.getInstance().getStore(storeId);

            if (s == null)
            {
                return(null);
            }
            return(s.getManagers());
        }
Ejemplo n.º 12
0
        public void AddStoreManagerWhoIsNull()
        {
            int   storeid = ss.createStore("abowim", zahi);
            Store store   = StoreManagement.getInstance().getStore(storeid);

            ss.addStoreManager(store.getStoreId(), null, zahi);
            LinkedList <StoreManager> managers = store.getManagers();

            Assert.AreEqual(managers.Count, 0);
        }
        public void AddProductWithNegativeAmount()
        {
            int            storeid = ss.createStore("abowim", zahi);
            Store          s       = StoreManagement.getInstance().getStore(storeid);
            int            p       = ss.addProductInStore("cola", 3.2, -31, zahi, storeid, "Drinks");
            ProductInStore pis     = ProductManager.getInstance().getProductInStore(p);

            Assert.IsNull(pis);
            Assert.AreEqual(s.getProductsInStore().Count, 0);
        }
Ejemplo n.º 14
0
        public void OwnerTryAddHimselfToBeStoreManager()
        {
            int   storeid = ss.createStore("abowim", zahi);
            Store store   = StoreManagement.getInstance().getStore(storeid);

            ss.addStoreManager(store.getStoreId(), "zahi", zahi);
            LinkedList <StoreManager> managers = store.getManagers();

            Assert.AreEqual(managers.Count, 0);
        }
Ejemplo n.º 15
0
        public LinkedList <Sale> viewSalesByStore(int storeId)
        {
            Store s = StoreManagement.getInstance().getStore(storeId);

            if (s == null)
            {
                return(null);
            }
            return(s.getAllSales());
        }
Ejemplo n.º 16
0
        //req 1.3 a
        public LinkedList <ProductInStore> viewProductsInStore(int storeId)
        {
            Store s = StoreManagement.getInstance().getStore(storeId);

            if (s == null)
            {
                return(null);
            }
            return(s.getProductsInStore());
        }
Ejemplo n.º 17
0
        //req 3.4 a

        /*
         * return:
         *           0 on sucess
         *          -1 if user Not Login
         *          -2 if new manager name not exist
         *          -3 if illegal store id
         *          -4 if don't have premition
         *          -5 database eror
         *          -6 already owner or manneger
         */
        public int addStoreManager(int sId, String newManager, User session)
        {
            Store     s  = StoreManagement.getInstance().getStore(sId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-4);//-4 if don't have premition
            }
            return(sR.addStoreManager(session, s, newManager));
        }
Ejemplo n.º 18
0
        //req 3.4 c

        /*
         *       return:
         *           0 on sucess
         *          -1 if user Not Login
         *          -2 if Store Name already exist
         *          -3 if illegal store id
         *          -4 if don't have premition
         *          -5 database eror
         *          -6 manager name doesn't exsist
         *          -7 no such premition
         *          -8 the mannager to add is not a manager in this store
         *          -10 can't remove himself
         */
        public int addManagerPermission(String permission, int storeId, String managerToAdd, User session)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-4); //-4 if don't have premition
            }
            return(sR.addManagerPermission(session, permission, s, managerToAdd));
        }
Ejemplo n.º 19
0
        //req 3.4 d
        public int removeManagerPermission(String permission, int storeId, String manager, User session)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-4); //-4 if you do not have permissions
            }
            return(sR.removeManagerPermission(session, permission, s, manager));
        }
Ejemplo n.º 20
0
        /*
         *        return:
         *           0  on sucess the SaleID
         *          -1 if user Not Login
         *          -4 if don't have premition
         *          -6 if illegal store id
         *          -8 if illegal sale id
         *          -9 database eror
         */
        public int removeSaleFromStore(User session, int storeId, int saleId)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-4);
            }
            return(sR.removeSaleFromStore(session, s, saleId));
        }
Ejemplo n.º 21
0
        /*
         * return:
         *           0  on sucess the SaleID
         *          -1 if user Not Login
         *          -4 if don't have premition
         *          -5 if illegal amount bigger then amount in stock
         *          -6 if illegal store id
         *          -7 if illegal price
         *          -8 if illegal sale id
         *          -9 database eror
         *          -10 due date not good
         *          -12 if illegal amount
         */
        public int editSale(User session, int storeId, int saleId, int amount, String dueDate)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-4);//-4 if don't have premition
            }
            return(sR.editSale(session, s, saleId, amount, dueDate));
        }
Ejemplo n.º 22
0
        public int removeNoCouponPolicyOnCountry(User session, int storeId, string country)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.removeNoCouponPolicyOnCountry(session, storeId, country));
        }
Ejemplo n.º 23
0
        public int removeNoDiscountPolicyOnStore(User session, int storeId)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.removeNoDiscountPolicyOnStore(session, storeId));
        }
Ejemplo n.º 24
0
        public void AddSaleWithNullParameters()
        {
            int            storeid = ss.createStore("admin store", admin);
            Store          store2  = StoreManagement.getInstance().getStore(storeid);
            int            m       = ss.addProductInStore("milk", 3.2, 10, admin, storeid, "Drinks");
            ProductInStore milk    = ProductManager.getInstance().getProductInStore(m);

            Assert.AreEqual(-1, ss.addSaleToStore(null, store2.getStoreId(), milk.getProductInStoreId(), 1, 1, DateTime.Now.AddMonths(1).ToString())); //could be -1 also
            Assert.AreEqual(-1, ss.addSaleToStore(admin, -4, milk.getProductInStoreId(), 1, 1, DateTime.Now.AddMonths(1).ToString()));                 //-6 if illegal store id
            Assert.AreEqual(-10, ss.addSaleToStore(admin, store2.getStoreId(), milk.getProductInStoreId(), 1, 1, null));                               //-10 due date not good
        }
Ejemplo n.º 25
0
        public int setAmountPolicyOnCountry(User session, int storeId, string country, int minAmount, int maxAmount)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.setAmountPolicyOnCountry(session, storeId, country, minAmount, maxAmount));
        }
Ejemplo n.º 26
0
        public int setNoDiscountPolicyOnCountry(User session, int storeId, String country)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.setNoDiscountPolicyOnCategoty(session, storeId, country));
        }
Ejemplo n.º 27
0
        //req 3.3 b

        /*
         * return:
         *           0 on sucess
         *          -1 if user Not Login
         *          -2 if Store Name already exist
         *          -3 if illegal product name
         *          -4 if don't have premition
         *          -5 if illegal amount
         *          -6 if illegal store id
         *          -7 if illegal price
         *          -8 if illegal product in store Id
         *          -9 database eror
         *          -10 can't remove himself
         *          -11 not a owner
         *          -12 if dealet creator
         */
        public int removeStoreOwner(int sId, String oldOwner, User session)
        {
            Store     s  = StoreManagement.getInstance().getStore(sId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-4);
            }
            return(sR.removeStoreOwner(session, s, oldOwner));
        }
Ejemplo n.º 28
0
        public int setAmountPolicyOnProductInStore(User session, int storeId, int productInStoreId, int minAmount, int maxAmount)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.setAmountPolicyOnProductInStore(session, storeId, productInStoreId, minAmount, maxAmount));
        }
Ejemplo n.º 29
0
        public int setNoCouponsPolicyOnStore(User session, int storeId)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.setNoCouponsPolicyOnStore(session, storeId));
        }
Ejemplo n.º 30
0
        public int removeNoCouponPolicyOnProductInStore(User session, int storeId, int productInStoreId)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.removeNoCouponPolicyOnProductInStore(session, storeId, productInStoreId));
        }