示例#1
0
        public void SetUp()
        {
            DbCommerce.GetInstance().StartTests();
            LinkedList <string> policy = new LinkedList <string>();

            system = Workshop192.MarketManagment.System.GetInstance();
            AllRegisteredUsers.GetInstance().CreateUser();
            user = AllRegisteredUsers.GetInstance().GetUser(1);
            system.OpenStore("store1");
            system.OpenStore("store2");
            store1   = system.GetStore("store1");
            store2   = system.GetStore("store2");
            product1 = new Product(1, "", "", 10);
            product2 = new Product(2, "", "", 20);
            product3 = new Product(3, "", "", 30);
            product4 = new Product(4, "", "", 40);
            store1.AddProducts(product1, 10);
            store1.AddProducts(product2, 10);
            store2.AddProducts(product3, 10);
            store2.AddProducts(product4, 10);
            policy.AddLast("Ban"); policy.AddLast("AND"); policy.AddLast("1"); policy.AddLast("user");
            product1.AddDiscountPolicy(policy, 50);
            policy = new LinkedList <string>();
            policy.AddLast("Min"); policy.AddLast("AND"); policy.AddLast("1"); policy.AddLast("0"); policy.AddLast("5");
            product1.AddSellingPolicy(policy);
            policy = new LinkedList <string>();
            policy.AddLast("Min"); policy.AddLast("AND"); policy.AddLast("0"); policy.AddLast("0"); policy.AddLast("5");
            store1.AddSellingPolicy(policy);
            policy = new LinkedList <string>();
            policy.AddLast("Max"); policy.AddLast("AND"); policy.AddLast("0"); policy.AddLast("0"); policy.AddLast("50");
            store1.AddSellingPolicy(policy);
        }
示例#2
0
 public static bool Edit(string option, int productID, int userID)
 {
     if (option.Equals("delete"))
     {
         return(AllRegisteredUsers.GetInstance().GetUser(userID).RemoveProductFromCart(productID));
     }
     return(false);
 }
示例#3
0
 public static bool Registration(string username, string password, int userNum)
 {
     if (CreateAndGetUser.GetUser(userNum).GetInfo() == null) // if the user logged in will return false
     {
         // if the user registerd will return false , otherwise true
         return(AllRegisteredUsers.GetInstance().RegisterUser(username, password));
     }
     return(false);
 }
示例#4
0
 public void Init()
 {
     userId = AllRegisteredUsers.GetInstance().CreateUser();
     DbCommerce.GetInstance().StartTests();
     AllRegisteredUsers.GetInstance().CreateUser();
     user = AllRegisteredUsers.GetInstance().GetUser(1);
     AllRegisteredUsers.GetInstance().RegisterUser("user", "123456");
     info = AllRegisteredUsers.GetInstance().GetUserInfo("user");
 }
示例#5
0
 public void SetUp()
 {
     DbCommerce.GetInstance().StartTests();
     AllRegisteredUsers.GetInstance().RegisterUser("User1", "123456");
     AllRegisteredUsers.GetInstance().RegisterUser("User2", "123456");
     AllRegisteredUsers.GetInstance().RegisterUser("User3", "123456");
     AllRegisteredUsers.GetInstance().GetUserInfo("User1").OpenStore("Store");
     AllRegisteredUsers.GetInstance().GetUserInfo("User1").AddStoreManager("Store", AllRegisteredUsers.GetInstance().GetUserInfo("User2"), new bool [] { false, false, false, false, false, false, false });
     AllRegisteredUsers.GetInstance().GetUserInfo("User1").AddStoreManager("Store", AllRegisteredUsers.GetInstance().GetUserInfo("User3"), new bool[] { true, true, true, true, true, true, true });
 }
 public static bool RemoveUser(int adminID, string nameToDelete)
 {
     if (AllRegisteredUsers.GetInstance().GetUser(adminID).GetInfo() == null || !AllRegisteredUsers.GetInstance().GetUser(adminID).IsAdmin())
     {
         return(false);
     }
     if (AllRegisteredUsers.GetInstance().GetUserInfo(nameToDelete) == null)
     {
         return(false);
     }
     return(AllRegisteredUsers.GetInstance().GetUser(adminID).RemoveUser(AllRegisteredUsers.GetInstance().GetUserInfo(nameToDelete)));
 }
