示例#1
0
        public void LogicalConditionPolicy_CheckConditionOr()
        {
            setup();
            //lcp= be satisfy - in cart must be 2 to 10 ps1 or nothing or inventory need minimum 5
            lcp = new LogicalConditionPolicy(5, LogicalConnections.or, LogicalConnections.and);
            pcp = new ProductConditionPolicy(0, 1, 2, 10, LogicalConnections.and);
            lcp.addChild(pcp);
            lcp.addChild(icp);
            List <KeyValuePair <ProductInStore, int> > cart = new List <KeyValuePair <ProductInStore, int> >();

            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 1));
            Assert.AreEqual(true, lcp.CheckConditionOr(cart, null), "The empty case - the product is not related to the purchase policy");
            Assert.AreEqual(true, lcp.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, 1));
            Assert.AreEqual(true, lcp.CheckConditionOr(cart, null), "The first condition is not satisfy");
            Assert.AreEqual(true, lcp.CheckCondition(cart, null), "The first condition is not satisfy");

            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 6));
            Assert.AreEqual(true, lcp.CheckConditionOr(cart, null), "Second condition are not satisfy");
            Assert.AreEqual(true, lcp.CheckCondition(cart, null), "Second condition are not satisfy");

            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 5));
            Assert.AreEqual(true, lcp.CheckConditionOr(cart, null), "All conditions are satisfy");
            Assert.AreEqual(true, lcp.CheckCondition(cart, null), "All conditions are satisfy");


            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 11));
            Assert.AreEqual(false, lcp.CheckConditionOr(cart, null), "No condition is satisfy");
            Assert.AreEqual(false, lcp.CheckCondition(cart, null), "No condition is satisfy");
        }
示例#2
0
        public void Store_addSimplePurchasePolicy()
        {
            setUp();
            PurchesPolicyData data = new PurchesPolicyData(0, 0, p1.Id, -1, 2, 10, -1, -1, LogicalConnections.and, null, false);

            try
            {
                ProductConditionPolicy p = (ProductConditionPolicy)store.addSimplePurchasePolicy(data);
                Assert.AreEqual(true, p.getId() == 0, "ProductConditionPolicy- id not insert correctly");
            }
            catch (Exception e)
            {
                Assert.AreEqual(true, false, "ProductConditionPolicy-An object of the wrong type was created");
            }

            data = new PurchesPolicyData(1, 0, p1.Id, -1, 5, -1, -1, -1, LogicalConnections.and, null, false);
            try
            {
                inventoryConditionPolicy p = (inventoryConditionPolicy)store.addSimplePurchasePolicy(data);
                Assert.AreEqual(true, p.getId() == 0, "inventoryConditionPolicy- id not insert correctly");
            }
            catch (Exception e)
            {
                Assert.AreEqual(true, false, "inventoryConditionPolicy-An object of the wrong type was created");
            }
            data = new PurchesPolicyData(2, 0, -1, -1, 2, 10, 15, 30, LogicalConnections.and, null, false);
            try
            {
                BuyConditionPolicy p = (BuyConditionPolicy)store.addSimplePurchasePolicy(data);
                Assert.AreEqual(true, p.getId() == 0, "BuyConditionPolicy- id not insert correctly");
            }
            catch (Exception e)
            {
                Assert.AreEqual(true, false, "BuyConditionPolicy-An object of the wrong type was created");
            }
            data = new PurchesPolicyData(3, 0, -1, -1, -1, -1, -1, -1, LogicalConnections.and, "TelAviv", true);
            try
            {
                UserConditionPolicy p = (UserConditionPolicy)store.addSimplePurchasePolicy(data);
                Assert.AreEqual(true, p.getId() == 0, "UserConditionPolicy- id not insert correctly");
            }
            catch (Exception e)
            {
                Assert.AreEqual(true, false, "UserConditionPolicy-An object of the wrong type was created");
            }
        }
示例#3
0
        public void LogicalConditionPolicy_CheckCondition_complexCondition()
        {
            setup();
            //lcp= be satisfy - in cart must be 2 to 10 ps1 or nothing or inventory need minimum 5
            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);

            lcp.addChild(lcpP1);
            lcp.addChild(lcpP2);

            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, lcp.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, lcp.CheckCondition(cart, null), "Sub-tree 1 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, lcp.CheckCondition(cart, null), "Sub-tree 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, lcp.CheckCondition(cart, null), "Both are satisfied");
        }
示例#4
0
        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");
        }
示例#5
0
        public void setUp()
        {
            store = new Store(1111, "adidas");

            admin        = new User(0, "admin", "1234", true, true);
            basket_admin = admin.Basket;
            ownerUser    = new User(1234, "Seifan", "2457", false, false);
            ownerUser.register(ownerUser.UserName, ownerUser.Password);
            ownerUser.signIn(ownerUser.UserName, ownerUser.Password);
            ownerRole = new Owner(store, ownerUser);
            ownerUser.Roles.Add(store.Id, ownerRole);


            p1   = new Product(0, "first", "", "", 100);
            p2   = new Product(1, "second", "", "", 50);
            p3   = new Product(2, "third", "", "", 200);
            p4   = new Product(3, "fourth", "", "", 300);
            pis1 = new ProductInStore(20, store, p1);
            pis2 = new ProductInStore(20, store, p2);
            pis3 = new ProductInStore(20, store, p3);
            pis4 = new ProductInStore(20, store, p4);
            store.Products.Add(p1.Id, pis1);
            store.Products.Add(p2.Id, pis2);
            store.Products.Add(p3.Id, pis3);
            store.Products.Add(p4.Id, pis4);

            products = new Dictionary <int, KeyValuePair <ProductInStore, int> >();
            products.Add(p1.Id, new KeyValuePair <ProductInStore, int>(pis1, 2));
            products.Add(p2.Id, new KeyValuePair <ProductInStore, int>(pis1, 10));
            products.Add(p3.Id, new KeyValuePair <ProductInStore, int>(pis1, 5));
            products.Add(p4.Id, new KeyValuePair <ProductInStore, int>(pis1, 4));

            pcp = new ProductConditionPolicy(0, 1, 0, 10, LogicalConnections.and);
            store.PurchasePolicy.Add(pcp);

            system = new TradingSystem(null, null);
            system.Stores.Add(store.Id, store);
            system.Users.Add(admin.Id, admin);
            system.Users.Add(ownerUser.Id, ownerUser);
        }
示例#6
0
        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);
        }