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 addManagerSuccTest()
 {
     try
     {
         sr.addManager(session2.getSubscribedUser(), per);
         Assert.AreEqual(store.getStoreRole(session2.getSubscribedUser()) is StoreManager, true);
         Assert.AreEqual(store.getStoreRole(session2.getSubscribedUser()).getAppointedBy(),
                         session1.getSubscribedUser());
         Assert.AreEqual(store.getStoreRole(session2.getSubscribedUser()),
                         session2.getSubscribedUser().getStoreRole(store));
     }
     catch (Exception)
     {
         Assert.Fail();
     }
 }
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 addManagerSuccTest()
 {
     Assert.AreEqual("", sr.addManager(session2.getSubscribedUser(), per));
     Assert.AreEqual(store.getStoreRole(session2.getSubscribedUser()) is StoreManager, true);
     Assert.AreEqual(store.getStoreRole(session2.getSubscribedUser()).getAppointedBy(),
                     session1.getSubscribedUser());
     Assert.AreEqual(store.getStoreRole(session2.getSubscribedUser()),
                     session2.getSubscribedUser().getStoreRole(store));
 }
Ejemplo n.º 5
0
        public void init()
        {
            MarketSystem.initTestWitOutRead();
            //storeDB.initTests();
            //productDB.initTests();
            //DBSubscribedUser.getInstance().initTests();
            session1 = new Session();
            string pass = DomainBridge.getInstance().encryptPassword("123");

            session1.register("eyal", pass);

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

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

            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.º 6
0
        public void removeSubscribedUserTest()
        {
            Session        sessionOwner       = userService.startSession();
            Session        sessionManager     = userService.startSession();
            SubscribedUser subscribedToDelete = sessionManager.getSubscribedUser();

            userService.register(sessionOwner, "bob", "theOwner");
            userService.register(sessionManager, "rob", "theManager");
            userService.login(sessionOwner, "bob", "theOwner");
            Store     store1 = userService.createStore(sessionOwner, "Zara", "clothes");
            Store     store2 = userService.createStore(sessionOwner, "Urban", "clothes");
            StoreRole owner1 = sessionOwner.getSubscribedUser().getStoreRole(store1);

            owner1.addManager(sessionManager.getSubscribedUser(), new Permissions(true, true, true));
            StoreRole owner2 = sessionOwner.getSubscribedUser().getStoreRole(store2);

            owner2.addOwner(sessionManager.getSubscribedUser());

            Session sessionAdmin = userService.startSession();

            Assert.AreEqual(userService.login(sessionAdmin, "admin", "1234"), "");
            Assert.IsTrue(Equals(userService.removeUser(sessionAdmin, "rob"), ""));

            Assert.IsTrue(sessionManager.getState() is Guest);
            Assert.IsTrue(store1.getStoreRole(subscribedToDelete) == null);
            Assert.IsTrue(store2.getStoreRole(subscribedToDelete) == null);
            Assert.IsTrue(sessionManager.getSubscribedUser() == null);

            //user does not exist anymore, login fails
            Assert.AreNotEqual(userService.login(sessionAdmin, "rob", "theManager"), "");

            //alternatives
            Assert.IsFalse(Equals(userService.removeUser(sessionAdmin, "haim"), ""));
            Assert.IsFalse(Equals(userService.removeUser(sessionAdmin, "admin"), ""));
            Assert.IsFalse(Equals(userService.removeUser(sessionManager, "rob"), ""));
            Assert.IsFalse(Equals(userService.removeUser(sessionOwner, "rob"), ""));
        }