Last week I ran into a really interesting issue. When I was running Visual Studio unit tests to validate instances of XML formatted EDIFact messages (see my previous blog post on BizTalk testing for more details on schema testing) I found that my tests just seemed to take forever and timed out with no reason provided.
I decided to apply a break point in my unit test and debugged it. Much to my surprise when I stepped into the line of code that was actually validating the instance file I saw the below.
Well, that’s really painful. The unit test was timing out because it was waiting for user input on the above screen, however unless the test was being run in debug mode the screen was not being displayed at all.
So far I haven’t found any way to get the out of the box ValidateInstance method to work on EDIFact schemas because I can’t supress the above screen. Interestingly enough, if the instance file actually fails validation then the test will fail rather than time out. Another alternative I explored was to use some non standard test methods to test instances of EDIFact messages against my schemas. In my previous blog post discussing BizTalk unit testing I mentioned that I regularly use non standard methods to extend my schema unit tests anyways since the out of the box ValidateInstance method doesn’t return an error message upon failure, and it also doesn’t work when your schemas import/include from other schemas. I chose to use only these extension methods (as described here), bypassing the out of the box testing methods altogether and the tests now complete succesfully. Note that in the below screenshot the TestExtensions.ValidateSchema method contains an extension method as described here.