コード例 #1
0
        public void WhenActivityWithMultipleDelayIsRunAsyncCancelationTokenCanCancel()
        {
            const string WaitForBookmarkName = "TestBookmark";

            // The WorkflowRuntime is not aware of the cancellation token and will not cancel the workflow
            // The WorkflowEpisode will cancel when the workflow becomes idle
            var workflowApplication =
                new WorkflowApplication(
                    new Sequence
                        {
                            Activities =
                                {
                                    new Delay { Duration = TimeSpan.FromMilliseconds(100) },
                                    new Delay { Duration = TimeSpan.FromMilliseconds(100) },
                                    new Delay { Duration = TimeSpan.FromMilliseconds(100) },
                                    new TestBookmark<int> { BookmarkName = WaitForBookmarkName }
                                }
                        });

            var tokenSource = new CancellationTokenSource();

            // Run the activity
            var task = workflowApplication.RunEpisodeAsync(WaitForBookmarkName, tokenSource.Token);

            // Immediately cancel
            tokenSource.Cancel();

            // Exception is thrown when Wait() or Result is accessed
            AssertHelper.Throws<TaskCanceledException>(task);
        }
コード例 #2
0
        public void WhenNoBookmarksAndOutArgRunAsyncShouldCompleteWithOutArgs()
        {
            const int Expected = 1;
            var workflowApplication = new WorkflowApplication(new EchoArg<int> { Value = Expected });

            var task = workflowApplication.RunEpisodeAsync(Constants.Timeout);

            Assert.IsNotNull(task);
            var result = task.Result;

            Assert.IsInstanceOfType(result, typeof(WorkflowCompletedEpisodeResult));

            var completedResult = (WorkflowCompletedEpisodeResult)result;
            Assert.IsNotNull(completedResult);
            Assert.AreEqual(ActivityInstanceState.Closed, completedResult.State);
            AssertOutArgument.AreEqual(completedResult.Outputs, "Result", Expected);
        }
コード例 #3
0
        public void WhenActivityWithBookmarkGoesIdleRunAsyncShouldReturnWorkflowIdleEpisodeResult()
        {
            var workflowApplication = new WorkflowApplication(new TestBookmark<int> { BookmarkName = "Test" });

            var result = workflowApplication.RunEpisodeAsync("Test", Constants.Timeout).Result;

            Assert.IsInstanceOfType(result, typeof(WorkflowIdleEpisodeResult));

            var idleEpisodeResult = (WorkflowIdleEpisodeResult)result;
            Assert.AreEqual(ActivityInstanceState.Executing, idleEpisodeResult.State);
            Assert.AreEqual(1, idleEpisodeResult.IdleArgs.Bookmarks.Count);
        }
コード例 #4
0
        public void WhenActivityWithBookmarkAndPersistenceGoesIdleRunAsyncShouldReturnWorkflowIdleEpisodeResult()
        {
            var activity = new TestBookmark<int> { BookmarkName = "Test" };
            var workflowApplication = new WorkflowApplication(activity) { InstanceStore = new MemoryStore() };

            var result = workflowApplication.RunEpisodeAsync("Test", Constants.Timeout).Result;

            Assert.IsInstanceOfType(result, typeof(WorkflowIdleEpisodeResult));

            var completedResult = (WorkflowIdleEpisodeResult)result;
            Assert.AreEqual(ActivityInstanceState.Executing, completedResult.State);
            Assert.AreEqual(1, completedResult.IdleArgs.Bookmarks.Count);
        }
コード例 #5
0
        public void WhenActivityThrowsRunShouldThrowAggregateWithInnerSetToTerminatingException()
        {
            var workflowApplication =
                new WorkflowApplication(
                    new Throw { Exception = new InArgument<Exception>(ctx => new InvalidOperationException()) });

            AssertHelper.Throws<InvalidOperationException>(workflowApplication.RunEpisodeAsync(Constants.Timeout));
        }
コード例 #6
0
        public void WhenActivityThrowsAndUnhandledTerminateRequestedEpisodeShouldTerminate()
        {
            var workflowApplication =
                new WorkflowApplication(
                    new Throw { Exception = new InArgument<Exception>(ctx => new InvalidOperationException()) });

            AssertHelper.Throws<InvalidOperationException>(
                workflowApplication.RunEpisodeAsync(UnhandledExceptionAction.Terminate));
        }
コード例 #7
0
        public void WhenActivityGoesIdleEpisodeContinuesUntilTrackingReportsActivityState()
        {
            const string WaitForBookmarkName = "TestBookmark";

            var workflowApplication =
                new WorkflowApplication(
                    new Sequence
                        {
                            Activities =
                                {
                                    new Delay { Duration = TimeSpan.FromMilliseconds(1) },
                                    new Delay { Duration = TimeSpan.FromMilliseconds(1) },
                                    new Delay { Duration = TimeSpan.FromMilliseconds(1) },
                                    new TestBookmark<int> { BookmarkName = WaitForBookmarkName }
                                }
                        });

            // Run through three idle events and end the episode when idle with a bookmark "TestBookmark"
            var result = workflowApplication.RunEpisodeAsync(WaitForBookmarkName, Constants.Timeout).Result;

            Assert.IsInstanceOfType(result, typeof(WorkflowIdleEpisodeResult));
            Assert.AreEqual(ActivityInstanceState.Executing, result.State);
        }