示例#1
0
        public void addStoreTest()
        {
            Store s1 = new Store("store", "store");
            int   ID = DBStore.getInstance().addStore(s1);

            Assert.AreNotEqual(DBStore.getInstance().getStore(ID), null);
        }
示例#2
0
        public void closeStoreTest()
        {
            int ID = DBStore.getInstance().addStore(s);

            DBStore.getInstance().closeStore(s);
            Assert.IsFalse(s.isActive());
        }
示例#3
0
        public void addToCartTest1()
        {
            Product p1 = new Product("p1", "ff", 56, 2, 10, DBStore.getInstance().getStore(store1));

            basket.addToCart(p1, 5);
            Assert.AreEqual(basket.getShoppingCarts().Keys.Count, 1);
        }
示例#4
0
        public void addManager(int storeid, string username,
                               bool editProduct, bool editDiscount, bool editPolicy, Session session)
        {
            SubscribedUser toAdd = DBSubscribedUser.getInstance().getSubscribedUser(username);

            if (toAdd == null)
            {
                throw new DoesntExistException("no such username");
            }
            Store store = DBStore.getInstance().getStore(storeid);

            if (store == null)
            {
                throw new DoesntExistException("no such store");
            }
            StoreRole sr = store.getStoreRole(session.getSubscribedUser());

            if (sr.getStore() != store)
            {
                throw new RoleException("this user can't appoint to this store");
            }
            Permissions permissions = new Permissions(editProduct, editDiscount, editPolicy);

            sr.addManager(toAdd, permissions);
        }
示例#5
0
 public void TestInitialize()
 {
     DBStore.getInstance().DBinit();
     s  = new Store("store", "store");
     su = new SubscribedUser("u", "u", new ShoppingBasket());
     sr = new StoreOwner(null, su, s);
 }
示例#6
0
 public void TestInitialize()
 {
     storeService = StoreService.getInstance();
     userService  = UserService.getInstance();
     DBStore.getInstance().init();
     DBSubscribedUser.getInstance().cleanDB();
 }
示例#7
0
        public void removeStoreTest()
        {
            int ID = DBStore.getInstance().addStore(s);

            Assert.AreEqual(DBStore.getInstance().removeStore(s), "");
            Assert.AreEqual(DBStore.getInstance().getStore(ID), null);
            Assert.AreNotEqual(DBStore.getInstance().removeStore(s), "");
        }
示例#8
0
 public void TestInitialize()
 {
     MarketSystem.initTestWitOutRead();
     s = new Store("store", "store");
     DBStore.getInstance().addStore(s);
     su = new SubscribedUser("u", "u", new ShoppingBasket());
     sr = new StoreOwner(null, su, s);
 }
示例#9
0
 public void Initialize()
 {
     userService  = UserService.getInstance();
     storeService = StoreService.getInstance();
     session      = userService.startSession();
     DBStore.getInstance().init();
     DBSubscribedUser.getInstance().cleanDB();
 }
示例#10
0
        public int addProduct(string productName, string productCategory, int price, int rank, int quantityLeft, int storeID, Session session)
        {
            DBStore   storeDB = DBStore.getInstance();
            Store     store   = storeDB.getStore(storeID);
            StoreRole sr      = store.getStoreRole(session.getSubscribedUser());
            Product   product = new Product(productName, productCategory, price, rank, quantityLeft, store);

            sr.addProduct(product);
            return(product.getProductID());
        }
示例#11
0
 public void initial()
 {
     MarketSystem.initTestWitOutRead();
     //DBProduct.getInstance().initTests();
     //DBProduct.getInstance().initTests();
     //DBStore.getInstance().initTests();
     store = new Store("store1", "games store");
     DBStore.getInstance().addStore(store);
     cart = new ShoppingCart(store.getStoreID());
 }
示例#12
0
        public void closeStore(int storeid, Session session)
        {
            Store store = DBStore.getInstance().getStore(storeid);

            if (store == null)
            {
                throw new DoesntExistException("no such store");
            }
            session.closeStore(store);
        }
