Exemplo n.º 1
0
        public void Setup()
        {
            _completed         = new TaskCompletionSource <RoutingSlipCompleted>(TestCancellationToken);
            _activityCompleted = new TaskCompletionSource <RoutingSlipActivityCompleted>(TestCancellationToken);

            LocalBus.SubscribeHandler <RoutingSlipCompleted>(x => _completed.SetResult(x));
            Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>());

            LocalBus.SubscribeHandler <RoutingSlipActivityCompleted>(x => _activityCompleted.SetResult(x));
            Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompleted>());

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            ActivityTestContext testActivity = GetActivityContext <TestActivity>();

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello",
            });
            builder.AddVariable("Variable", "Knife");

            _routingSlip = builder.Build();

            LocalBus.Execute(_routingSlip);
        }
        public void Should_compensate_both_activities()
        {
            var handled = new ManualResetEvent(false);

            LocalBus.SubscribeHandler <RoutingSlipFaulted>(message => handled.Set());

            Assert.IsTrue(WaitForSubscription <RoutingSlipFaulted>());

            ActivityTestContext testActivity  = GetActivityContext <TestActivity>();
            ActivityTestContext faultActivity = GetActivityContext <NastyFaultyActivity>();

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello Again!",
            });
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello Again!",
            });
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri);

            LocalBus.Execute(builder.Build());

            Assert.IsTrue(handled.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
        }
        public void Should_handle_the_failed_to_compensate_event()
        {
            var handledCompensationFailure = new ManualResetEvent(false);
            var handledRoutingSlipFailure  = new ManualResetEvent(false);

            LocalBus.SubscribeHandler <RoutingSlipActivityCompensationFailed>(message => handledCompensationFailure.Set());
            LocalBus.SubscribeHandler <RoutingSlipCompensationFailed>(message => handledRoutingSlipFailure.Set());

            Assert.IsTrue(WaitForSubscription <RoutingSlipCompensationFailed>());
            Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompensationFailed>());

            ActivityTestContext testActivity             = GetActivityContext <TestActivity>();
            ActivityTestContext faultyCompensateActivity = GetActivityContext <FaultyCompensateActivity>();
            ActivityTestContext faultActivity            = GetActivityContext <FaultyActivity>();

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            builder.AddVariable("Value", "Hello");
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);
            builder.AddActivity(faultyCompensateActivity.Name, faultyCompensateActivity.ExecuteUri);
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri);

            LocalBus.Execute(builder.Build());

            Assert.IsTrue(handledRoutingSlipFailure.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
            Assert.IsTrue(handledCompensationFailure.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
        }
        public void Should_immediately_complete_an_empty_list()
        {
            Guid trackingNumber = Guid.NewGuid();

            var completed = new TaskCompletionSource <RoutingSlipCompleted>();
            var reviseActivityCompleted = new TaskCompletionSource <RoutingSlipActivityCompleted>();
            var testActivityCompleted   = new TaskCompletionSource <RoutingSlipActivityCompleted>();

            ActivityTestContext testActivity   = GetActivityContext <TestActivity>();
            ActivityTestContext reviseActivity = GetActivityContext <ReviseToEmptyItineraryActivity>();

            LocalBus.SubscribeHandler <RoutingSlipCompleted>(msg =>
            {
                if (msg.TrackingNumber == trackingNumber)
                {
                    completed.SetResult(msg);
                }
            });
            LocalBus.SubscribeHandler <RoutingSlipActivityCompleted>(msg =>
            {
                if (msg.TrackingNumber == trackingNumber)
                {
                    if (msg.ActivityName.Equals(testActivity.Name))
                    {
                        testActivityCompleted.SetResult(msg);
                    }
                    if (msg.ActivityName.Equals(reviseActivity.Name))
                    {
                        reviseActivityCompleted.SetResult(msg);
                    }
                }
            });

            Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>());
            Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompleted>());

            var builder = new RoutingSlipBuilder(trackingNumber);

            builder.AddActivity(reviseActivity.Name, reviseActivity.ExecuteUri, new
            {
                Value = "Time to remove any remaining items!",
            });
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello",
            });
            LocalBus.Execute(builder.Build());

            Assert.IsTrue(completed.Task.Wait(TestTimeout), "RoutingSlip did not complete");
            Assert.IsTrue(reviseActivityCompleted.Task.Wait(TestTimeout), "Revise Activity did not complete");

            Assert.IsFalse(testActivityCompleted.Task.Wait(3.Seconds()), "Test Activity should not have completed");
        }
        public void Should_continue_with_the_source_itinerary()
        {
            var trackingNumber = Guid.NewGuid();

            var completed = new TaskCompletionSource <RoutingSlipCompleted>();
            var reviseActivityCompleted = new TaskCompletionSource <RoutingSlipActivityCompleted>();
            var testActivityCompleted   = new TaskCompletionSource <RoutingSlipActivityCompleted>();

            ActivityTestContext testActivity   = GetActivityContext <TestActivity>();
            ActivityTestContext reviseActivity = GetActivityContext <ReviseWithNoChangeItineraryActivity>();

            LocalBus.SubscribeHandler <RoutingSlipCompleted>(msg =>
            {
                if (msg.TrackingNumber == trackingNumber)
                {
                    completed.SetResult(msg);
                }
            });
            LocalBus.SubscribeHandler <RoutingSlipActivityCompleted>(msg =>
            {
                if (msg.TrackingNumber == trackingNumber)
                {
                    if (msg.ActivityName.Equals(testActivity.Name))
                    {
                        testActivityCompleted.SetResult(msg);
                    }
                    if (msg.ActivityName.Equals(reviseActivity.Name))
                    {
                        reviseActivityCompleted.SetResult(msg);
                    }
                }
            });

            Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>());
            Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompleted>());

            var builder = new RoutingSlipBuilder(trackingNumber);

            builder.AddActivity(reviseActivity.Name, reviseActivity.ExecuteUri, new
            {
                Value = "Time to remove any remaining items!",
            });
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello",
            });
            LocalBus.Execute(builder.Build());

            Assert.IsTrue(completed.Task.Wait(TestTimeout), "RoutingSlip did not complete");
            Assert.IsTrue(reviseActivityCompleted.Task.Wait(TestTimeout), "Revise Activity did not complete");
            Assert.IsTrue(testActivityCompleted.Task.Wait(TestTimeout), "TestActivity did not complete");
        }
        public void Should_immediately_complete_an_empty_list()
        {
            var handled = new ManualResetEvent(false);

            LocalBus.SubscribeHandler <RoutingSlipCompleted>(message => { handled.Set(); });

            Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>());

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            LocalBus.Execute(builder.Build());

            Assert.IsTrue(handled.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
        }
        public void Should_work_for_activity_arguments()
        {
            _intValue     = 27;
            _stringValue  = "Hello, World.";
            _decimalValue = 123.45m;

            var completed = new TaskCompletionSource <RoutingSlipCompleted>();
            var faulted   = new TaskCompletionSource <RoutingSlipFaulted>();

            LocalBus.SubscribeHandler <RoutingSlipCompleted>(message => completed.TrySetResult(message));
            LocalBus.SubscribeHandler <RoutingSlipFaulted>(message => faulted.TrySetResult(message));

            Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>());
            Assert.IsTrue(WaitForSubscription <RoutingSlipFaulted>());

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            ActivityTestContext testActivity  = GetActivityContext <ObjectGraphTestActivity>();
            ActivityTestContext testActivity2 = GetActivityContext <TestActivity>();

            var dictionary = new Dictionary <string, object>
            {
                { "Outer", new OuterObjectImpl(_intValue, _stringValue, _decimalValue) },
                { "Names", new[] { "Albert", "Chris" } },
            };

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, dictionary);
            builder.AddActivity(testActivity2.Name, testActivity2.ExecuteUri);

            LocalBus.Execute(builder.Build());

            Assert.AreNotEqual(WaitHandle.WaitTimeout,
                               Task.WaitAny(new Task[] { completed.Task, faulted.Task }, Debugger.IsAttached
                                                                            ? 5.Minutes()
                                                                            : 30.Seconds()));

            if (faulted.Task.Status == TaskStatus.RanToCompletion)
            {
                Assert.Fail("Failed due to exception {0}", faulted.Task.Result.ActivityExceptions.Any()
                                                               ? faulted.Task.Result.ActivityExceptions.First()
                            .ExceptionInfo.Message
                                                               : "Unknown");
            }

            Assert.AreEqual(TaskStatus.RanToCompletion, completed.Task.Status, "Did not complete");
        }
        public void Should_capture_a_thrown_exception()
        {
            var handled = new ManualResetEvent(false);

            LocalBus.SubscribeHandler <RoutingSlipFaulted>(message => handled.Set());

            Assert.IsTrue(WaitForSubscription <RoutingSlipFaulted>());

            ActivityTestContext faultActivity = GetActivityContext <NastyFaultyActivity>();

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri);

            LocalBus.Execute(builder.Build());

            Assert.IsTrue(handled.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
        }
        public void Setup()
        {
            _completed = new TaskCompletionSource <RoutingSlipCompleted>(TestCancellationToken);
            _firstActivityCompleted  = new TaskCompletionSource <RoutingSlipActivityCompleted>(TestCancellationToken);
            _secondActivityCompleted = new TaskCompletionSource <RoutingSlipActivityCompleted>(TestCancellationToken);

            LocalBus.SubscribeHandler <RoutingSlipCompleted>(x => _completed.SetResult(x));
            Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>());

            LocalBus.SubscribeHandler <RoutingSlipActivityCompleted>(x =>
            {
                if (x.ActivityName.Equals("Test"))
                {
                    _firstActivityCompleted.SetResult(x);
                }
                if (x.ActivityName.Equals("SecondTest"))
                {
                    _secondActivityCompleted.SetResult(x);
                }
            });
            Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompleted>());

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            ActivityTestContext testActivity = GetActivityContext <TestActivity>();

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value     = "Hello",
                NullValue = (string)null,
            });

            testActivity = GetActivityContext <SecondTestActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);

            builder.AddVariable("Variable", "Knife");
            builder.AddVariable("Nothing", null);

            _routingSlip = builder.Build();

            LocalBus.Execute(_routingSlip);
        }
        public void Should_publish_the_completed_event()
        {
            var handled = new ManualResetEvent(false);

            LocalBus.SubscribeHandler <RoutingSlipCompleted>(message => { handled.Set(); });

            Assert.IsTrue(WaitForSubscription <RoutingSlipCompleted>());

            ActivityTestContext testActivity = GetActivityContext <TestActivity>();

            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello",
            });
            LocalBus.Execute(builder.Build());

            Assert.IsTrue(handled.WaitOne(Debugger.IsAttached ? 5.Minutes() : 30.Seconds()));
        }