Build() публичный Метод

Builds the routing slip using the current state of the builder
public Build ( ) : RoutingSlip
Результат RoutingSlip
Пример #1
0
        public async Task Should_complete_the_additional_item()
        {
            Guid trackingNumber = Guid.NewGuid();

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

            Task<ConsumeContext<RoutingSlipCompleted>> completed =
                SubscribeHandler<RoutingSlipCompleted>(context => (context.Message.TrackingNumber == trackingNumber));

            Task<ConsumeContext<RoutingSlipActivityCompleted>> testActivityCompleted = SubscribeHandler<RoutingSlipActivityCompleted>(
                context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(testActivity.Name));

            Task<ConsumeContext<RoutingSlipActivityCompleted>> reviseActivityCompleted = SubscribeHandler<RoutingSlipActivityCompleted>(
                context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(reviseActivity.Name));

            Task<ConsumeContext<RoutingSlipRevised>> revised = SubscribeHandler<RoutingSlipRevised>(
                context => context.Message.TrackingNumber == trackingNumber);

            var builder = new RoutingSlipBuilder(trackingNumber);
            builder.AddActivity(reviseActivity.Name, reviseActivity.ExecuteUri, new
            {
                Value = "Time to add a new item!",
            });

            await Bus.Execute(builder.Build());

            await completed;
            await testActivityCompleted;
            await reviseActivityCompleted;
            
            var revisions = await revised;
            Assert.AreEqual(0, revisions.Message.DiscardedItinerary.Length);
        }
Пример #2
0
        public async Task Should_publish_the_completed_event()
        {
            var startTime = DateTime.UtcNow;

            Task<ConsumeContext<RoutingSlipCompleted>> completed = SubscribeHandler<RoutingSlipCompleted>();
            var myCompleted = SubscribeHandler<MyRoutingSlipCompleted>();

            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);
            await builder.AddSubscription(Bus.Address, RoutingSlipEvents.Completed, x => x.Send<MyRoutingSlipCompleted>(new
            {
                builder.TrackingNumber,
                SomeValue = "Hello"
            }));

            var testActivity = GetActivityContext<TestActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello"
            });

            await Bus.Execute(builder.Build());

            await completed;

            var context = await myCompleted;

            Assert.That(context.Message.Timestamp, Is.GreaterThanOrEqualTo(startTime));

            Console.WriteLine(GetBodyString(context.ReceiveContext));
        }
        public void Setup()
        {
            _faulted = SubscribeHandler<RoutingSlipFaulted>();
            _activityCompleted = SubscribeHandler<RoutingSlipActivityCompleted>(x => x.Message.ActivityName.Equals("Test"));
            _activityCompensated = SubscribeHandler<RoutingSlipActivityCompensated>(x => x.Message.ActivityName.Equals("Test"));
            _secondActivityCompleted = SubscribeHandler<RoutingSlipActivityCompleted>(x => x.Message.ActivityName.Equals("SecondTest"));
            _activityFaulted = SubscribeHandler<RoutingSlipActivityFaulted>(x => x.Message.ActivityName.Equals("Faulty"));

            _trackingNumber = NewId.NextGuid();
            var builder = new RoutingSlipBuilder(_trackingNumber);
            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello",
            });

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

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

            Await(() => Bus.Execute(builder.Build()));
        }
        public async Task Should_continue_with_the_source_itinerary()
        {
            var trackingNumber = Guid.NewGuid();

            var testActivity = GetActivityContext<TestActivity>();
            var reviseActivity = GetActivityContext<ReviseItineraryActivity>();

            Task<ConsumeContext<RoutingSlipCompleted>> completed =
                SubscribeHandler<RoutingSlipCompleted>(context => (context.Message.TrackingNumber == trackingNumber));

            Task<ConsumeContext<RoutingSlipActivityCompleted>> testActivityCompleted = SubscribeHandler<RoutingSlipActivityCompleted>(
                context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(testActivity.Name));

            Task<ConsumeContext<RoutingSlipActivityCompleted>> reviseActivityCompleted = SubscribeHandler<RoutingSlipActivityCompleted>(
                context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(reviseActivity.Name));

            var builder = new RoutingSlipBuilder(trackingNumber);
            builder.AddActivity(reviseActivity.Name, reviseActivity.ExecuteUri, new
            {
                Value = "Time to add a new item!"
            });

            await Bus.Execute(builder.Build());

            await completed;
            await reviseActivityCompleted;
            ConsumeContext<RoutingSlipActivityCompleted> testActivityResult = await testActivityCompleted;

            testActivityResult.Message.GetArgument<string>("Value").ShouldBe("Added");

            ConsumeContext<RoutingSlipActivityCompleted> consumeContext = await _handled;

            Assert.That(consumeContext.Message.GetArgument<string>("Value"), Is.EqualTo("Added"));
        }
