Exemplo n.º 1
0
        public bool setUp1()
        {
            bool   flag = true;
            string user = instance.initUser();

            flag = flag & instance.register("user", "user", user);
            flag = flag & instance.openStore("store", "user");
            flag = flag & instance.createNewProductInStore("product", "cat", "details", 10, "store", "user");
            List <KeyValuePair <string, int> > products = new List <KeyValuePair <string, int> >();

            products.Add(new KeyValuePair <string, int>("product", 10));
            if (!flag)
            {
                return(flag);
            }
            flag = flag & instance.addProductsInStore(products, "store", "user");
            return(flag);
        }
Exemplo n.º 2
0
        internal static bool fileSetUp()
        {
            string       user    = "";
            bool         flag    = true;
            ServiceLayer service = ServiceLayer.getInstance();
            // Open the file to read from.
            string       path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\src\\State.json");
            StreamReader sr   = null;

            try {
                sr = new StreamReader(path);
            }
            catch (Exception e) {
                ErrorManager.Instance.WriteToLog("SystemState - fileSetUp - File not exist");
                return(false);
            }
            using (sr)
            {
                string json  = sr.ReadToEnd();
                State  state = JsonConvert.DeserializeObject <State>(json);
                foreach (Request r in state.Requests)
                {
                    switch (r.RequestName)
                    {
                    case "Init":
                        flag = flag & service.init(r.User, r.Password);
                        break;

                    case "InitUser":
                        user = service.initUser();
                        break;

                    case "Login":
                        flag = flag & service.signIn(r.User, r.Password);
                        break;

                    case "Register":
                        flag = flag & service.register(r.User, r.Password, user);
                        break;

                    case "Logout":
                        if (r.User != null)
                        {
                            flag = flag & service.signOut(r.User);
                        }
                        else
                        {
                            return(false);
                        }
                        break;

                    case "AddProductsToCart":
                        if (r.User != null)
                        {
                            flag = flag & service.addProductsToCart(r.Products, r.Store, r.User);
                        }
                        else
                        {
                            flag = flag & service.addProductsToCart(r.Products, r.Store, user);
                        }
                        break;

                    case "EditProductQuantityInCart":
                        if (r.User != null)
                        {
                            flag = flag & service.editProductQuantityInCart(r.Product, r.Quantity, r.Store, r.User);
                        }
                        else
                        {
                            flag = flag & service.editProductQuantityInCart(r.Product, r.Quantity, r.Store, user);
                        }
                        break;

                    case "RemoveProductsFromCart":
                        if (r.User != null)
                        {
                            flag = flag & service.removeProductsFromCart(r.ProductsToRemove, r.Store, r.User);
                        }
                        else
                        {
                            flag = flag & service.removeProductsFromCart(r.ProductsToRemove, r.Store, user);
                        }
                        break;

                    case "OpenStore":
                        if (r.User != null)
                        {
                            flag = flag & service.openStore(r.Store, r.User);
                        }
                        else
                        {
                            return(false);
                        }
                        break;

                    case "CreateNewProductInStore":
                        if (r.User != null)
                        {
                            flag = flag & service.createNewProductInStore(r.ProductName, r.Category, r.Details, r.Price, r.Store, r.User);
                        }
                        else
                        {
                            return(false);
                        }
                        break;

                    case "AddProductsInStore":
                        if (r.User != null)
                        {
                            flag = flag & service.addProductsInStore(r.Products, r.Store, r.User);
                        }
                        else
                        {
                            return(false);
                        }
                        break;

                    case "RemoveProductsInStore":
                        if (r.User != null)
                        {
                            flag = flag & service.removeProductsInStore(r.Products, r.Store, r.User);
                        }
                        else
                        {
                            return(false);
                        }
                        break;

                    case "EditProductInStore":
                        if (r.User != null)
                        {
                            flag = flag & service.editProductInStore(r.Product, r.ProductName, r.Category, r.Details, r.Price, r.Store, r.User);
                        }
                        else
                        {
                            return(false);
                        }
                        break;

                    case "AssignOwner":
                        if (r.User != null)
                        {
                            flag = flag & service.assignOwnerSetUp(r.User, r.Owner, r.Store);
                        }
                        else
                        {
                            return(false);
                        }
                        break;

                    case "RemoveOwner":
                        if (r.User != null)
                        {
                            flag = flag & service.removeOwner(r.Owner, r.Store, r.User);
                        }
                        else
                        {
                            return(false);
                        }
                        break;

                    case "AssignManager":
                        if (r.User != null)
                        {
                            flag = flag & service.assignManager(r.Manager, r.Store, r.Permissions, r.User);
                        }
                        else
                        {
                            return(false);
                        }
                        break;

                    case "RemoveManager":
                        if (r.User != null)
                        {
                            flag = flag & service.removeOwner(r.Manager, r.Store, r.User);
                        }
                        else
                        {
                            return(false);
                        }
                        break;

                    case "RemoveUser":
                        if (r.User != null)
                        {
                            flag = flag & service.removeUser(r.UserToRemove, r.User);
                        }
                        else
                        {
                            return(false);
                        }
                        break;

                    default:
                        return(false);
                    }
                }
            }
            return(flag);
        }