Beispiel #1
0
        public void IncrementServiceShouldIncrementData()
        {
            // Arrange
            const int initialData  = 1;
            const int expectedData = 2;

            WorkflowServiceTestHost host = null;

            try
            {
                using (host = WorkflowServiceTestHost.Open("IncrementService.xamlx", serviceAddress))
                {
                    var proxy = new IncrementService.ServiceClient(binding, serviceAddress);
                    int?value = initialData;
                    proxy.Increment(ref value);
                    Assert.AreEqual(expectedData, value, "Increment did not correctly increment the value");
                }
            }
            finally
            {
                if (host != null)
                {
                    host.Tracking.Trace();
                }
            }
        }
        public void ShouldCorrelateServiceCalls()
        {
            var serviceAddress = ServiceTest.GetUniqueEndpointAddress();
            using (var host = new WorkflowServiceTestHost("ServiceWithCorrelation.xamlx", serviceAddress.Uri))
            {
                // Add an idle behavior to unload as soon as idle is detected
                host.Host.Description.Behaviors.Add(new WorkflowIdleBehavior { TimeToUnload = TimeSpan.Zero });
                host.Open();

                var client = ChannelFactory<IServiceWithCorrelation>.CreateChannel(ServiceTest.Pipe, serviceAddress);
                Trace.WriteLine("Test Client: Sending GetData(1)");
                var response = client.GetData(1);
                Assert.AreEqual("1", response.Text);

                Trace.WriteLine(string.Format("Test Client: Received GetData response {0} with key {1}", response.Text, response.Key));

                // Wait for unload
                Assert.IsTrue(host.WaitForInstanceUnloaded(2000), "Timeout waiting for instance unloaded");

                // If you want to see what is in the memory store, dump it
                // MemoryStore.Dump();
                Trace.WriteLine(string.Format("Test Client:  Sending GetMoreData(2, {0})", response.Key));
                var secondResponse = client.GetMoreData(2, response.Key);
                Assert.AreEqual("2", secondResponse.Text);

                Trace.WriteLine(string.Format("Test Client: Received GetMoreData response {0} with key {1}", secondResponse.Text, secondResponse.Key));

                host.WaitForInstanceDeleted();
                host.Close();
                MemoryStore.DisplayCommandCounts();
                host.WaitForHostClosed();

                host.Tracking.Trace();
            }
        }
        public void ShouldFaultProxyWhenLessThanZero()
        {
            var serviceAddress = ServiceTest.GetUniqueEndpointAddress();
            using (var testHost = new WorkflowServiceTestHost("TestService.xamlx", serviceAddress))
            {
                testHost.Open();
                var client = ChannelFactory<ITestService>.CreateChannel(ServiceTest.Pipe, serviceAddress);
                AssertHelper.Throws<FaultException>(() => client.GetData(-1));

                testHost.Close();
            }
        }
        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);
            }
        }