Tracking Records not appearing after Close with WorkflowServiceTestHost

Nov 8, 2012 at 9:41 PM
Edited Nov 8, 2012 at 10:24 PM

I'm experiencing unexpected results with WorkflowServiceTestHost.

Stripped-down example code (Insert Code Snippet chokes on this):


    var service = new WorkflowService { Body = rootActivity };

    var endpointAddress = new EndpointAddress(new Uri(EndpointUri));

    using (var host = WorkflowServiceTestHost.Open(service, endpointAddress))
    {
        var client =
            ChannelFactory<IParameterizedWorkflow>.CreateChannel(
            new BasicHttpBinding(), endpointAddress);

        const string StringArgumentValue = "cow";
        const int IntArgumentValue = 42;

        client.CreateInstance(StringArgumentValue, IntArgumentValue);

        host.Close();
        host.WaitForHostClosed();

        IDictionary<string, object> variables =
        host.Tracking.Records
         .OfType<ActivityStateRecord>()
        .Single(x =>
             x.Activity.Name == RootActivityName
             && x.State == "Closed")
        .Variables;

        Assert.That(variables[StringVariableName], Is.EqualTo(StringArgumentValue));
        Assert.That(variables[IntVariableName], Is.EqualTo(IntArgumentValue));
    }

The goal is to test my custom CreateInstance activity, which is embedded in a Sequence. CreateInstance is a NativeActivity that contains a Receive and a SendReply.

This test passes if run in isolation. However, if it's run with other tests, it fails on the LINQ statement ("Sequence contains no matching element"). I can't see where it's sharing any state.

.NET 4.0, Microsoft.Activities.UnitTesting v2.0.6.9 (it failed on a much older version as well).

What do I need to do to get this test to pass reliably?

UPDATE: I've tried disposing of the client/channel, calling host.Tracking.Trace() (which at least adds visibility), and increasing the timeout on WaitForHostClosed. Apparently WaitForHostClosed is timing out. Why?

Mar 27, 2013 at 2:32 AM
I am trying to upgrade my inventory tracking system and I wonder can this tracking records method be integrated in my UPC-A barcode recording system.