Changing the "object reference not set to an instance of an object" Exception in BizUnit 2.3 for Biztalk 2006

By Geert van der Cruijsen at March 04, 2008 20:49
Filed Under: Biztalk 2006

Lately I’ve been working with BizUnit 2.3 to create Unit tests for the Orchestrations we’ve build in BizTalk 2006 at our current customer.

BizUnit 2.3 is an opensource project on CodePlex (http://www.codeplex.com/bizunit ) to help you make the testing of these orchestrations easier. I’ve noticed that when you create a validation step and try to do a check with an xpath query you can get weird errors when the element you are looking for doesn’t exists.The Exception you’ll receive will be: 

 

"object reference not set to an instance of an object"

This Error doesn’t really say what is going wrong in your test report and that’s because the application isn’t throwing an ApplicationException but the code right in front of it will go wrong because checknode is null and BizUnit is trying to compare the checknode.InnerText.What I did was change the code in the XmlValidationStep.cs so it will give a nice ApplicationException when the element you are trying to check doesn’t exist in the xml file you are checking.The changes I made to the code are written down here and should be inserted into XmlValidationStep.cs in the BizUnit 2.3 project

 

string xpathExp = xpath.SelectSingleNode("@query").Value;
XmlNode valNode = xpath.SelectSingleNode(".");
string nodeValue = valNode.InnerText;
context.LogInfo("XmlValidationStep evaluting XPath {0} equals \"{1}\"", xpathExp, nodeValue );
XmlNode checkNode = null;

try
{
  checkNode = doc.SelectSingleNode(xpathExp);
}
catch
{ }
if
(checkNode != null)
{

  if
(0 != nodeValue.CompareTo(checkNode.InnerText))
  {
    throw new ApplicationException(string.Format("XmlValidationStep failed, compare {0} != {1}, xpath query used: {2}", nodeValue, checkNode.InnerText, xpathExp));
  }
}
else

{
  throw new ApplicationException(string.Format("XmlValidationStep failed, no element found, xpath query used: {0}", xpathExp));
} 

Hope this will help you understand the errors you get while testing with BizUnit on your project! 

Geert van der Cruijsen

 

 

Comments

7/26/2010 1:52:01 AM #

ohh�nice publish however actually?

Etta Vostal

7/26/2010 1:52:02 AM #

Couldnt be written any better about Biztalk 2006 . Reading this column strikes a chord in my memory of my old room mate! He always kept talking regarding this. I will forward this informative article 2 him. Pretty certain he will have a great read. Thankfulness 4 sharing!

Roslyn Zawislak

7/26/2010 6:54:22 AM #

Biztalk 2006 THIS IS ROCK SOLID.

Aurore Mohabir

7/26/2010 6:54:34 AM #

Appreciation 4 taking the time to debate Biztalk 2006, I feel strongly regarding it and love learning more on this matter. If likely, since you gain expertise, would you mind updating your webpage with more information? Extremely helpful 4 me.

Daron Toczek

7/27/2010 12:22:35 AM #

I should in reality be working

Malisa Andruszkiewic

7/27/2010 12:22:36 AM #

Biztalk 2006 Biztalk 2006 Biztalk 2006 Do you agree to guest posts? I would love to write down pair articles here.

Henry Sonkin

7/27/2010 5:21:42 AM #

pls more photoes

Wendy Hirtz

7/27/2010 5:21:44 AM #

go figure lol|Smile}

Johnathan Lenior

7/30/2010 5:05:41 AM #

Biztalk 2006 THIS IS ROCK SOLID.

Moriah Bushweller

Add comment



biuquote
Loading