Exemple #1
0
        public void TestPersistenceWithBookmarkAndOutputs()
        {
            var bookmarkName = NewBookmarkName();
            var a            = new ReadLineReturnOrThrow()
            {
                BookmarkName = bookmarkName,
            };


            bool completed1 = false;
            bool unloaded1  = false;

            AutoResetEvent syncEvent = new AutoResetEvent(false);

            var app = new WorkflowApplication(a);

            app.InstanceStore   = WFDefinitionStore.Instance.Store;
            app.PersistableIdle = (eventArgs) =>
            {
                return(PersistableIdleAction.Unload);//so persist and unload
            };

            app.OnUnhandledException = (e) =>
            {
                return(UnhandledExceptionAction.Abort);
            };

            app.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
            {
                completed1 = true;
            };

            app.Aborted = (eventArgs) =>
            {
            };

            app.Unloaded = (eventArgs) =>
            {
                unloaded1 = true;
                syncEvent.Set();
            };

            //  app.Persist();
            var id = app.Id;

            app.Run();
            syncEvent.WaitOne();

            Assert.False(completed1);
            Assert.True(unloaded1);

            //Now to use a new WorkflowApplication to load the persisted instance.
            var dic = LoadWithBookmarkAndComplete(a, id, bookmarkName, "Something");

            Assert.Equal("SomethingABC", dic["FinalResult"]);
        }
Exemple #2
0
        public void TestPersistenceWithBookmarkAndThrowsWihoutOnUnhandledException()
        {
            var bookmarkName = NewBookmarkName();
            var a            = new ReadLineReturnOrThrow()
            {
                BookmarkName = bookmarkName,
            };


            bool completed1 = false;
            bool unloaded1  = false;

            AutoResetEvent syncEvent = new AutoResetEvent(false);

            var app = new WorkflowApplication(a);

            app.InstanceStore   = WFDefinitionStore.Instance.Store;
            app.PersistableIdle = (eventArgs) =>
            {
                return(PersistableIdleAction.Unload);//so persist and unload
            };

            app.OnUnhandledException = (e) =>
            {
                return(UnhandledExceptionAction.Abort);
            };

            app.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
            {
                unloaded1 = true;
            };

            app.Aborted = (eventArgs) =>
            {
            };

            app.Unloaded = (eventArgs) =>
            {
                unloaded1 = true;
                syncEvent.Set();
            };

            //  app.Persist();
            var id = app.Id;

            app.Run();
            syncEvent.WaitOne();

            Assert.False(completed1);
            Assert.True(unloaded1);



            bool           completed2            = false;
            bool           unloaded2             = false;
            AutoResetEvent syncEvent2            = new AutoResetEvent(false);
            IDictionary <string, object> outputs = null;

            var app2 = new WorkflowApplication(a)
            {
                Completed = e =>
                {
                    Assert.Equal(ActivityInstanceState.Faulted, e.CompletionState);// Exception thrown during resume but without exception handler, so it should be Faulted
                    Assert.NotNull(e.Outputs);
                    Assert.Equal(0, e.Outputs.Count);
                    if (e.CompletionState == ActivityInstanceState.Closed)
                    {
                        outputs = e.Outputs;
                    }
                    completed2 = true;
                },

                Unloaded = e =>
                {
                    unloaded2 = true;
                    syncEvent2.Set();
                },

                InstanceStore = WFDefinitionStore.Instance.Store,
            };

            app2.Load(id);

            app2.ResumeBookmark(bookmarkName, null); //so exception will be thrown

            syncEvent2.WaitOne();

            Assert.True(completed2);
            Assert.True(unloaded2);
            Assert.Null(outputs);
        }