Ejemplo n.º 1
0
        public void init()
        {
            storeDB.init();
            productDB.init();
            DBSubscribedUser.getInstance().cleanDB();
            session1 = new Session();
            session1.register("eyal", "123");

            session2 = new Session();
            session2.register("bar", "123");

            session3 = new Session();
            session3.register("etay", "123");

            session1.login("eyal", "123");
            session2.login("bar", "123");
            session3.login("etay", "123");

            store = session1.createStore("mystore", "a store");

            per  = new Permissions(true, true, true);
            per2 = new Permissions(false, false, false);

            sr = session1.getSubscribedUser().getStoreRole(store);
            sr.addManager(session2.getSubscribedUser(), per);
            sr.addManager(session3.getSubscribedUser(), per2);

            sr1 = session2.getSubscribedUser().getStoreRole(store);
            sr2 = session3.getSubscribedUser().getStoreRole(store);

            p  = new Product("product", "cat", 10, 0, 10, store);
            p1 = new Product("product1", "cat", 10, 0, 10, store);
        }
Ejemplo n.º 2
0
 public void TestInitialize()
 {
     storeService = StoreService.getInstance();
     userService  = UserService.getInstance();
     DBStore.getInstance().init();
     DBSubscribedUser.getInstance().cleanDB();
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public void Initialize()
 {
     userService  = UserService.getInstance();
     storeService = StoreService.getInstance();
     session      = userService.startSession();
     DBStore.getInstance().init();
     DBSubscribedUser.getInstance().cleanDB();
 }
Ejemplo n.º 5
0
        public void getSubscribedUserTest()
        {
            DBSubscribedUser db   = DBSubscribedUser.getInstance();
            string           pass = DomainBridge.getInstance().encryptPassword("etay123");
            Session          s    = new Session();

            s.register("etay11", pass);
            Assert.AreNotEqual(db.getSubscribedUser("etay11"), null);
        }
Ejemplo n.º 6
0
        public void getSubscribedUserTest()
        {
            DBSubscribedUser db = DBSubscribedUser.getInstance();
            Session          s  = new Session();

            s.register("etay", "etay");
            Assert.AreNotEqual(db.getSubscribedUser("etay"), null);
            db.cleanDB();
        }
Ejemplo n.º 7
0
        public void loginTest()
        {
            DBSubscribedUser db   = DBSubscribedUser.getInstance();
            Session          s    = new Session();
            string           pass = DomainBridge.getInstance().encryptPassword("etay123");

            s.register("etay", pass);
            s.login("etay", "etay123");
            Assert.AreEqual(db.getloggedInUser("etay"), s.getSubscribedUser());
        }
Ejemplo n.º 8
0
        public void logoutTest()
        {
            DBSubscribedUser dbsubscribedUser = DBSubscribedUser.getInstance();

            session.login("admin", "1234");
            UserState state = session.getState();

            Assert.IsTrue(state is Admin);
            Assert.IsTrue(Equals(state.logout(session.getSubscribedUser(), session), ""));
            Assert.IsTrue(session.getState() is Guest);
        }
Ejemplo n.º 9
0
        public void loginTest()
        {
            DBSubscribedUser db = DBSubscribedUser.getInstance();

            db.cleanDB();
            Session s = new Session();

            s.register("etay", "etay");
            s.login("etay", "etay");
            Assert.AreEqual(db.getloggedInUser("etay"), s.getSubscribedUser());
            db.cleanDB();
        }
Ejemplo n.º 10
0
        public void createStoreTest()
        {
            DBSubscribedUser db   = DBSubscribedUser.getInstance();
            Session          s    = new Session();
            string           pass = DomainBridge.getInstance().encryptPassword("yael");

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

            Assert.AreNotEqual(store, null);
        }
Ejemplo n.º 11
0
        public void registerTest()
        {
            DBSubscribedUser dbsubscribedUser = DBSubscribedUser.getInstance();
            SubscribedUser   sub3             = new SubscribedUser("Benny", "aaaa", new ShoppingBasket());

            dbsubscribedUser.register(sub3);

            Session   session = new Session();
            UserState state   = session.getState();

            Assert.IsTrue(Equals(state.register("Benny", "aaaa", session), "ERROR: username already exists"));
            Assert.IsTrue(Equals(state.register("Viva", "Diva", session), ""));
            Assert.IsTrue(state is Guest);
            dbsubscribedUser.cleanDB();
        }
Ejemplo n.º 12
0
        public void logoutTest()
        {
            DBSubscribedUser db = DBSubscribedUser.getInstance();

            db.cleanDB();
            Session s = new Session();

            s.register("etay", "etay");
            s.login("etay", "etay");
            if (db.getSubscribedUser("etay") == null)
            {
                Assert.Fail();
            }
            s.logout();
            Assert.AreEqual(null, db.getloggedInUser("etay"));
        }
Ejemplo n.º 13
0
 public void logoutTest()
 {
     try
     {
         DBSubscribedUser db   = DBSubscribedUser.getInstance();
         Session          s    = new Session();
         string           pass = DomainBridge.getInstance().encryptPassword("etay123");
         s.register("etay", pass);
         s.login("etay", "etay123");
         s.getState().logout(s.getSubscribedUser(), s);
         Assert.IsTrue(s.getState() is Guest);
     }
     catch (LoginException)
     {
         Assert.Fail();
     }
 }
Ejemplo n.º 14
0
        public void logoutTest()
        {
            DBSubscribedUser dbsubscribedUser = DBSubscribedUser.getInstance();
            SubscribedUser   sub2             = new SubscribedUser("Gal", "Gadot", new ShoppingBasket());

            dbsubscribedUser.register(sub2);

            Session   session = new Session();
            UserState state   = session.getState();

            state.login("Gal", "Gadot", session);
            SubscribedUser user = session.getSubscribedUser();

            session.getState().logout(user, session);
            Assert.IsTrue(session.getState() is Guest);
            Assert.IsNull(dbsubscribedUser.getloggedInUser("Gal"));
            dbsubscribedUser.cleanDB();
        }
Ejemplo n.º 15
0
        public void loginTest1()
        {
            DBSubscribedUser dbsubscribedUser = DBSubscribedUser.getInstance();
            SubscribedUser   sub1             = new SubscribedUser("Danny", dbsubscribedUser.encryptPassword("Shovevani"), new ShoppingBasket());

            dbsubscribedUser.register(sub1);

            Session   session = new Session();
            UserState state   = session.getState();

            try
            {
                state.login("bob", "dilan", session);
                Assert.Fail();
            } catch (LoginException)
            {
                Assert.IsTrue(true);
            }
        }
Ejemplo n.º 16
0
        public void registerTest1()
        {
            DBSubscribedUser dbsubscribedUser = DBSubscribedUser.getInstance();
            SubscribedUser   sub3             = new SubscribedUser("Benny", "aaaa", new ShoppingBasket());

            dbsubscribedUser.register(sub3);

            Session   session = new Session();
            UserState state   = session.getState();

            try
            {
                state.register("Benny", "aaaa", session);
                Assert.Fail();
            }
            catch (RegisterException)
            {
                Assert.IsTrue(state is Guest);
            }
        }
Ejemplo n.º 17
0
        public void loginTest()
        {
            DBSubscribedUser dbsubscribedUser = DBSubscribedUser.getInstance();
            SubscribedUser   sub1             = new SubscribedUser("Danny", dbsubscribedUser.encryptPassword("Shovevani"), new ShoppingBasket());

            dbsubscribedUser.register(sub1);

            Session   session = new Session();
            UserState state   = session.getState();

            Assert.IsTrue(Equals(state.login("bob", "dilan", session), "ERROR: username does not exist"));
            Assert.IsTrue(Equals(state.login("Danny", "Shovevani", session), ""));
            Assert.IsTrue(session.getState() is LoggedIn);

            Session   session2 = new Session();
            UserState state2   = session2.getState();

            Assert.IsTrue(Equals(state.login("Danny", "aaaa", session2), "ERROR: password incorrect"));
            dbsubscribedUser.cleanDB();
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 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);
        }