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"); }
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 LogicalConditionPolicy_addChild() { setup(); Assert.AreEqual(true, lcp.addChild(icp), "Adding the child is successful"); Assert.AreEqual(false, lcp.addChild(icp), "Adding a double child is prohibited"); }