public void CollectionTest() { CustomerFactory factory = new CustomerFactory(new ObjectContext(CreateDataStore())); Customer customer = factory.FindFirst("Name = {0}", "Joe Blow"); IList <WME> factlist = customer.GenerateFactsForRootObject(); Assert.IsTrue(factlist.Count == 11, "Wrong count."); Agenda agenda = new Agenda(); agenda.LoadRulesFromAssemblies = false; Variable customer_var = new Variable("Customer"); Variable orders = new Variable("Orders"); Variable order = new Variable("Order"); Variable orderItems = new Variable("OrderItems"); Variable orderItem = new Variable("OrderItem"); Variable product = new Variable("Product"); //Variable comment = new Variable("Comment"); Variable description = new Variable("Description"); Production mostSimple = new Production("CollectionTest"); mostSimple.AddConditionToLHS(new PositiveCondition(customer_var, "$Customer.Orders", orders)); mostSimple.AddConditionToLHS(new PositiveCondition(orders, "$Customer.Orders.Order", order)); mostSimple.AddConditionToLHS(new PositiveCondition(order, "$Customer.Orders.Order.OrderItems", orderItems)); mostSimple.AddConditionToLHS(new PositiveCondition(orderItems, "$Customer.Orders.Order.OrderItems.OrderItem", orderItem)); mostSimple.AddConditionToLHS(new PositiveCondition(orderItem, "$Customer.Orders.Order.OrderItems.OrderItem.Product", product)); mostSimple.AddConditionToLHS(new PositiveCondition(product, "$Customer.Orders.Order.OrderItems.OrderItem.Product.Description", description)); mostSimple.AddConditionToLHS(new FunctionCondition(description, new FuncTerm("funcEquals", new funcEquals()), "Troll Food")); mostSimple.AddConditionToRHS(new InvokeCondition("shout", customer_var, "Shout", "Yipee")); mostSimple.AddConditionToRHS(new AssertCondition("Wow", customer_var, "eats", description)); agenda.AddProduction(mostSimple); agenda.AddFacts(factlist); agenda.Run(); agenda.VisualizeNetworkToFile(@"C:\Temp\CollectionTest.log", false); Assert.IsTrue(agenda.TotalFacts == 11, "Bad"); Assert.IsTrue(agenda.ActionsTaken.Count == 1, "Bad"); Assert.IsTrue(agenda.ActionsSkipped.Count == 0, "Bad"); Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Bad"); Assert.IsTrue(customer.Result != null && customer.Result.StartsWith("Shout"), "Did not invoke method."); }
public void FirstAggTest() { CustomerFactory factory = new CustomerFactory(new ObjectContext(CreateDataStore())); Customer customer = factory.FindFirst("Name = {0}", "Joe Blow"); IList <WME> factlist = customer.GenerateFactsForRootObject(); Assert.IsTrue(factlist.Count == 11, "Wrong count."); Agenda agenda = new Agenda(); agenda.LoadRulesFromAssemblies = false; Variable customer_var = new Variable("Customer"); Variable orders = new Variable("Orders"); Variable order = new Variable("Order"); Variable val = new Variable("?Value"); Aggregator ag = new Aggregator("Count of customer orders."); ag.GroupBy = customer_var; ag.AggregatorFunction = new Count("$Customer.Orders.Order", "$Customer.Orders.Count"); ag.AddConditionToLHS(new AND(customer_var, "$Customer.Orders", orders)); ag.AddConditionToLHS(new AND(orders, "$Customer.Orders.Order", order)); agenda.AddAggregator(ag); Production mostSimple = new Production("If Big Spender"); mostSimple.AddConditionToLHS(new AND(customer_var, "$Customer.Orders.Count", val)); mostSimple.AddConditionToRHS(new INVOKE("shout", customer_var, "Shout", val)); agenda.AddProduction(mostSimple); agenda.AddFacts(factlist); agenda.Run(); agenda.VisualizeNetworkToFile(@"C:\Temp\FirstAggTest.log", false); Assert.IsTrue(agenda.TotalFacts == 11, "Bad"); Assert.IsTrue(agenda.ActionsTaken.Count == 1, "Bad"); Assert.IsTrue(agenda.ActionsSkipped.Count == 0, "Bad"); Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Bad"); Assert.IsTrue(customer.Result != null && customer.Result.StartsWith("Shout"), "Did not invoke method."); }
public void FirstAggTest() { CustomerFactory factory = new CustomerFactory(new ObjectContext(CreateDataStore())); Customer customer = factory.FindFirst("Name = {0}", "Joe Blow"); IList<WME> factlist = customer.GenerateFactsForRootObject(); Assert.IsTrue(factlist.Count == 11, "Wrong count."); Agenda agenda = new Agenda(); agenda.LoadRulesFromAssemblies = false; Variable customer_var = new Variable("Customer"); Variable orders = new Variable("Orders"); Variable order = new Variable("Order"); Variable val = new Variable("?Value"); Aggregator ag = new Aggregator("Count of customer orders."); ag.GroupBy = customer_var; ag.AggregatorFunction = new Count("$Customer.Orders.Order", "$Customer.Orders.Count"); ag.AddConditionToLHS(new AND(customer_var, "$Customer.Orders", orders)); ag.AddConditionToLHS(new AND(orders, "$Customer.Orders.Order", order)); agenda.AddAggregator(ag); Production mostSimple = new Production("If Big Spender"); mostSimple.AddConditionToLHS(new AND(customer_var, "$Customer.Orders.Count", val)); mostSimple.AddConditionToRHS(new INVOKE("shout", customer_var, "Shout", val)); agenda.AddProduction(mostSimple); agenda.AddFacts(factlist); agenda.Run(); agenda.VisualizeNetworkToFile(@"C:\Temp\FirstAggTest.log", false); Assert.IsTrue(agenda.TotalFacts == 11, "Bad"); Assert.IsTrue(agenda.ActionsTaken.Count == 1, "Bad"); Assert.IsTrue(agenda.ActionsSkipped.Count == 0, "Bad"); Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Bad"); Assert.IsTrue(customer.Result != null && customer.Result.StartsWith("Shout"), "Did not invoke method."); }
public void FirstTest() { CustomerFactory factory = new CustomerFactory(new ObjectContext(CreateDataStore())); Customer customer = factory.FindFirst("Status.Name = {0}", "Active"); Assert.IsNotNull(customer, "Should not be null."); IList <WME> factlist = customer.GenerateFactsForRootObject(); Assert.IsTrue(factlist.Count == 11, "Wrong count."); Agenda agenda = new Agenda(); agenda.LoadRulesFromAssemblies = false; Variable customer_var = new Variable("Customer"); Variable customer_name = new Variable("Customer.Name"); Production mostSimple = new Production("Most Simple"); mostSimple.AddConditionToLHS(new PositiveCondition(customer_var, "$Customer.Name", customer_name)); mostSimple.AddConditionToRHS(new InvokeCondition("shout", customer_var, "Shout", customer_name)); agenda.AddProduction(mostSimple); agenda.AddFacts(factlist); agenda.Run(); agenda.VisualizeNetworkToFile(@"C:\Temp\NeoFirstTest.log", false); Assert.IsTrue(agenda.TotalFacts == 11, "Bad"); Assert.IsTrue(agenda.ActionsTaken.Count == 1, "Bad"); Assert.IsTrue(agenda.ActionsSkipped.Count == 0, "Bad"); Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Bad"); Assert.IsTrue(customer.Result != null && customer.Result.StartsWith("Shout"), "Did not invoke method."); }