public void IfThenCondition_CheckCondition_complexOperands()
        {
            setup();
            LogicalConditionPolicy   lcpP1 = new LogicalConditionPolicy(7, LogicalConnections.or, LogicalConnections.and);
            ProductConditionPolicy   pcpP1 = new ProductConditionPolicy(8, p1.Id, 2, 10, LogicalConnections.and);
            inventoryConditionPolicy icpP1 = new inventoryConditionPolicy(9, p1.Id, 5, LogicalConnections.and);

            lcpP1.addChild(pcpP1);
            lcpP1.addChild(icpP1);

            LogicalConditionPolicy   lcpP2 = new LogicalConditionPolicy(14, LogicalConnections.and, LogicalConnections.and);
            ProductConditionPolicy   pcpP2 = new ProductConditionPolicy(15, p2.Id, 2, 10, LogicalConnections.and);
            inventoryConditionPolicy icpP2 = new inventoryConditionPolicy(16, p2.Id, 5, LogicalConnections.and);

            lcpP2.addChild(pcpP2);
            lcpP2.addChild(icpP2);

            itcp = new IfThenCondition(7, lcpP1, lcpP2, LogicalConnections.and);


            ProductInStore ps3 = new ProductInStore(10, store, new Product(3, "", "", "", 1));
            List <KeyValuePair <ProductInStore, int> > cart = new List <KeyValuePair <ProductInStore, int> >();

            cart.Add(new KeyValuePair <ProductInStore, int>(ps3, 1));
            Assert.AreEqual(true, itcp.CheckCondition(cart, null), "The empty case - the product is not related to the purchase policy");


            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 11));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 5));
            Assert.AreEqual(false, itcp.CheckCondition(cart, null), "if is not satisfied");


            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 5));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 1));
            Assert.AreEqual(false, itcp.CheckCondition(cart, null), "then 2 is not satisfied");


            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 5));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 5));
            Assert.AreEqual(true, itcp.CheckCondition(cart, null), "Both are satisfied");
        }
        public void setup()
        {
            sys         = new TradingSystem(null, null);
            admin       = new User(0, "admin", "1234", true, true);
            admin.State = state.signedIn;
            store       = new Store(0, "store");
            OwnerSotre  = new Owner(store, admin);
            store.RolesDictionary.Add(admin.Id, store.Roles.AddChild(OwnerSotre));
            admin.Roles.Add(store.Id, OwnerSotre);
            manager       = new User(1, "manager", "1234", false, true);
            manager.State = state.signedIn;
            List <int> permmision = new List <int>();

            permmision.Add(2);
            managerSotre = new Manager(store, manager, permmision);
            store.RolesDictionary.Add(manager.Id, store.Roles.AddChild(managerSotre));
            manager.Roles.Add(store.Id, managerSotre);

            p1  = new Product(1, "p1", null, null, 1);
            ps1 = new ProductInStore(10, store, p1);
            store.Products.Add(p1.Id, ps1);
            p2  = new Product(2, "p2", null, null, 10);
            ps2 = new ProductInStore(10, store, p2);
            store.Products.Add(p2.Id, ps2);
            pcp = new ProductConditionPolicy(0, 1, 0, 10, LogicalConnections.and);
            icp = new inventoryConditionPolicy(1, 1, 5, LogicalConnections.and);
            bcp = new BuyConditionPolicy(2, 2, 5, 10, 20, LogicalConnections.and);
            ucp = new UserConditionPolicy(3, "Tel Aviv", true, LogicalConnections.and);
            //itcp= if(buy p1 min buy =0 &max buy =10) then (min inventory =5)
            itcp = new IfThenCondition(4, pcp, icp, LogicalConnections.and);
            lcp  = new LogicalConditionPolicy(5, LogicalConnections.and, LogicalConnections.and);

            sys.Users.Add(admin.Id, admin);
            sys.Users.Add(manager.Id, manager);
            sys.Stores.Add(store.Id, store);
        }