Пример #5
0
        public async Task Should_compensate_with_the_log()
        {
            Task<ConsumeContext<RoutingSlipFaulted>> faulted = SubscribeHandler<RoutingSlipFaulted>();
            Task<ConsumeContext<RoutingSlipActivityCompleted>> activity = SubscribeHandler<RoutingSlipActivityCompleted>();
            Task<ConsumeContext<RoutingSlipActivityCompensated>> activityCompensated = SubscribeHandler<RoutingSlipActivityCompensated>();

            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            ActivityTestContext testActivity = GetActivityContext<AddressActivity>();
            ActivityTestContext faultyActivity = GetActivityContext<FaultyActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Address = new Uri("http://google.com/"),
            });
            builder.AddActivity(faultyActivity.Name, faultyActivity.ExecuteUri);

            await Bus.Execute(builder.Build());

            await faulted;

            var consumeContext = await activity;

            Assert.AreEqual(new Uri("http://google.com/"), consumeContext.Message.GetResult<string>("UsedAddress"));

            var context = await activityCompensated;

            Assert.AreEqual(new Uri("http://google.com/"), context.Message.GetResult<string>("UsedAddress"));
        }
Пример #6
0
        public async Task Should_be_properly_serialized_as_a_message()
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            builder.AddActivity("test", new Uri("loopback://localhost/execute_testactivity"), new {});

            await InputQueueSendEndpoint.Send(builder.Build());

            await _received;
        }
Пример #7
0
        public async Task Should_immediately_complete_an_empty_list()
        {
            Task<ConsumeContext<RoutingSlipCompleted>> completed = SubscribeHandler<RoutingSlipCompleted>();

            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            await Bus.Execute(builder.Build());

            await completed;
        }
Пример #8
0
        Task BeginWorkflow(ConsumeContext<IExampleEvent> exampleEvent)
        {
            return Task.Run(() =>
            {
                var builder = new RoutingSlipBuilder(NewId.NextGuid());

                builder.AddActivity(_exampleCourierActivity.ActivityName, _exampleCourierActivity.GetExecuteUri(), exampleEvent);

                RoutingSlip routingSlip = builder.Build();

                _bus.Execute(routingSlip);
            });
        }
Пример #9
0
        public async Task Should_capture_a_thrown_exception()
        {
            Task<ConsumeContext<RoutingSlipFaulted>> handled = SubscribeHandler<RoutingSlipFaulted>();

            ActivityTestContext faultActivity = GetActivityContext<NastyFaultyActivity>();

            var builder = new RoutingSlipBuilder(Guid.NewGuid());
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri);

            await Bus.Execute(builder.Build());

            await handled;
        }
Пример #10
0
        public void Setup()
        {
            var builder = new RoutingSlipBuilder(Guid.NewGuid());

            var fetchAvatarActivity = GetActivityContext<FetchAvatarActivity>();
            builder.AddActivity(fetchAvatarActivity.Name, fetchAvatarActivity.ExecuteUri);

            builder.AddVariable("EmailAddress", "*****@*****.**");
            builder.AddVariable("BookingRequestId", NewId.NextGuid());

            _routingSlip = builder.Build();

            Await(() => Bus.Execute(_routingSlip));
        }
Пример #11
0
        public void Should_serialize_properly()
        {
            var builder = new RoutingSlipBuilder(Guid.NewGuid());
            builder.AddActivity("a", new Uri("loopback://locahost/execute_a"));

            builder.AddSubscription(new Uri("loopback://localhost/events"), RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted);

            RoutingSlip routingSlip = builder.Build();

            string jsonString = routingSlip.ToJsonString();

            RoutingSlip loaded = RoutingSlipExtensions.GetRoutingSlip(jsonString);

            Assert.AreEqual(RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted, loaded.Subscriptions[0].Events);
        }
Пример #12
0
        public async Task Should_work_for_activity_arguments()
        {
            _intValue = 27;
            _stringValue = "Hello, World.";
            _decimalValue = 123.45m;

            Task<ConsumeContext<RoutingSlipCompleted>> completed = SubscribeHandler<RoutingSlipCompleted>();
            Task<ConsumeContext<RoutingSlipFaulted>> faulted = SubscribeHandler<RoutingSlipFaulted>();

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

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

            var dictionary = new Dictionary<string, object>
            {
                {"Outer", new OuterObjectImpl(_intValue, _stringValue, _decimalValue)},
                {"Names", new[] {"Albert", "Chris"}},
                {"ArgumentsDictionary", _argumentsDictionary}
            };
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, dictionary);
            builder.AddActivity(testActivity2.Name, testActivity2.ExecuteUri, new
            {
                Value = "Howdy!"
            });

            builder.AddVariable("ArgumentsDictionary", new Dictionary<string, string>
            {
                {"good_jpath_key", "val3"},
                {"bad jpath key", "val4"}
            });

            await Bus.Execute(builder.Build());

            await Task.WhenAny(completed, faulted);

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

            completed.Status.ShouldBe(TaskStatus.RanToCompletion);
        }