示例#7
0
 // use case 2.6 - Save products to cart
 public static bool SaveProduct(int productId,int userID,int amount)
 {
     for(int i = 0; i < Workshop192.MarketManagment.System.GetInstance().GetAllStores().Count; i++)
     {
         for(int j = 0; j < Workshop192.MarketManagment.System.GetInstance().GetAllStores().ElementAt(i).GetInventory().Count; j++)
         {
             if (Workshop192.MarketManagment.System.GetInstance().GetAllStores().ElementAt(i).GetInventory().ElementAt(j).productId == productId)
             {
                 string storeName = Workshop192.MarketManagment.System.GetInstance().GetAllStores().ElementAt(i).GetName();
                 return AllRegisteredUsers.GetInstance().GetUser(userID).AddProductsToMultiCart(storeName, productId, amount);
             }
         }
     }
     return false;
 }
示例#8
0
 public void SetUp()
 {
     DbCommerce.GetInstance().StartTests();
     AllRegisteredUsers.GetInstance().RegisterUser("admin", "admin12");
     admin = new Admin(AllRegisteredUsers.GetInstance().GetUserInfo("admin"));
     AllRegisteredUsers.GetInstance().RegisterUser("asd", "12345567");
     AllRegisteredUsers.GetInstance().RegisterUser("asdf", "111111111");
     AllRegisteredUsers.GetInstance().RegisterUser("qwe", "111222434");
     user1 = AllRegisteredUsers.GetInstance().GetUserInfo("asd");
     user2 = AllRegisteredUsers.GetInstance().GetUserInfo("asdf");
     user3 = AllRegisteredUsers.GetInstance().GetUserInfo("qwe");
     user1.OpenStore("tmp");
     user1.AddStoreManager("tmp", user2, new bool[7]);
     user1.AddStoreOwner("tmp", user3);
 }
示例#9
0
        public static LinkedList <string> ShowWaitingsList(int userId, string Store)
        {
            LinkedList <string> ret = new LinkedList <string>();
            string AllNames         = AllRegisteredUsers.GetInstance().GetUser(userId).GetInfo().GetOwner(Store).pendingUsers;

            if (AllNames == null)
            {
                AllNames = "";
            }
            string[] names = AllNames.Split('$');
            for (int i = 0; i < names.Length; i++)
            {
                ret.AddLast(names[i]);
            }
            return(ret);
        }
示例#10
0
        public void SetUp()
        {
            DbCommerce.GetInstance().StartTests();
            int user_1 = AllRegisteredUsers.GetInstance().CreateUser();

            AllRegisteredUsers.GetInstance().CreateUser();
            AllRegisteredUsers.GetInstance().CreateUser();
            AllRegisteredUsers.GetInstance().CreateUser();
            user1 = AllRegisteredUsers.GetInstance().GetUser(1);
            user2 = AllRegisteredUsers.GetInstance().GetUser(2);
            user3 = AllRegisteredUsers.GetInstance().GetUser(3);
            AllRegisteredUsers.GetInstance().RegisterUser("user1", "1234567");
            AllRegisteredUsers.GetInstance().RegisterUser("user2", "1234567");
            AllRegisteredUsers.GetInstance().RegisterUser("user3", "1234567");
            user1.LogIn(AllRegisteredUsers.GetInstance().GetUserInfo("user1"));
            user2.LogIn(AllRegisteredUsers.GetInstance().GetUserInfo("user2"));
            user3.LogIn(AllRegisteredUsers.GetInstance().GetUserInfo("user3"));
            user1.OpenStore("store", user_1);
        }