示例#13
0
        public TotalPricePolicy(int totalPrice)
        {
            if (totalPrice < 0)
            {
                throw new ILLArgumentException("total price can not be a negative number.");
            }

            this.totalPrice = totalPrice;

            this.policyID = DBStore.getInstance().getNextPolicyID();
        }
示例#14
0
        public void createStoreTest()
        {
            Session session = new Session();

            session.register("yael", "yael");
            session.login("yael", "yael");
            Store store = session.getState().createStore("Wallmart", "sells everything", session.getSubscribedUser());

            Assert.IsTrue(store != null);
            DBStore.getInstance().cleanDB();
        }
示例#15
0
        public void decFromProductQuantity(int productid, int amount, Session session)
        {
            Product product = DBProduct.getInstance().getProductByID(productid);

            if (product == null)
            {
                throw new DoesntExistException("no such username");
            }

            SubscribedUser user = session.getSubscribedUser();

            StoreRole sr = DBStore.getInstance().getStoreRole(product.getStore(), user);

            sr.decFromProductQuantity(product, amount);
        }
示例#16
0
        public void removeProduct(int productid, Session session)
        {
            Product product = DBProduct.getInstance().getProductByID(productid);

            if (product == null)
            {
                throw new DoesntExistException("no such username");
            }

            SubscribedUser user = session.getSubscribedUser();

            StoreRole sr = DBStore.getInstance().getStoreRole(product.getStore(), user);

            sr.removeProduct(product);
        }
示例#17
0
        public void setProductDiscount(int productid, int discount, Session session)
        {
            Product product = DBProduct.getInstance().getProductByID(productid);

            if (product == null)
            {
                throw new DoesntExistException("no such username");
            }

            SubscribedUser user = session.getSubscribedUser();

            DBStore   storeDB = DBStore.getInstance();
            StoreRole sr      = storeDB.getStoreRole(product.getStore(), user);

            //??????????????????????????????/
            //sr.setProductDiscount(product, discount);
        }
示例#18
0
 public ComplexPurchasePolicy(string type, PurchasePolicy p1, PurchasePolicy p2)
 {
     if (type == "xor")
     {
         this.type = Type.xor;
     }
     else if (type == "or")
     {
         this.type = Type.or;
     }
     else
     {
         this.type = Type.and;
     }
     this.p1       = p1;
     this.p2       = p2;
     this.policyID = DBStore.getInstance().getNextPolicyID();
 }
示例#19
0
        public void addOwner(int storeid, string username, Session session)
        {
            SubscribedUser toAdd = DBSubscribedUser.getInstance().getSubscribedUser(username);

            if (toAdd == null)
            {
                throw new DoesntExistException("no such username");
            }
            Store store = DBStore.getInstance().getStore(storeid);

            if (store == null)
            {
                throw new DoesntExistException("no such store");
            }
            StoreRole sr = store.getStoreRole(session.getSubscribedUser());

            if (sr.getStore() != store)
            {
                throw new RoleException("this user can't appoint to this store");
            }
            sr.addOwner(toAdd);
        }
示例#20
0
        public void removeRole(int storeid, string username, Session session)
        {
            SubscribedUser toRemove = DBSubscribedUser.getInstance().getSubscribedUser(username);

            if (toRemove == null)
            {
                throw new DoesntExistException("no such username");
            }
            Store store = DBStore.getInstance().getStore(storeid);

            if (store == null)
            {
                throw new DoesntExistException("no such store");
            }
            StoreRole sr = store.getStoreRole(session.getSubscribedUser());

            if (sr.getStore() != store)
            {
                throw new RoleException("this user can't remove roles from this store");
            }
            sr.remove(toRemove);
        }
示例#21
0
 public void addStoreRoleTest()
 {
     DBStore.getInstance().addStoreRole(sr);
     Assert.AreEqual(DBStore.getInstance().getStoreRole(s, su), sr);
 }
示例#22
0
 public void removeStoreRoleTest()
 {
     DBStore.getInstance().addStoreRole(sr);
     DBStore.getInstance().removeStoreRole(sr);
     Assert.AreEqual(DBStore.getInstance().getStoreRole(s, su), null);
 }