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"); } }
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"); }
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); }