示例#11
0
 // use case 4.1 - Manage Products
 public static bool ManageProduct(int userID, int productID, string name, string category, int price, int amount, string store, string option)
 {
     if (AllRegisteredUsers.GetInstance().GetUser(userID).GetInfo() == null)
     {
         return(false);
     }
     else
     {
         if (option.Equals("edit"))
         {
             if (AllRegisteredUsers.GetInstance().GetUser(userID).GetInfo().GetOwner(store) != null)
             {
                 return(AllRegisteredUsers.GetInstance().GetUser(userID).GetInfo().GetOwner(store).EditProduct(productID, name, category, price, amount));
             }
             return(AllRegisteredUsers.GetInstance().GetUser(userID).GetInfo().EditProduct(store, productID, name, category, price, amount));
         }
         else if (option.Equals("add"))
         {
             Product product = Workshop192.MarketManagment.System.GetInstance().CreateProduct(name, category, price);
             if (AllRegisteredUsers.GetInstance().GetUser(userID).GetInfo().GetOwner(store) != null)
             {
                 return(AllRegisteredUsers.GetInstance().GetUser(userID).GetInfo().GetOwner(store).AddProducts(product, amount));
             }
             return(AllRegisteredUsers.GetInstance().GetUser(userID).GetInfo().GetManager(store).AddProducts(product, amount));
         }
         else if (option.Equals("delete"))
         {
             if (AllRegisteredUsers.GetInstance().GetUser(userID).GetInfo().GetOwner(store) != null)
             {
                 return(AllRegisteredUsers.GetInstance().GetUser(userID).GetInfo().GetOwner(store).RemoveProductFromInventory(productID));
             }
             return(AllRegisteredUsers.GetInstance().GetUser(userID).GetInfo().GetManager(store).RemoveProductFromInventory(productID));
         }
         return(false);
     }
 }
示例#12
0
 public void AddProducts_ManagerDosentHavePrivilege_ReturnsFalse()
 {
     Assert.Throws <ErrorMessageException>(() => AllRegisteredUsers.GetInstance().GetUserInfo("User2").GetManager("Store").AddProducts(new Product(1, "", "", 1), 2));
 }
示例#13
0
 // use case 4.3 - Assign store owner
 public static bool assignStoreOwner(int I_storeOwner, string store, string username)
 {
     return(CreateAndGetUser.GetUser(I_storeOwner).AddStoreOwner(store, AllRegisteredUsers.GetInstance().GetUserInfo(username)));
 }
示例#14
0
 public static string GetUserName(int user)
 {
     return(AllRegisteredUsers.GetInstance().GetUser(user).GetUserName());
 }
示例#15
0
 public static User GetUser(int userNum)
 {
     return(AllRegisteredUsers.GetInstance().GetUser(userNum));
 }
示例#16
0
 public static int CreateUser()
 {
     return(AllRegisteredUsers.GetInstance().CreateUser());
 }
示例#17
0
 // use case 4.5 - Assign store Manager
 public static bool AsssignManager(int userNum, string store, string username, bool [] privileges)
 {
     return(CreateAndGetUser.GetUser(userNum).AddStoreManager(store, AllRegisteredUsers.GetInstance().GetUserInfo(username), privileges));
 }
示例#18
0
 public void AddProducts_ManagerHasPrivilege_ReturnsTrue()
 {
     Assert.IsTrue(AllRegisteredUsers.GetInstance().GetUserInfo("User3").GetManager("Store").AddProducts(new Product(1, "", "", 1), 2));
 }
示例#19
0
 public void TearDown()
 {
     DbCommerce.GetInstance().EndTests();
     Workshop192.MarketManagment.System.Reset();
     AllRegisteredUsers.Reset();
 }
示例#20
0
 public static bool removeStoreManager(int Im, string store, string toRemove)
 {
     return(CreateAndGetUser.GetUser(Im).RemoveStoreManager(store, AllRegisteredUsers.GetInstance().GetUserInfo(toRemove)));
 }