Пример #13
0
        public async Task Consume(ConsumeContext <TRequest> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddSubscription(context.ReceiveContext.InputAddress, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted);

            builder.AddVariable("RequestId", context.RequestId);
            builder.AddVariable("ResponseAddress", context.ResponseAddress);
            builder.AddVariable("FaultAddress", context.FaultAddress);
            builder.AddVariable("Request", context.Message);

            await BuildRoutingSlip(builder, context);

            var routingSlip = builder.Build();

            await context.Execute(routingSlip).ConfigureAwait(false);
        }
Пример #14
0
        public async Task Should_publish_the_completed_event()
        {
            Task<ConsumeContext<RoutingSlipCompleted>> completed = SubscribeHandler<RoutingSlipCompleted>();

            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello",
            });

            await Bus.Execute(builder.Build());

            await completed;
        }
        public void Should_publish_the_completed_event()
        {
            _completed = SubscribeHandler<RoutingSlipCompleted>();
            _activityCompleted = SubscribeHandler<RoutingSlipActivityCompleted>();

            _trackingNumber = NewId.NextGuid();
            var builder = new RoutingSlipBuilder(_trackingNumber);
            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello",
            });

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

            Await(() => Bus.Execute(builder.Build()));

            Await(() => _completed);
        }
Пример #16
0
        public async Task Should_publish_the_completed_event()
        {
            _completed = SubscribeHandler<RoutingSlipCompleted>();
            _activityCompleted = SubscribeHandler<RoutingSlipActivityCompleted>();

            _trackingNumber = NewId.NextGuid();
            var builder = new RoutingSlipBuilder(_trackingNumber);
            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            ActivityTestContext testActivity = GetActivityContext<SetVariableActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Key = "Test",
                Value = "Used",
            });

            builder.AddVariable("Value", "Ignored");

            await Bus.Execute(builder.Build());

            await _completed;
        }
Пример #17
0
        public async Task Should_compensate_both_activities()
        {
            Task<ConsumeContext<RoutingSlipFaulted>> handled = SubscribeHandler<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);

            await Bus.Execute(builder.Build());

            await handled;
        }
Пример #18
0
        public async Task Should_handle_the_failed_to_compensate_event()
        {
            Task<ConsumeContext<RoutingSlipActivityCompensationFailed>> handledCompensationFailure =
                SubscribeHandler<RoutingSlipActivityCompensationFailed>();
            Task<ConsumeContext<RoutingSlipCompensationFailed>> handledRoutingSlipFailure =
                SubscribeHandler<RoutingSlipCompensationFailed>();

            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);

            await Bus.Execute(builder.Build());

            await handledRoutingSlipFailure;

            await handledCompensationFailure;
        }
Пример #19
0
        public async Task Should_publish_the_faulted_routing_slip_event()
        {
            var testActivity = GetActivityContext<TestActivity>();
            var faultActivity = GetActivityContext<FaultyActivity>();

            Task<ConsumeContext<RoutingSlipFaulted>> handled = SubscribeHandler<RoutingSlipFaulted>();
            Task<ConsumeContext<RoutingSlipActivityCompensated>> compensated = SubscribeHandler<RoutingSlipActivityCompensated>(
                context => context.Message.ActivityName.Equals(testActivity.Name));

            var builder = new RoutingSlipBuilder(Guid.NewGuid());
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new
            {
                Value = "Hello"
            });
            builder.AddActivity(faultActivity.Name, faultActivity.ExecuteUri, new
            {
            });

            await Bus.Execute(builder.Build());

            await handled;

            await compensated;
        }
        public async Task BookMeeting(ConsumeContext<BookMeeting> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddActivity(_settings.ReserveRoomActivityName,
                _settings.ReserveRoomExecuteAddress, new
                {
                    ReservationApiKey = "secret"
                });

            builder.AddActivity(_settings.FetchAvatarActivityName, _settings.FetchAvatarExecuteAddress);

            builder.SetVariables(new
            {
                context.Message.EmailAddress,
                context.Message.StartTime,
                context.Message.Duration,
                context.Message.RoomCapacity
            });

            var routingSlip = builder.Build();

            await context.Execute(routingSlip);
        }
