public void Execute_First_Null_Arg_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); Order order = new Order(); string error; engine.Execute(null, ref order, out error); }
public void Initialize() { //New instance of Order _order = new Order() { Id = 123, Items = new List<OrderItem>() { new OrderItem() { BasePricePerItem = 10, Quantity = 2, Discount = 2 } }, OrderNumber = "test", LastUpdatedUtc = new DateTime(1969, 7, 21), TimeOfOrderUtc = new DateTime(1969, 7, 21), Customer = new Customer(), IsPlaced = true, BillingAddress = new Address(), ShippingAddress = new Address(), AffiliateId = "test", OrderDiscount = 3.14159265D }; }
public void Execute_Null_OrderItem_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); Order order = new Order(); string error; engine.Execute( ConfigurationManager.AppSettings["RuleFilePath"], ref order, out error); }
public void Execute_InValidRulePath_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); Order order = new Order() { Items = new List<OrderItem>() }; string error; Assert.IsTrue(engine.Execute( "test", ref order, out error)); }
public void Execute_Empty_Object_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); Order order = new Order() { Items = new List<OrderItem>() }; string error; Assert.IsTrue(engine.Execute( ConfigurationManager.AppSettings["RuleFilePath"], ref order, out error)); }
public Order CalculateOrderTotal(Order order) { if (order == null) { throw new ArgumentNullException("order"); } string errorMessage; if (_ruleExecutor.Execute( ConfigurationManager.AppSettings["RuleFilePath"], ref order, out errorMessage)) { return order; } throw new BusinessException(errorMessage); }
public void Execute_InValidRuleFile_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); Order order = new Order() { Items = new List<OrderItem>() }; string path = Environment.CurrentDirectory + "\\test.txt"; using (var stream = File.Create(path)) { stream.Close(); } string error; Assert.IsTrue(engine.Execute( path, ref order, out error)); }
public void Execute_CustomerMoreThan2_LessThan_890_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); var order = new Order { Id = 1, Customer = new Customer { RegisteredOnUtc = DateTime.UtcNow.AddYears(3) }, Items = new List<OrderItem>() }; order.Items.Add(new OrderItem { BasePricePerItem = 100, Quantity = 8, ItemType = ProductItemType.Apparel }); order.Items.Add(new OrderItem { BasePricePerItem = 90, Quantity = 1, ItemType = ProductItemType.Grocery }); string error; Assert.IsTrue(engine.Execute( ConfigurationManager.AppSettings["RuleFilePath"], ref order, out error)); Assert.AreEqual(order.TotalOrderDiscounts, 40D + 40D); }
public void Execute_Affiliate_LessThan_890_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); var order = new Order { Id = 1, Customer = new Customer (), Items = new List<OrderItem>(), AffiliateId = "AFF-10" }; order.Items.Add(new OrderItem { BasePricePerItem = 100, Quantity = 8, ItemType = ProductItemType.Apparel }); order.Items.Add(new OrderItem { BasePricePerItem = 90, Quantity = 1, ItemType = ProductItemType.Grocery }); string error; Assert.IsTrue(engine.Execute( ConfigurationManager.AppSettings["RuleFilePath"], ref order, out error)); Assert.AreEqual(order.TotalOrderDiscounts, 80D + 40D); }
public void Execute_EmployeeNoDiscountOnGrocery_LessThan_100_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); var order = new Order { Id = 1, Customer = new Customer { IsEmployee = true }, Items = new List<OrderItem>() }; order.Items.Add(new OrderItem { BasePricePerItem = 50, Quantity = 1, ItemType = ProductItemType.Grocery }); string error; Assert.IsTrue(engine.Execute( ConfigurationManager.AppSettings["RuleFilePath"], ref order, out error)); Assert.AreEqual(order.TotalOrderDiscounts, 0D); }
static void Main(string[] args) { // employee var order1 = new Order { Id = 1, Customer = new Customer { IsEmployee = true }, Items = new List<OrderItem>() }; order1.Items.Add(new OrderItem { BasePricePerItem = 40, Quantity = 1, ItemType = ProductItemType.Apparel }); order1.Items.Add(new OrderItem { BasePricePerItem = 50, Quantity = 1, ItemType = ProductItemType.Grocery }); var service = new OrderOperation(new RuleEngine<Order>()); var result1 = service.CalculateOrderTotal(order1); Console.WriteLine(result1.TotalGrand); // Affiliate var order2 = new Order { Id = 1, Customer = new Customer(), Items = new List<OrderItem>(), AffiliateId = "AFF-10" }; order2.Items.Add(new OrderItem { BasePricePerItem = 40, Quantity = 1, ItemType = ProductItemType.Apparel }); order2.Items.Add(new OrderItem { BasePricePerItem = 50, Quantity = 1, ItemType = ProductItemType.Grocery }); var result2 = service.CalculateOrderTotal(order2); Console.WriteLine(result2.TotalGrand); // more than 2 year var order3 = new Order { Id = 1, Customer = new Customer { RegisteredOnUtc = DateTime.UtcNow.AddYears(3) }, Items = new List<OrderItem>() }; order3.Items.Add(new OrderItem { BasePricePerItem = 40, Quantity = 1, ItemType = ProductItemType.Apparel }); order3.Items.Add(new OrderItem { BasePricePerItem = 50, Quantity = 1, ItemType = ProductItemType.Grocery }); var result3 = service.CalculateOrderTotal(order3); Console.WriteLine(result3.TotalGrand); // no discount var order = new Order { Id = 1, Customer = new Customer() {RegisteredOnUtc = DateTime.UtcNow.AddYears(1)}, Items = new List<OrderItem>() }; order.Items.Add(new OrderItem { BasePricePerItem = 40, Quantity = 1, ItemType = ProductItemType.Apparel }); order.Items.Add(new OrderItem { BasePricePerItem = 50, Quantity = 1, ItemType = ProductItemType.Grocery }); var result4 = service.CalculateOrderTotal(order); Console.WriteLine(result4.TotalGrand); Console.ReadKey(); }