public void GetExtensionsReturnsExtensionsCollection()
        {
            const string BookmarkName = "Test";

            var activity = new Sequence
                {
                    Activities =
                        {
                            new ActivityExtensionTest { AddExtensionProvider = true },
                            new TestBookmark<int> { BookmarkName = BookmarkName },
                            new ActivityExtensionTest { AddExtensionProvider = true },
                        }
                };

            var traceTrackingParticipant = new TraceTrackingParticipant();
            var listTrackingParticipant = new ListTrackingParticipant();

            var workflowApplication = new WorkflowApplication(activity);

            // Add a couple of singleton extensions
            workflowApplication.Extensions.Add(traceTrackingParticipant);
            workflowApplication.Extensions.Add(listTrackingParticipant);

            // foreach (var extension in workflowApplication.Extensions)
            // {
            // Doh! this won't work
            // foreach statement cannot operate on variables of type
            // 'System.Activities.Hosting.WorkflowInstanceExtensionManager'
            // because 'System.Activities.Hosting.WorkflowInstanceExtensionManager'
            // does not contain a public definition for 'GetEnumerator'
            // }

            // Run it so that the activity will create an extension
            workflowApplication.RunEpisode(BookmarkName, Constants.Timeout);

            // Resume and run to completion
            workflowApplication.ResumeEpisodeBookmark(BookmarkName, 1);

            // Now I can get the Singleton Extensions as a collection
            var extensions = workflowApplication.GetSingletonExtensions();
            Assert.IsNotNull(extensions);
            Assert.AreEqual(2, extensions.Count);

            // Note: Extensions created by AddDefaultExtensionProvider will not appear in the collection
            Assert.IsTrue(extensions.Contains(traceTrackingParticipant));
            Assert.IsTrue(extensions.Contains(listTrackingParticipant));

            foreach (var extension in extensions)
            {
                Debug.WriteLine("Found singleton extension " + extension);
            }
        }
        public void TraceTrackingParticipantShouldTrace()
        {
            // Arrange
            var target = new TraceTrackingParticipant();
            var host = new WorkflowApplication(new Sequence());
            host.Extensions.Add(target);
            var memoryListener = new MemoryListener();
            Trace.Listeners.Add(memoryListener);

            // Act
            host.RunEpisode();

            Assert.IsTrue(memoryListener.Records.Count > 0);
        }
        public void TraceTrackingParticipantShouldTraceOptions()
        {
            // Arrange
            var memoryListener = new MemoryListener();
            Trace.Listeners.Add(memoryListener);
            var target = new TraceTrackingParticipant(TrackingOption.All);
            var host = WorkflowApplicationTest.Create(new Sequence());
            host.Extensions.Add(target);

            // Act
            try
            {
                host.TestWorkflowApplication.RunEpisode(Constants.Timeout);

                Assert.AreEqual(5, memoryListener.Records.Count);
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
        public void WorkflowServiceHostReturnsExtensionsCollection()
        {
            var traceTrackingParticipant = new TraceTrackingParticipant();
            var listTrackingParticipant = new ListTrackingParticipant();

            var service = new WorkflowService() { Body = new Sequence() };
            var host = new WorkflowServiceHost(service);

            // Add a couple of singleton extensions
            host.WorkflowExtensions.Add(traceTrackingParticipant);
            host.WorkflowExtensions.Add(listTrackingParticipant);

            // Now I can get the Singleton Extensions as a collection
            var extensions = host.WorkflowExtensions.GetSingletonExtensions();
            Assert.IsNotNull(extensions);
            Assert.AreEqual(2, extensions.Count);

            Assert.IsTrue(extensions.Contains(traceTrackingParticipant));
            Assert.IsTrue(extensions.Contains(listTrackingParticipant));
        }