public void ShouldHostService() { var trackingProfile = new TrackingProfile { Queries = { new ActivityStateQuery { ActivityName = "ReceiveRequest", States = { "Executing" }, }, new ActivityStateQuery { ActivityName = "SendResponse", States = { "Executing" }, }, } }; var xamlInjector = new XamlInjector("TestSumService.xamlx"); // The first TestActivity1 will not be replaced - will add 1 to sum // Replace the second TestActivity1 with TestActivity2 - will add 2 to sum xamlInjector.ReplaceAt(1, typeof(TestActivity1), typeof(TestActivity2)); // Replace third TestActivity1 with TestActivity3 - will add 3 to sum xamlInjector.ReplaceAt(2, typeof(TestActivity1), typeof(TestActivity3)); // Replace all (2) TestActivity4 with TestActivity5 - will add 10 to sum xamlInjector.ReplaceAll(typeof(TestActivity4), typeof(TestActivity5)); // Response will be (data=1)+1+2+3+10 = 17 var serviceAddress = ServiceTest.GetUniqueEndpointAddress(); using (var testHost = new WorkflowServiceTestHost(xamlInjector.GetWorkflowService(), serviceAddress)) { testHost.Tracking.TrackingProfile = trackingProfile; testHost.Open(); var client = ChannelFactory<ITestService>.CreateChannel(ServiceTest.Pipe, serviceAddress); var response = client.GetData(1); Assert.AreEqual("17", response); testHost.Close(); // Find the tracking records for the ReceiveRequest and SendResponse // Activity <ReceiveRequest> state is Executing AssertTracking.ExistsAt(testHost.Tracking.Records, 0, "ReceiveRequest", ActivityInstanceState.Executing); // Activity <SendResponse> state is Executing AssertTracking.ExistsAt(testHost.Tracking.Records, 1, "SendResponse", ActivityInstanceState.Executing); } }
/// <summary> /// The verify injection. /// </summary> /// <param name="xamlInjector"> /// The xaml injector. /// </param> private void VerifyInjection(XamlInjector xamlInjector) { // The first TestActivity1 will not be replaced - will add 1 to sum // Replace the second TestActivity1 with TestActivity2 - will add 2 to sum xamlInjector.ReplaceAt(1, typeof(TestActivity1), typeof(TestActivity2)); // Replace third TestActivity1 with TestActivity3 - will add 3 to sum xamlInjector.ReplaceAt(2, typeof(TestActivity1), typeof(TestActivity3)); // Replace all (2) TestActivity4 with TestActivity5 - will add 10 to sum xamlInjector.ReplaceAll(typeof(TestActivity4), typeof(TestActivity5)); // Debug.WriteLine(string.Format("Invoking Injected XAML activity {0}", activity.GetType())); var host = new WorkflowInvokerTest(xamlInjector.GetActivity()); try { // Act host.TestActivity(); // Total should be 1+2+3+10=16 host.AssertOutArgument.AreEqual("sum", 16); } finally { host.Tracking.Trace(); } }