Пример #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();
            ses  = sellServices.getInstance();
            zahi = us.startSession();
            us.register(zahi, "zahi", "123456");
            us.login(zahi, "zahi", "123456");
            admin = us.startSession();
            us.register(admin, "admin", "123456");
            us.login(admin, "admin", "123456");
        }
Пример #2
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);
        }
Пример #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);
        }
Пример #4
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);
        }
Пример #5
0
        public IHttpActionResult Get()
        {
            try
            {
                apiResp = new ApiResponse();
                var mng = new StoreManagement();
                apiResp.Data = mng.RetrieveAll();

                return(Ok(apiResp));
            }
            catch (BussinessException bex)
            {
                var MessageManage = new ApplicationMessageManagement();
                MessageManage.Create(bex.AppMessage);
                return(InternalServerError(new Exception(bex.ExceptionId + "-"
                                                         + bex.AppMessage.Message)));
            }
            catch (Exception ex)
            {
                ApplicationMessage msg = new ApplicationMessage
                {
                    Message = ex.Message
                };
                var MessageManage = new ApplicationMessageManagement();
                MessageManage.Create(msg);
                return(InternalServerError(new Exception(ex.Message)));
            }
        }
Пример #6
0
        public IHttpActionResult Post(Store store)
        {
            try
            {
                var mng = new StoreManagement();
                mng.Create(store);

                apiResp = new ApiResponse
                {
                    Message = "Action was executed."
                };

                return(Ok(apiResp));
            }
            catch (BussinessException bex)
            {
                var MessageManage = new ApplicationMessageManagement();
                MessageManage.Create(bex.AppMessage);
                return(InternalServerError(new Exception(bex.ExceptionId + "-"
                                                         + bex.AppMessage.Message)));
            }
            catch (Exception ex)
            {
                ApplicationMessage msg = new ApplicationMessage
                {
                    Message = ex.Message
                };
                var MessageManage = new ApplicationMessageManagement();
                MessageManage.Create(msg);
                return(InternalServerError(new Exception(ex.Message)));
            }
        }
Пример #7
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");
        }
Пример #8
0
        private static ShoppingCart ShoppingCartInit()
        {
            var StoreList = new Dictionary <int, Store>();

            StoreList.Add(1, new Store(1, "OO商店"));
            StoreList.Add(2, new Store(2, "XX商店"));
            var StoreManagement = new StoreManagement(StoreList);

            var productSampleList = new Dictionary <int, Product>();

            productSampleList.Add(1, new Product(1, "二手蘋果手機", 8700, 1));
            productSampleList.Add(2, new Product(2, "C# cookbook", 568, 1));
            productSampleList.Add(3, new Product(3, "HP 筆電\t", 16888, 1));
            productSampleList.Add(4, new Product(4, "哈利波特影集", 2250, 2));
            productSampleList.Add(5, new Product(5, "無間道三部曲", 1090, 2));
            var ProductManagement = new ProductManagement(productSampleList);
            var ShipmentList      = new Dictionary <int, Shipment>();

            ShipmentList.Add(1, new Shipment(1, "宅急便", 60));
            ShipmentList.Add(2, new Shipment(2, "郵局", 40));
            ShipmentList.Add(3, new Shipment(3, "超商店到店", 50));
            var shipmentManagement = new ShipmentManagement(ShipmentList);
            var shoppingCart       = new ShoppingCart(productSampleList, StoreList, ShipmentList, StoreManagement.GetStoreById, ProductManagement.GetProductById);

            return(shoppingCart);
        }
        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);
            }
        }
Пример #10
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);
        }
Пример #11
0
 public void init()
 {
     WebServices.DAL.CleanDB cDB = new WebServices.DAL.CleanDB();
     cDB.emptyDB();
     StoreManagement.restartInstance();
     sa = StoreManagement.getInstance();
 }
Пример #12
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
        }
Пример #13
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
        }
        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);
        }
Пример #15
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));
        }
Пример #16
0
        public LinkedList <Sale> viewSalesByStore(int storeId)
        {
            Store s = StoreManagement.getInstance().getStore(storeId);

            if (s == null)
            {
                return(null);
            }
            return(s.getAllSales());
        }
Пример #17
0
        public LinkedList <StoreManager> getManagers(int storeId)
        {
            Store s = StoreManagement.getInstance().getStore(storeId);

            if (s == null)
            {
                return(null);
            }
            return(s.getManagers());
        }
        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);
        }
        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);
        }
Пример #20
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());
        }
Пример #21
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
        }
Пример #22
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));
        }
Пример #23
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));
        }
Пример #24
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));
        }
Пример #25
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));
        }
Пример #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));
        }
Пример #27
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));
        }
Пример #28
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));
        }
Пример #29
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));
        }
Пример #30
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));
        }