Monday, June 27, 2011

Unit Tests Gone Nuts

I recently updated some code on a project that contains some unit tests. To verify that everything is working well, I executed the unit tests and they were failing but when I executed them in Debug mode - they all passed. The unit tests seem to fail only in Run mode and not in Debug mode.

I can't figure out what went wrong until I discovered this. Apparently, when Code Coverage is enabled, the assemblies don't seem to get updated after compilation. To solve the issue, disable Code Coverage and everything will work just fine.

Unit tests are some of the things that most fresh developers would complain about - labeling it being tedious and waste of time. This silly Visual Studio bug really didn't do much in helping the situation. Amazingly, it still exists in Visual Studio 2010 SP1.

Tuesday, June 07, 2011

Message Contracts in Workflow Services

The Workflow Designer in Visual Studio 2010 (even with SP1) is really good at driving developers up the wall! I was modifying my ExpenseSample Workflow to directly read a Correlation ID from my Entity and it took me almost the whole morning to figure out what's wrong!

Here's my MessageContract


    [MessageContract(IsWrapped=false)]
    public class SubmitterRequestMessage
    {
        [MessageBodyMember]
        public Expense Expense { getset; }
    }


And I went to set the CorrelatesOn property of my ReceiveActivity. It nicely gave me something like the following:
sm:body()/xg0:SubmitterRequestMessage/xg0:Expense/xg1:WorkflowID

However, when I execute my workflow, it throws an exception. As usual I have to enable WCF tracing to get pass all the useless generic WCF error messages to find out what's the problem. The error message I got was:

A correlation query yielded an empty result set. Please ensure correlation queries for the endpoint are correctly configured.

Then I found this article Troubleshooting Correlation


Turns out there is a bug in the tool which generates the wrong XPath. To fix the problem, I simply need to change it to:
sm:body()/tempuri:Expense/xg1:WorkflowID


and everything works. I don't understand why such things can happen in the best IDE on the planet. I don't understand how such thing can slip through VS's QC and I certainly don't understand why it isn't fixed in SP1.