/// <summary>
        ///   Runs the sample service through the list of triggers
        /// </summary>
        /// <param name="address"> The host address </param>
        /// <param name="exampleTriggers"> The triggers. </param>
        private void RunSampleStateMachineService(EndpointAddress address, params ExampleTrigger[] exampleTriggers)
        {
            var proxy = new ServiceClient(ServiceTest.Pipe, address);
            var instanceId = Guid.Empty;
            try
            {
                Debug.Assert(exampleTriggers != null, "exampleTriggers != null");
                foreach (var trigger in exampleTriggers)
                {
                    switch (trigger)
                    {
                        case ExampleTrigger.T1:
                            instanceId = proxy.T1().GetValueOrDefault();
                            break;

                        case ExampleTrigger.T2:
                            proxy.T2(instanceId);
                            break;

                        case ExampleTrigger.T3:
                            proxy.T3(instanceId);
                            break;

                        case ExampleTrigger.T4:
                            proxy.T4(instanceId);
                            break;
                        case ExampleTrigger.T5:
                            proxy.T5(instanceId);
                            break;
                        case ExampleTrigger.T6:
                            proxy.T6(instanceId);
                            break;
                        case ExampleTrigger.T7:
                            proxy.T7(instanceId);
                            break;
                    }
                }

                proxy.Close();
            }
            catch (Exception)
            {
                proxy.Abort();
                throw;
            }
        }
        /// <summary>
        ///   Given
        ///   * A WorkflowService configured to use the StateMachineStateTracker
        ///   * An instance store with 2 persisted instances with state tracker information
        ///   When
        ///   * LoadInstances is called using the xamlx file
        ///   Then
        ///   * The list of StateMachineStateTracker instances is returned with 2 instances
        /// </summary>
        /// <summary>
        ///   Runs the sample service through the list of triggers
        /// </summary>
        /// <param name="testdb"> The test database </param>
        /// <param name="exampleTriggers"> The triggers. </param>
        private static void RunSampleStateMachineService(
            SqlWorkflowInstanceStoreTest testdb, params ExampleTrigger[] exampleTriggers)
        {
            Debug.Assert(testdb != null, "TestInstanceStore != null");
            var instanceStore = new SqlWorkflowInstanceStore(testdb.ConnectionString);

            WorkflowServiceTestHost host = null;
            var serviceEndpoint = ServiceTest.GetUniqueEndpointAddress();

            var proxy = new ServiceClient(ServiceTest.Pipe, serviceEndpoint);
            var instanceId = Guid.Empty;
            try
            {
                using (
                    host =
                    WorkflowServiceTestHost.Open(
                        Constants.StateMachineServiceExampleXamlx,
                        serviceEndpoint,
                        instanceStore,
                        new StateMachineTrackingBehavior(),
                        new WorkflowIdleBehavior { TimeToPersist = TimeSpan.Zero, TimeToUnload = TimeSpan.Zero }))
                {
                    Debug.Assert(exampleTriggers != null, "exampleTriggers != null");
                    foreach (var trigger in exampleTriggers)
                    {
                        switch (trigger)
                        {
                            case ExampleTrigger.T1:
                                instanceId = proxy.T1().GetValueOrDefault();
                                break;

                            case ExampleTrigger.T2:
                                proxy.T2(instanceId);
                                break;

                            case ExampleTrigger.T3:
                                proxy.T3(instanceId);
                                break;

                            case ExampleTrigger.T4:
                                proxy.T4(instanceId);
                                break;
                            case ExampleTrigger.T5:
                                proxy.T5(instanceId);
                                break;
                            case ExampleTrigger.T6:
                                proxy.T6(instanceId);
                                break;
                            case ExampleTrigger.T7:
                                proxy.T7(instanceId);
                                break;
                        }
                    }

                    proxy.Close();
                }
            }
            catch (Exception)
            {
                proxy.Abort();
                throw;
            }
            finally
            {
                if (host != null)
                {
                    Debug.Assert(host.Tracking != null, "host.Tracking != null");
                    host.Tracking.Trace();
                }
            }
        }