Пример #21
0
        public async Task Should_immediately_complete_an_empty_list()
        {
            Guid trackingNumber = Guid.NewGuid();

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

            Task<ConsumeContext<RoutingSlipCompleted>> completed =
                SubscribeHandler<RoutingSlipCompleted>(context => (context.Message.TrackingNumber == trackingNumber));

            Task<ConsumeContext<RoutingSlipActivityCompleted>> testActivityCompleted = SubscribeHandler<RoutingSlipActivityCompleted>(
                context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(testActivity.Name));

            Task<ConsumeContext<RoutingSlipActivityCompleted>> reviseActivityCompleted = SubscribeHandler<RoutingSlipActivityCompleted>(
                context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(reviseActivity.Name));

            Task<ConsumeContext<RoutingSlipRevised>> revised = SubscribeHandler<RoutingSlipRevised>(
                context => context.Message.TrackingNumber == trackingNumber);

            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",
            });

            await Bus.Execute(builder.Build());

            await completed;
            await reviseActivityCompleted;

            var revisions = await revised;
            Assert.AreEqual(1, revisions.Message.DiscardedItinerary.Length);
            Assert.AreEqual(0, revisions.Message.Itinerary.Length);

            testActivityCompleted.Wait(TimeSpan.FromSeconds(3)).ShouldBe(false);
        }
Пример #22
0
        static void Main()
        {
            ConfigureLogger();

            // MassTransit to use Log4Net
            Log4NetLogger.Use();

            IBusControl busControl = CreateBus();

            BusHandle busHandle = busControl.Start();

            string validateQueueName = ConfigurationManager.AppSettings["ValidateActivityQueue"];

            Uri validateAddress = _host.Settings.GetQueueAddress(validateQueueName);

            string retrieveQueueName = ConfigurationManager.AppSettings["RetrieveActivityQueue"];

            Uri retrieveAddress = _host.Settings.GetQueueAddress(retrieveQueueName);

            try
            {
                for (;;)
                {
                    Console.Write("Enter an address (quit exits): ");
                    string requestAddress = Console.ReadLine();
                    if (requestAddress == "quit")
                        break;

                    if (string.IsNullOrEmpty(requestAddress))
                        requestAddress = "http://www.microsoft.com/index.html";

                    int limit = 1;

                    if (requestAddress.All(x => char.IsDigit(x) || char.IsPunctuation(x)))
                    {
                        string[] values = requestAddress.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
                        requestAddress = values[0];
                        if (values.Length > 1)
                        {
                            limit = int.Parse(values[1]);
                            Console.WriteLine("Sending {0}", limit);
                        }
                    }

                    switch (requestAddress)
                    {
                        case "0":
                            requestAddress = "http://www.microsoft.com/index.html";
                            break;
                        case "1":
                            requestAddress = "http://i.imgur.com/Iroma7d.png";
                            break;
                        case "2":
                            requestAddress = "http://i.imgur.com/NK8eZUe.jpg";
                            break;
                    }

                    Uri requestUri;
                    try
                    {
                        requestUri = new Uri(requestAddress);
                    }
                    catch (UriFormatException)
                    {
                        Console.WriteLine("The URL entered is invalid: " + requestAddress);
                        continue;
                    }

                    IEnumerable<Task> tasks = Enumerable.Range(0, limit).Select(x => Task.Run(async () =>
                    {
                        var builder = new RoutingSlipBuilder(NewId.NextGuid());

                        builder.AddActivity("Validate", validateAddress);
                        builder.AddActivity("Retrieve", retrieveAddress);

                        builder.SetVariables(new
                        {
                            RequestId = NewId.NextGuid(),
                            Address = requestUri,
                        });

                        RoutingSlip routingSlip = builder.Build();

                        await busControl.Publish<RoutingSlipCreated>(new
                        {
                            TrackingNumber = routingSlip.TrackingNumber,
                            Timestamp = routingSlip.CreateTimestamp,
                        });

                        await busControl.Execute(routingSlip);
                    }));

                    Task.WaitAll(tasks.ToArray());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception!!! OMG!!! {0}", ex);
                Console.ReadLine();
            }
            finally
            {
                busHandle.Stop(TimeSpan.FromSeconds(30));
            }
        }
        public async Task Setup()
        {
            ActivityTestContext testActivity = GetActivityContext<TestActivity>();
            ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>();

            _completed = SubscribeHandler<RoutingSlipCompleted>();
            _firstActivityCompleted =
                SubscribeHandler<RoutingSlipActivityCompleted>(context => context.Message.ActivityName.Equals(testActivity.Name));
            _secondActivityCompleted =
                SubscribeHandler<RoutingSlipActivityCompleted>(context => context.Message.ActivityName.Equals(secondActivity.Name));

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

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

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

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

            _routingSlip = builder.Build();

            await Bus.Execute(_routingSlip);
        }