public void AnyActivityInstanceStateFindsClosed()
        {
            // Arrange
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act
                var any = tracking.Records.Any(ActivityInstanceState.Closed);

                // Assert
                Assert.IsTrue(any);
            }
            finally
            {
                tracking.Trace();
            }
        }
        public void InvokeWithExtensions()
        {
            var childActivity = new TestActivityWithExtensions();
            var target = new InvokeWorkflow();
            var incStore = new IncrementStore();
            var decStore = new DecrementStore();

            var extensions = new object[] { incStore, decStore };

            dynamic innerInput = new WorkflowArguments();
            innerInput.Num = 3;

            dynamic input = new WorkflowArguments();
            input.Activity = childActivity;
            input.Input = innerInput;
            input.Extensions = extensions;

            // inner dictionary gets passed to child
            var host = WorkflowInvokerTest.Create(target);

            try
            {
                host.TestActivity(input);
                Assert.AreEqual(4, incStore.Value);
                Assert.AreEqual(2, decStore.Value);
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
Esempio n. 3
0
        public void DelayUntilTimeNowPlus1Day1Sec()
        {
            DateTime until;

            DateTime.TryParse(DateTime.Now.ToShortTimeString(), out until);

            var days = new List<DayOfWeek>
                {
                   DateTime.Now.AddDays(1).DayOfWeek, DateTime.Now.DayOfWeek, DateTime.Now.AddDays(-1).DayOfWeek
                };

            var activity = new DelayUntilTime { OccurenceDays = days };
            dynamic input = new WorkflowArguments();
            input.Time = DateTime.Now.AddSeconds(1).TimeOfDay;

            var host = new WorkflowInvokerTest(activity);

            try
            {
                host.TestActivity(input, Constants.Timeout);

                host.Tracking.Assert.Exists(
                    "DelayUntilTime", ActivityInstanceState.Closed, "DelayUntilTime activity failed to close");
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
        public void WorkflowArgumentsCanPassToWorkflowApplication()
        {
            // Arrange
            var activity = new ArgTest();
            dynamic input = new WorkflowArguments();
            dynamic output = null;
            var completed = new AutoResetEvent(false);
            // Act
            input.Num1 = 2;
            input.Num2 = 3;

            var host = new WorkflowApplication(activity, input);
            host.Completed += args =>
                {
                    output = WorkflowArguments.FromDictionary(args.Outputs);
                    completed.Set();
                };

            host.Run();

            // Wait for complete
            Assert.IsTrue(completed.WaitOne(1000));

            // Assert
            Assert.AreEqual(5, output.Result);
        }
 public void ArgumentsOverloadShouldPassViaStatic()
 {
     const string UserName = "******";
     var expectedGreeting = string.Format("Hello {0} from Workflow 4", UserName);
     dynamic arguments = new WorkflowArguments();
     arguments.UserName = UserName;
     var target = WorkflowInvokerTest.Create(new SayHello(), arguments);
     target.TestActivity();
     Assert.AreEqual(expectedGreeting, target.OutArguments.Greeting);
 }
Esempio n. 6
0
 public void LoadAssemblyShouldLoadAnAssembly()
 {
     var activity = new LoadAssembly();
     var host = WorkflowInvokerTest.Create(activity);
     dynamic arguments = new WorkflowArguments();
     arguments.Path = "ActivityLibrary.dll";
     try
     {
         host.TestActivity(arguments);
         Assert.IsNotNull(host.OutArguments.Assembly);
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
        public void AddToDictionaryShouldAddRefType()
        {
            const string ExpectedKey = "key";
            const string ExpectedValue = "value";
            var dictionary = new Dictionary<string, string>();
            var activity = new AddToDictionary<string, string>();
            var host = new WorkflowInvokerTest(activity);
            dynamic input = new WorkflowArguments();
            input.Dictionary = dictionary;
            input.Key = ExpectedKey;
            input.Value = ExpectedValue;

            try
            {
                host.TestActivity(input);

                Assert.AreEqual(1, dictionary.Count);
                Assert.AreEqual(ExpectedValue, dictionary[ExpectedKey]);
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
        public void WhereActivityInstanceStateFindsClosed()
        {
            // Arrange
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act
                var query = tracking.Records.Where(ActivityInstanceState.Closed);

                // Assert
                var list = query.ToList();
                Assert.AreEqual(4, list.Count());
                Assert.IsFalse(
                    list.Any(record => record != null && record.GetInstanceState() != ActivityInstanceState.Closed),
                    "Found record where the state is not closed");
            }
            finally
            {
                tracking.Trace();
            }
        }
        public void WorkflowArgumentsCanPassToWorkflowInvoker()
        {
            // Arrange
            var activity = new ArgTest();
            dynamic input = new WorkflowArguments();

            // Act
            input.Num1 = 2;
            input.Num2 = 3;

            var output = WorkflowArguments.FromDictionary(WorkflowInvoker.Invoke(activity, input));

            // Assert
            Assert.AreEqual(5, output.Result);
        }
        public void WhereDisplayNameMatch()
        {
            // Arrange
            const string DisplayName = "AddToNumOrThrow";
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act
                var query = tracking.Records.Where(ActivityInstanceState.Executing, DisplayName);

                // Assert
                var list = query.ToList();
                Assert.AreEqual(1, list.Count());
                var activityStateRecord = list.FirstOrDefault();
                Assert.IsNotNull(activityStateRecord);
                Assert.AreEqual(DisplayName, activityStateRecord.Activity.Name);
                Assert.AreEqual(ActivityInstanceState.Executing, activityStateRecord.GetInstanceState());
            }
            finally
            {
                tracking.Trace();
            }
        }
        public void WorkflowArgumentsThrowIfInvalid()
        {
            // Arrange
            var activity = new ArgTest();
            dynamic input = new WorkflowArguments();

            // Act
            input.Num1 = 2;
            input.Num2 = 3;
            input.DoesNotExist = "This will cause an exception";

            // Assert
            AssertHelper.Throws<ArgumentException>(() => WorkflowInvoker.Invoke(activity, input));
        }
        public void WithArgumentValueMatch()
        {
            // Arrange
            const string DisplayName = "AddToNumOrThrow";
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act
                var query = tracking.Records.OfType<ActivityStateRecord>().WithArgument("Num", 2);

                // Assert
                var list = query.ToList();
                Assert.AreEqual(2, list.Count());
                var first = list.First();
                Assert.IsNotNull(first);
                Assert.AreEqual(DisplayName, first.Activity.Name);
                Assert.AreEqual(ActivityInstanceState.Executing, first.GetInstanceState());
                var last = list.Last();
                Assert.IsNotNull(last);
                Assert.AreEqual(DisplayName, last.Activity.Name);
                Assert.AreEqual(ActivityInstanceState.Closed, last.GetInstanceState());
            }
            finally
            {
                tracking.Trace();
            }
        }
        public void LastActivityInstanceStateDoesNotFindFaulted()
        {
            // Arrange
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            host.RunEpisode();

            // Act / Assert
            AssertHelper.Throws<InvalidOperationException>(() => tracking.Records.Last(ActivityInstanceState.Faulted));
        }
        public void WhereActivityInstanceStateDoesNotFindFaulted()
        {
            // Arrange
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act
                var query = tracking.Records.Where(ActivityInstanceState.Faulted);

                // Assert
                Assert.AreEqual(0, query.Count());
            }
            finally
            {
                tracking.Trace();
            }
        }
 public void GetFromDictionaryReturnTrueWhenGetWithGoodKey()
 {
     const string ExpectedKey = "key";
     const string ExpectedValue = "value";
     var dictionary = new Dictionary<string, string> { { ExpectedKey, ExpectedValue } };
     var activity = new GetFromDictionary<string, string>();
     var host = new WorkflowInvokerTest(activity);
     dynamic input = new WorkflowArguments();
     input.Dictionary = dictionary;
     input.Key = ExpectedKey;
     try
     {
         host.TestActivity(input);
         host.AssertOutArgument.IsTrue("Result");
         host.AssertOutArgument.AreEqual("Value", ExpectedValue);
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
        public void FirstOrDefaultActivityInstanceStateDoesNotFindFaulted()
        {
            // Arrange
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            host.RunEpisode();

            // Act
            var record = tracking.Records.FirstOrDefault(ActivityInstanceState.Faulted);

            // Assert
            Assert.IsNull(record);
        }
 public void ValueExistsInDictionaryReturnTrueWhenValueExists()
 {
     const string ExpectedKey = "key";
     const string ExpectedValue = "value";
     var dictionary = new Dictionary<string, string> { { ExpectedKey, ExpectedValue } };
     var activity = new ValueExistsInDictionary<string, string>();
     var host = new WorkflowInvokerTest(activity);
     dynamic input = new WorkflowArguments();
     input.Dictionary = dictionary;
     input.Value = ExpectedValue;
     try
     {
         host.TestActivity(input);
         host.AssertOutArgument.IsTrue("Result");
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
        public void FirstActivityInstanceStateFindsClosed()
        {
            // Arrange
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act
                var record = tracking.Records.First(ActivityInstanceState.Closed);

                // Assert
                Assert.IsNotNull(record);
                Assert.AreEqual(ActivityInstanceState.Closed, record.GetInstanceState());
            }
            finally
            {
                tracking.Trace();
            }
        }
        public void WithVariableValueThrowsNegStartRecordNumber()
        {
            // Arrange
            const long StartRecordNumber = -1;
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act / Assert
                AssertHelper.Throws<ArgumentOutOfRangeException>(
                    () => tracking.Records.OfType<ActivityStateRecord>().WithVariable("BAD", 1, StartRecordNumber));
            }
            finally
            {
                tracking.Trace();
            }
        }
        public void WithVariableValueStartMatch()
        {
            // Arrange
            const string DisplayName = "Sequence";
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act
                // Find all ActivityStateRecords that have an variable named "Num" starting with record 7
                var query = tracking.Records.OfType<ActivityStateRecord>().WithVariable("VarNum", 1, 7);

                // Assert
                var list = query.ToList();
                Assert.AreEqual(1, list.Count());
                var first = list.First();
                Assert.IsNotNull(first);
                Assert.AreEqual(DisplayName, first.Activity.Name);
                Assert.AreEqual(ActivityInstanceState.Closed, first.GetInstanceState());
            }
            finally
            {
                tracking.Trace();
            }
        }
 public void AddToNullDictionaryShouldThrow()
 {
     const string ExpectedKey = "key";
     const string ExpectedValue = "value";
     var activity = new AddToDictionary<string, string>();
     var host = new WorkflowInvokerTest(activity);
     dynamic input = new WorkflowArguments();
     input.Dictionary = null;
     input.Key = ExpectedKey;
     input.Value = ExpectedValue;
     try
     {
         AssertHelper.Throws<InvalidOperationException>(() => host.TestActivity(input));
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
        public void WhereIdAndStartRecordNumber()
        {
            // Arrange
            const string Id = "1.9";
            const long StartRecordNumber = 5;
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act
                var query = tracking.Records.Where(
                    ActivityInstanceState.Executing, activityId: Id, startRecordNumber: StartRecordNumber);

                // Assert
                var list = query.ToList();
                Assert.AreEqual(1, list.Count());
                var activityStateRecord = list.FirstOrDefault();
                Assert.IsNotNull(activityStateRecord);
                Assert.AreEqual(Id, activityStateRecord.Activity.Id);
                Assert.AreEqual(ActivityInstanceState.Executing, activityStateRecord.GetInstanceState());
            }
            finally
            {
                tracking.Trace();
            }
        }
        public void ClearDictionaryShouldClear()
        {
            var dictionary = new Dictionary<string, int> { { "Key", 1 } };
            var activity = new ClearDictionary<string, int>();
            var host = new WorkflowInvokerTest(activity);
            dynamic input = new WorkflowArguments();
            input.Dictionary = dictionary;
            try
            {
                host.TestActivity(input);

                Assert.AreEqual(0, dictionary.Count);
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
        public void FirstThrowsNegStartRecordNumber()
        {
            // Arrange
            const string DisplayName = "Assign";
            const long StartRecordNumber = -1;
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act / Assert
                AssertHelper.Throws<ArgumentOutOfRangeException>(
                    () =>
                    tracking.Records.First(
                        ActivityInstanceState.Executing, DisplayName, startRecordNumber: StartRecordNumber));
            }
            finally
            {
                tracking.Trace();
            }
        }
 public void RemoveFromNullDictionaryShouldThrow()
 {
     var activity = new RemoveFromDictionary<string, string>();
     var host = new WorkflowInvokerTest(activity);
     dynamic input = new WorkflowArguments();
     input.Dictionary = null;
     input.Key = "key";
     try
     {
         AssertHelper.Throws<InvalidOperationException>(() => host.TestActivity(input));
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
        public void WhereIdNoMatchPastStartRecordNumber()
        {
            // Arrange
            const string Id = "Assign";
            const long StartRecordNumber = 9;
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act
                var query = tracking.Records.Where(
                    ActivityInstanceState.Executing, activityId: Id, startRecordNumber: StartRecordNumber);

                // Assert
                var list = query.ToList();
                Assert.AreEqual(0, list.Count());
            }
            finally
            {
                tracking.Trace();
            }
        }
 public void ValueExistsInNullDictionaryShouldThrow()
 {
     var activity = new ValueExistsInDictionary<string, string>();
     var host = new WorkflowInvokerTest(activity);
     dynamic input = new WorkflowArguments();
     input.Dictionary = null;
     input.Value = "value";
     try
     {
         AssertHelper.Throws<InvalidOperationException>(() => host.TestActivity(input));
     }
     finally
     {
         host.Tracking.Trace();
     }
 }
        public void FirstOrDefaultDisplayNameNoMatchPastStartRecordNumber()
        {
            // Arrange
            const string DisplayName = "Assign";
            const long StartRecordNumber = 9;
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act
                var record = tracking.Records.FirstOrDefault(
                    ActivityInstanceState.Executing, DisplayName, startRecordNumber: StartRecordNumber);

                // Assert
                Assert.IsNull(record);
            }
            finally
            {
                tracking.Trace();
            }
        }
Esempio n. 29
0
        public void WhenSendWithContentStubInvoked()
        {
            var xamlInjector = new XamlInjector(Constants.ActivityWithSendMessageContentXaml);
            xamlInjector.ReplaceAll(typeof(Send), typeof(SendStub));
            var sut = xamlInjector.GetActivity();
            var host = new WorkflowInvokerTest(sut);
            var stubExtension = new MessagingStubExtension();
            host.Invoker.Extensions.Add(stubExtension);

            dynamic arguments = new WorkflowArguments();
            arguments.data = "Test";
            try
            {
                host.TestActivity(arguments);

                // Shows that the SendStub activity was used
                host.Tracking.Assert.Exists("SendStub", ActivityInstanceState.Closed);
                host.Tracking.Assert.DoesNotExist("Send", ActivityInstanceState.Closed);

                Assert.AreEqual(2, stubExtension.Messages.Count);
                Assert.AreEqual("Test 1", stubExtension.Messages[0].Content);
                Assert.AreEqual("Test 2", stubExtension.Messages[1].Content);
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
        public void FirstOrDefaultIdMatch()
        {
            // Arrange
            const string Id = "1";
            var activity = new AddToNumOrThrow();
            dynamic args = new WorkflowArguments();
            args.Num = 2;
            var host = new WorkflowApplication(activity, args);
            var tracking = new ListTrackingParticipant();
            host.Extensions.Add(tracking);

            try
            {
                host.RunEpisode();

                // Act
                var record = tracking.Records.FirstOrDefault(ActivityInstanceState.Executing, activityId: Id);

                // Assert
                Assert.IsNotNull(record);
                Assert.AreEqual(ActivityInstanceState.Executing, record.GetInstanceState());
            }
            finally
            {
                tracking.Trace();
            }
        }