Once all business policies and their required
vocabularies are defined, you need to test and debug them before
deploying them in production.
Because of the nonsequential nature of business
processes, the Business Rules Composer doesn't provide the same testing,
tracing, and debugging functionality as procedural development
environments such as Visual Studio. Nonetheless, it does provide a
testing tool, shown in Figure 1.
You can simply select fact instances for the testing tool to assert into the engine for your policy or select a FactCreator
that the testing tool will instantiate and call to create the facts
required for the policy execution. The testing tool then uses the DebugTrackingInterceptor to track the execution of the Business Rule Engine and display it in the output window.
The following extract of output was produced by the
Business Rule Composer testing tool when testing the Loans Processing
policy from the Loans Sample in the SDK. It shows the details of the
tracked information by the DebugTrackingInterceptor.
RULE ENGINE TRACE for RULESET: LoanProcessing 5/19/2009 12:46:13 PM
FACT ACTIVITY 5/19/2009 12:46:13 PM
Rule Engine Instance Identifier: fb330399-15f0-4dc7-9137-4463a32f580e
Ruleset Name: LoanProcessing
Operation: Assert
Object Type: DataConnection:Northwind:CustInfo
Object Instance Identifier: 782
FACT ACTIVITY 5/19/2009 12:46:13 PM
Rule Engine Instance Identifier: fb330399-15f0-4dc7-9137-4463a32f580e
Ruleset Name: LoanProcessing
Operation: Assert
Object Type: TypedXmlDocument:Microsoft.Samples.BizTalk.LoansProcessor.Case
Object Instance Identifier: 778
FACT ACTIVITY 5/19/2009 12:46:13 PM
Rule Engine Instance Identifier: fb330399-15f0-4dc7-9137-4463a32f580e
Ruleset Name: LoanProcessing
Operation: Assert
Object Type: TypedXmlDocument:Microsoft.Samples.BizTalk.LoansProcessor.Case:Root
Object Instance Identifier: 777
CONDITION EVALUATION TEST (MATCH) 5/19/2009 12:46:13 PM
Rule Engine Instance Identifier: fb330399-15f0-4dc7-9137-4463a32f580e
Ruleset Name: LoanProcessing
Test Expression: NOT(TypedXmlDocument:Microsoft.Samples.BizTalk.LoansProcessor.Case:
Root.Income/BasicSalary > 0)
Left Operand Value: 12
Right Operand Value: 0
Test Result: False
CONDITION EVALUATION TEST (MATCH) 5/19/2009 12:46:13 PM
Rule Engine Instance Identifier: fb330399-15f0-4dc7-9137-4463a32f580e
Ruleset Name: LoanProcessing
Test Expression: NOT(TypedXmlDocument:Microsoft.Samples.BizTalk.LoansProcessor.Case:
Root.Income/OtherIncome > 0)
Left Operand Value: 10
Right Operand Value: 0
Test Result: False
CONDITION EVALUATION TEST (MATCH) 5/19/2009 12:46:13 PM
Rule Engine Instance Identifier: fb330399-15f0-4dc7-9137-4463a32f580e
Ruleset Name: LoanProcessing
Test Expression: TypedXmlDocument:Microsoft.Samples.BizTalk.LoansProcessor.Case:
Root.PlaceOfResidence/TimeInMonths >= 3
Left Operand Value: 15
Right Operand Value: 3
Test Result: True
[.. cut for brevity ..]
If you are testing or executing policies outside of
BizTalk or in a component consumed within BizTalk, you can specify an
alternative custom interceptor that implements the IRuleSetTrackingInterceptor interface.
Creating your custom interceptor allows you to track and log as much
information as your application requires. It allows you to step through
the rule processing and view fact details through the facts you pass to
the policy. The following code snippet demonstrates how to invoke your
custom interceptor—MyInterceptorClass.
...
xmlDocument = IncomingXMLMessage.XMLCase;
typedXmlDocument = new
Microsoft.RuleEngine.TypedXmlDocument("Microsoft.Samples.BizTalk.LoansProcessor.
Case",xmlDocument);
policy = new Microsoft.RuleEngine.Policy("LoanProcessing");
policy.Execute(typedXmlDocument,new MyInterceptorClass());
OutgoingXMLMessage.XMLCase = xmlDocument;
policy.Dispose();
...
The RuleTesterApp project accompanying this book
implements a simple rule testing tool. The tool's user interface allows
the user to load XML policy definitions, specify the destination trace
output file, and then execute those policies. To experiment with your
own custom tracking interceptor, instantiate your interceptor in the
method FireRule RulesTesterFrm class on line 267 instead of the current instantiation of the DebugTrackingInterceptor.
...
// Change the following line to instantiate your own custom Tracking Interceptor
DebugTrackingInterceptor dti = new DebugTrackingInterceptor(traceFileName);
try
{
for( int i = 0 ; i < policies.Length; i++ )
{
string PolicyName = policies[i].Trim();
lblProcessing.Text = PolicyName;
ProcessingTxtBx.Text = ProcessingTxtBx.Text + "Processing ... " + policies[i]
+ " " + DateTime.Now + "\r\n";
Application.DoEvents();
Microsoft.RuleEngine.Policy tstPolicy = new
Microsoft.RuleEngine.Policy(PolicyName);
ArrayList shortTermFacts = null;
shortTermFacts =GetFacts(PolicyName);
shortTermFacts.Add(doc1);
// Change the following line to pass in your own custom Tracking Interceptor
// to the rule set Execute method
tstPolicy.Execute(shortTermFacts.ToArray(), dti);
tstPolicy = null;
}
}
...