Exemplo n.º 1
0
        public void Test2()
        {
            CustomerFactory       factory   = new CustomerFactory(new ObjectContext(CreateDataStore()));
            ObjectList <Customer> customers = factory.Find("Status.Name = {0}", "Active");

            Assert.IsNotNull(customers.Count >= 2, "Should not be at least 2.");

            Agenda agenda = new Agenda();

            agenda.ConflictResolutionStrategy = new SalienceResolver();
            agenda.LoadRulesFromAssemblies    = false;
            agenda.AddObjects(customers);

            Production WhatsMyName = new Production("Whats My Name");

            WhatsMyName.Salience = 1;
            Variable customer_var  = new Variable("Customer");
            Variable customer_name = new Variable("Name");

            WhatsMyName.AddConditionToLHS(new PositiveCondition("C2", customer_var, "$Customer.Name", customer_name));
            WhatsMyName.AddConditionToLHS(new FunctionCondition("C3", customer_name, new FuncTerm("funcEquals", new funcEquals()), "Joe Blow"));
            WhatsMyName.AddConditionToRHS(new InvokeCondition("R1", customer_var, "Shout", customer_name));
            WhatsMyName.AddConditionToRHS(new SetCondition("R2", customer_var, "Remarks", "Hello from Expergent."));
            agenda.AddProduction(WhatsMyName);

            Production WhatsMyName1 = new Production();

            WhatsMyName1.Salience = 10;
            WhatsMyName1.AddConditionToLHS(new PositiveCondition(customer_var, "$Customer.Name", customer_name));
            WhatsMyName1.AddConditionToRHS(new InvokeCondition(customer_var, "Shout", "Squid"));
            WhatsMyName1.AddConditionToRHS(new SetCondition(customer_var, "Remarks", "Squid Text"));
            agenda.AddProduction(WhatsMyName1);

            agenda.Run();

            agenda.VisualizeNetworkToFile(@"C:\Temp\NeoTest2.log", false);

            Assert.IsTrue(agenda.TotalFacts == 22, "Bad");
            Assert.IsTrue(agenda.ActionsTaken.Count == 6, "Bad");
            Assert.IsTrue(agenda.ActionsSkipped.Count == 0, "Bad");
            Assert.IsTrue(agenda.ActivatedRuleCount == 2, "Bad");
            Assert.IsTrue(customers.FindFirst("Name = {0}", "Joe Blow").Result != null && customers.FindFirst("Name = {0}", "Joe Blow").Result.Contains("Squid"), "Did not invoke method.");
            Assert.IsTrue(customers.FindFirst("Name = {0}", "Joe Blow").Remarks != null && customers.FindFirst("Name = {0}", "Joe Blow").Remarks.Contains("Squid Text"), "Did not invoke method.");
        }