Martijn's blog - E-Commerce, EAI, BizTalk and .NET

2005/10/11

Unit testing BRE policies

When Unit testing BRE policies, it might be useful to be able to declaratively define which RuleStore to use, which Policy to test and which Version to load. Using the Attributes I created, doing this become pretty simple. One of the Attributes also provides for a class Type to be instantiated implementing IRuleSetTrackingInterceptor, which allows tracking what the BRE does while executing the requested Policy. Have a look at the code, as I think it might be useful for many UnitTesting scenarios with version policies.

using it is quite simple:


using MartijnHoogendoorn.BizTalk.BRE.Testing.Attributes;

[Test]
[PolicyTester("MyPolicy", typeof(MyInterceptor))]
[RuleStore("Integrated Security=SSPI;Database=BizTalkRuleEngineDb;Server=MyRuleEngineServer", "MYDOMAIN", "myusername", "mypassword")]

private void TestMyPolicy()
{
  XmlReader reader = new XmlTextReader(@"..\..\..\MyMessage.xml");
  XmlSerializer serializer = new XmlSerializer(typeof(MyMessage));
  MyMessageClass = (MyMessageClass) serializer.Deserialize(reader);

  MyInterceptor interceptor = (MyInterceptor) PolicyTesterHelper.ExecutePolicy(new object[] { "Some interesting value", someObject });
  foreach(string eventLine in interceptor.PolicyExecutionEvents)
  {
    System.Diagnostics.Trace.WriteLine(interceptor.PolicyExecutionEvents.ToString());
  }
}

See the sample code here for a real implementation

5 Comments:

  • Hoping you can help!

    Hi there...using your new Biztalk Pipeline wizard 1.34 version. I wanted to get the "Basics" working on a custom pipeline component, and I'm still getting an error!

    I created a custom pipeline, and then created a simple xml message to pass through to the send port. On the send port, I speciified this pipeline.

    I used your wizard to create just the skeleton component. It does nothing...just returns the message.

    I then associated it with my send port.

    When I try to push a message through, I get this error.

    There was a failure executing the send pipeline: "PipeLineTest.Senddata" Source: "Microsoft.BizTalk.Messaging" Send Port: "C:\Projects\TestSystem\BizTalkProjects\Processing\OutBox\post%MessageID%.xml" Reason: AddDocument: The component "dataComponent" must implement the IAssemblerComponent interface.

    What am I doing wrong?

    By Anonymous Anonymous, at 3:56 AM  

  • Hi Mikeh,

    You selected "implement IAssemblerComponent interface" from the options when selection the class I guess. You now have a method called AddDocument, which should be implemented...

    Ping me by e-mail if you have other questions

    By Blogger Martijn Hoogendoorn, at 9:38 PM  

  • Martijn,

    Have a look at the Policy Verificatorfrom Acumen Business. This is a tool that automates the process of testing Business Rules. The tool should be able to find rule anomalies among rules, or within the premisse of a rule. The tool ships with some examples.

    I hope you like it.

    Marco

    By Blogger Ensing, at 1:20 AM  

  • I absolutely love your blog and find almost all of your post’s to be precisely what I’m looking for. Does one offer guest writers to write content in your case? I wouldn’t mind creating a post or elaborating on a lot of the subjects you write regarding here. Again, awesome site!

    By Anonymous Gadgets UK, at 9:47 AM  

  • Thanks you. Very good post.Unless they can offer a really compelling reason for users to come back, it will be the next Bebo, MySpace

    By Anonymous 10755GF, at 11:09 PM  

Post a Comment

<< Home