Testing a WorkflowService .xamlx file with Visual Studio
One thing I have not tackled until today was how to test a Workflow Service in a .xamlx file. When I started out this morning working on it I realized that there isn’t a great deal of information about how to do this available anywhere.
Update 7/30/2010 – Download the WF4 Workflow Test Helper library for sample code
Here is what I came up with. Look at this test and tell me what you think.
using System.Activities;
using System.Activities.Tracking;
using System.ServiceModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WorkflowTestHelper.Tracking;
namespace WorkflowTestHelper.Tests
{
/// <summary>
/// This test demonstrates the WorkflowServiceTestHost class
/// </summary>
[TestClass]
public class WorkflowServiceTestHostTest
{
/// <summary>
/// The endpoint address to be used by the test host
/// </summary>
private readonly EndpointAddress _serviceAddress = new EndpointAddress("net.pipe://localhost/TestService");
/// <summary>
/// Verifies that the WorkflowServiceTestHost hosts a service and that the service receives and sends a reply
/// </summary>
/// <remarks>
/// Be sure to enable deployment - the xamlx file must be deployed
/// </remarks>
[TestMethod]
[DeploymentItem(@"WorkflowTestHelper.Tests.Activities\TestService.xamlx")]
public void ShouldHostService()
{
var trackingProfile =
new TrackingProfile
{
Queries =
{
new ActivityStateQuery
{
ActivityName = "ReceiveRequest",
States = {"Executing"},
},
new ActivityStateQuery
{
ActivityName = "SendResponse",
States = {"Executing"},
},
}
};
using (var host = WorkflowServiceTestHost.Open("TestService.xamlx", _serviceAddress.Uri, trackingProfile))
{
var client = new ServiceClient(new NetNamedPipeBinding(), _serviceAddress);
var response = client.GetData(1);
Assert.AreEqual("1", response);
host.Tracking.Trace();
// Find the tracking records for the ReceiveRequest and SendResponse
// Activity <ReceiveRequest> state is Executing
AssertTracking.ExistsAt(host.Tracking.Records, 0, "ReceiveRequest", ActivityInstanceState.Executing);
// Activity <SendResponse> state is Executing
AssertTracking.ExistsAt(host.Tracking.Records, 1, "SendResponse", ActivityInstanceState.Executing);
}
}
}
}
Comments
Anonymous
July 29, 2010
Could you provide the code? We are starting a project in WF 4.0 and we have not decided how to do the unit testing. As I see you host the xaml and contact it through wcf, but WorkflowServiceTestHost is something like Biztalk's bizmonade? I can not find it in Internet. It seems a lightweight host, but you have to provide a wcf binding. I think something like bizmonade should be the way to go. http://bizmonade.matricis.com/ RegardsAnonymous
August 02, 2010
@Pablo Sample code code.msdn.microsoft.com/wfth