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 async Task Should_publish_the_completed_event() { _harness = new InMemoryTestHarness(); _activity = _harness.Activity <TestActivity, TestArguments, TestLog>(); await _harness.Start(); _completed = _harness.SubscribeHandler <RoutingSlipCompleted>(); _activityCompleted = _harness.SubscribeHandler <RoutingSlipActivityCompleted>(); _trackingNumber = NewId.NextGuid(); var builder = new RoutingSlipBuilder(_trackingNumber); builder.AddSubscription(_harness.BusAddress, RoutingSlipEvents.All); builder.AddActivity(_activity.Name, _activity.ExecuteAddress, new { Value = "Hello" }); builder.AddVariable("Variable", "Knife"); await _harness.Bus.Execute(builder.Build()); await _completed; }
public async Task ShouldRetry_WhenMessageRetryIsUsed() { try { var testActivity = new ActivityTestContext <FirstFaultyActivity, FaultyArguments, FaultyLog>( harness, () => new FirstFaultyActivity(), null, null); harness.OnConfigureBus += bus => bus.UseMessageRetry(r => r.Immediate(2)); await harness.Start(); var routingSlipCompletedHandler = ConnectPublishHandler <RoutingSlipCompleted>(harness); var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { }); await harness.Bus.Execute(builder.Build()); await routingSlipCompletedHandler; } finally { await harness.Stop(); } }
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)); }
protected override Task BuildRoutingSlip(RoutingSlipBuilder builder, ConsumeContext <CreateOrderCommand> request) { builder.AddActivity("DeductStock", new Uri($"{configuration["RabbitmqConfig:HostUri"]}/DeductStock_execute"), new DeductStockModel { ProductId = request.Message.ProductId }); builder.AddActivity("DeductBalance", new Uri($"{configuration["RabbitmqConfig:HostUri"]}/DeductBalance_execute"), new DeductBalanceModel { CustomerId = request.Message.CustomerId, Price = request.Message.Price }); builder.AddActivity("CreateOrder", new Uri($"{configuration["RabbitmqConfig:HostUri"]}/CreateOrder_execute"), new CreateOrderModel { Price = request.Message.Price, CustomerId = request.Message.CustomerId, ProductId = request.Message.ProductId }); return(Task.CompletedTask); }
public async Task Should_continue_with_the_source_itinerary() { _trackingNumber = Guid.NewGuid(); var reviseActivity = GetActivityContext <ReviseItineraryActivity>(); 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")); }
public async Task Consume(ConsumeContext <SubmitOrder> context) { var routingSlipBuilder = new RoutingSlipBuilder(NewId.NextGuid()); var activityName = nameof(SaveOrderActivity).Replace("Activity", string.Empty); var sanitizedName = KebabCaseEndpointNameFormatter.Instance.SanitizeName(activityName); routingSlipBuilder.AddActivity( activityName, new Uri($"queue:{sanitizedName}_execute"), new { context.Message.OrderId } ); var routingSlipAddress = new Uri($"rabbitmq://localhost/{KebabCaseEndpointNameFormatter.Instance.Consumer<RoutingSlipEventConsumer>()}"); routingSlipBuilder.AddSubscription( routingSlipAddress, RoutingSlipEvents.Completed ); var routingSlip = routingSlipBuilder.Build(); await context.Execute(routingSlip); if (context.RequestId != null) { await context.RespondAsync <OrderSubmissionAccepted>(new { InVar.Timestamp, context.Message.OrderId }); } }
public void Should_fail_if_not_supported() { using (var provider = new AesCryptoServiceProvider()) { provider.GenerateKey(); provider.GenerateIV(); using (ICryptoTransform encryptor = provider.CreateEncryptor()) { byte[] bytes = Encoding.UTF8.GetBytes("secret"); byte[] password = encryptor.TransformFinalBlock(bytes, 0, bytes.Length); var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddActivity("GetFile", new Uri("rabbitmq://localhost/execute_getfile"), new { Username = "******", Password = password, }); RoutingSlip routingSlip = builder.Build(); Console.WriteLine(routingSlip.ToJsonString()); } } }
public async Task Should_properly_load() { _completed = SubscribeHandler <RoutingSlipCompleted>(); _faulted = SubscribeHandler <RoutingSlipFaulted>(); _activityCompleted = SubscribeHandler <RoutingSlipActivityCompleted>(); _trackingNumber = NewId.NextGuid(); var builder = new RoutingSlipBuilder(_trackingNumber); builder.AddSubscription(Bus.Address, RoutingSlipEvents.All); ActivityTestContext testActivity = GetActivityContext <SetLargeVariableActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { Key = "Name", Value = await _repository.PutString("Frank"), }); await Bus.Execute(builder.Build()); await Task.WhenAny(_completed, _faulted); if (_faulted.IsCompleted) { Console.WriteLine(string.Join(",", _faulted.Result.Message.ActivityExceptions.Select(x => x.ExceptionInfo.Message))); } Assert.That(_completed.Status, Is.EqualTo(TaskStatus.RanToCompletion)); }
public async Task ShouldCreateOneSpans_WhenThreeRetriesAreUsedAndActivityFailsOnFirstAttempt() { try { var testActivity = new ActivityTestContext <FirstFaultyActivity, FaultyArguments, FaultyLog>( harness, () => new FirstFaultyActivity(), cfg => cfg.UseRetry(r => r.Immediate(2)), null); await harness.Start(); var routingSlipCompletedHandler = ConnectPublishHandler <RoutingSlipCompleted>(harness); var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri, new { }); await harness.Bus.Execute(builder.Build()); await routingSlipCompletedHandler; } finally { await harness.Stop(); } }
public async Task Consume(ConsumeContext <SubmitOrder> context) { LogContext.Info?.Log("Submitting Order: {OrderId}", context.Message.OrderId); using (var client = new HttpClient()) await client.GetAsync("https://www.google.com"); var builder = new RoutingSlipBuilder(NewId.NextGuid()); if (!EndpointConvention.TryGetDestinationAddress <ProcessOrderArguments>(out var activityAddress)) { throw new ConfigurationException("No endpoint address for activity"); } builder.AddActivity("Process", activityAddress); if (!EndpointConvention.TryGetDestinationAddress <OrderProcessed>(out var eventAddress)) { throw new ConfigurationException("No endpoint address for activity"); } await builder.AddSubscription(eventAddress, RoutingSlipEvents.Completed, endpoint => endpoint.Send <OrderProcessed>(context.Message)); await context.Execute(builder.Build()); await context.Publish <OrderSubmitted>(context.Message, x => x.ResponseAddress = context.ResponseAddress); }
public async Task Should_publish_the_completed_event() { Task <ConsumeContext <RoutingSlipCompleted> > completed = SubscribeHandler <RoutingSlipCompleted>(); Task <ConsumeContext <RoutingSlipActivityCompleted> > activity = SubscribeHandler <RoutingSlipActivityCompleted>(); var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddSubscription(Bus.Address, RoutingSlipEvents.All); ActivityTestContext testActivity = GetActivityContext <AddressActivity>(); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.SetVariables(new { Address = new Uri("http://google.com/"), }); await Bus.Execute(builder.Build()); await completed; var consumeContext = await activity; Assert.AreEqual(new Uri("http://google.com/"), consumeContext.Message.GetResult <string>("UsedAddress")); }
public async Task Should_complete_the_additional_item() { var trackingNumber = Guid.NewGuid(); var testActivity = GetActivityContext <TestActivity>(); var reviseActivity = GetActivityContext <ReviseItineraryActivity>(); Task <ConsumeContext <RoutingSlipCompleted> > completed = ConnectPublishHandler <RoutingSlipCompleted>(context => context.Message.TrackingNumber == trackingNumber); Task <ConsumeContext <RoutingSlipActivityCompleted> > testActivityCompleted = ConnectPublishHandler <RoutingSlipActivityCompleted>( context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(testActivity.Name)); Task <ConsumeContext <RoutingSlipActivityCompleted> > reviseActivityCompleted = ConnectPublishHandler <RoutingSlipActivityCompleted>( context => context.Message.TrackingNumber == trackingNumber && context.Message.ActivityName.Equals(reviseActivity.Name)); Task <ConsumeContext <RoutingSlipRevised> > revised = ConnectPublishHandler <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; ConsumeContext <RoutingSlipRevised> revisions = await revised; Assert.AreEqual(0, revisions.Message.DiscardedItinerary.Length); }
public async Task Should_retry_and_eventually_succeed() { var testActivity = GetActivityContext <TestActivity>(); var faultActivity = GetActivityContext <FirstFaultyActivity>(); Task <ConsumeContext <RoutingSlipCompleted> > completed = ConnectPublishHandler <RoutingSlipCompleted>(); 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 completed; }
public async Task Should_complete_the_routing_slip() { Task <ConsumeContext <RoutingSlipCompleted> > completed = SubscribeHandler <RoutingSlipCompleted>(); var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddSubscription(Bus.Address, RoutingSlipEvents.Completed); builder.AddActivity("Ping", new Uri("loopback://localhost/Ping_execute")); builder.AddActivity("PingSecond", new Uri("loopback://localhost/PingSecond_execute")); await Bus.Execute(builder.Build()); ConsumeContext <RoutingSlipCompleted> routingSlipCompleted = await completed; Assert.That(routingSlipCompleted.Message.TrackingNumber, Is.EqualTo(builder.TrackingNumber)); }
public async Task Should_continue_with_the_source_itinerary() { 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)); 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"); }
public void Setup() { _test = TestFactory.ForConsumer <ExecuteActivityHost <TestActivity, TestArguments> >() .InSingleBusScenario() .New(x => { x.ConstructUsing( () => { var compensateAddress = new Uri("loopback://localhost/mt_server"); return (new ExecuteActivityHost <TestActivity, TestArguments>( compensateAddress, new FactoryMethodExecuteActivityFactory <TestActivity, TestArguments>(_ => new TestActivity()))); }); var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity("test", new Uri("loopback://localhost/mt_client"), new { Value = "Hello", }); x.Send(builder.Build()); }); _test.Execute(); }
public void Setup() { _faulted = new TaskCompletionSource <RoutingSlipFaulted>(TestCancellationToken); _firstActivityCompleted = new TaskCompletionSource <RoutingSlipActivityCompleted>(TestCancellationToken); _firstActivityCompensated = new TaskCompletionSource <RoutingSlipActivityCompensated>(TestCancellationToken); LocalBus.SubscribeHandler <RoutingSlipFaulted>(x => _faulted.SetResult(x)); Assert.IsTrue(WaitForSubscription <RoutingSlipFaulted>()); LocalBus.SubscribeHandler <RoutingSlipActivityCompleted>(x => { if (x.ActivityName.Equals("Test")) { _firstActivityCompleted.SetResult(x); } }); Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompleted>()); LocalBus.SubscribeHandler <RoutingSlipActivityCompensated>(x => { if (x.ActivityName.Equals("Test")) { _firstActivityCompensated.SetResult(x); } }); Assert.IsTrue(WaitForSubscription <RoutingSlipActivityCompensated>()); var builder = new RoutingSlipBuilder(Guid.NewGuid()); 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"); _routingSlip = builder.Build(); LocalBus.Execute(_routingSlip); }
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); }
public static async Task EnviaLancamento(IBus bus, int conta, string desc, decimal valor) { var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddActivity("GeraLancamento", GetQueueUri(bus, ContaCorrenteQueues.ActivityQueue), new GeraLancamento(conta, valor)); builder.AddActivity("EnvioSPB", GetQueueUri(bus, SPBQueues.CommandQueue), new EnviaTransacao(conta, valor, desc)); builder.AddSubscription(GetQueueUri(bus, "routingSlipLogs"), RoutingSlipEvents.All); var routingSlip = builder.Build(); await bus.Execute(routingSlip); }
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_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_be_properly_serialized_as_a_message() { var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity("test", new Uri("loopback://localhost/mt_client"), new {}); _bus.Publish(builder.Build()); Assert.IsTrue(_received.WaitOne(8.Seconds())); }
public async Task Should_compensate_both_activities() { var builder = new RoutingSlipBuilder(Guid.NewGuid()); Task <ConsumeContext <RoutingSlipFaulted> > handled = ConnectPublishHandler <RoutingSlipFaulted>(x => x.Message.TrackingNumber == builder.TrackingNumber); var testActivity = GetActivityContext <TestActivity>(); var faultActivity = GetActivityContext <NastyFaultyActivity>(); 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; }
public void Should_properly_map_the_types() { var builder = new RoutingSlipBuilder(Guid.NewGuid()); var cmd3 = new ActivityMessageThreeCmd { Data = "Msg Three in Routing Slip." }; builder.AddActivity("ActivityMessageThreeCmd", new Uri("loopback://localhost/exec_ActivityMessageThreeCmd"), cmd3); }
public async Task Execute(ConsumeContext <IOffice365HardDeleteUserCommand> context) { var builder = new RoutingSlipBuilder(NewId.NextGuid()); var command = context.Message; builder.AddActivity(Office365ServiceConstants.ActivityHardDeleteDatabaseUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(IDeleteDatabaseUserActivity)), new { command.UserPrincipalName, WorkflowActivityType = WorkflowActivityType.Office365HardDeleteUser, WorkflowStep = WorkflowActivityStep.Office365HardDeleteDatabaseUser }); builder.AddActivity(Office365ServiceConstants.ActivityHardDeletePartnerPlatformUser, _activityConfigurator.GetActivityExecuteUri(context, typeof(IHardDeletePartnerPlatformUserActivity)), new { command.Office365CustomerId, command.UserPrincipalName, WorkflowActivityType = WorkflowActivityType.Office365HardDeleteUser, WorkflowStep = WorkflowActivityStep.Office365HardDeletePartnerPortalUser }); builder.AddSubscription(Office365ServiceConstants.QueueOffice365RoutingSlipEventUri, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted | RoutingSlipEvents.ActivityCompleted | RoutingSlipEvents.ActivityFaulted | RoutingSlipEvents.ActivityCompensated | RoutingSlipEvents.ActivityCompensationFailed); var routingSlip = builder.Build(); await context.Send <IRoutingSlipStarted>(Office365ServiceConstants.QueueOffice365RoutingSlipStartedUri, new { builder.TrackingNumber, CreateTimestamp = DateTime.UtcNow, Arguments = context.Message, WorkflowActivityType = WorkflowActivityType.Office365HardDeleteUser.ToString() }); await context.Execute(routingSlip); }
public async Task Execute(ConsumeContext <IOffice365AddAdditionalDomainCommand> context) { var builder = new RoutingSlipBuilder(NewId.NextGuid()); var command = context.Message; builder.AddActivity(Office365ServiceConstants.ActivityAddOffice365CustomerDomainToPartnerPortal, _activityConfigurator.GetActivityExecuteUri(context, typeof(IAddCustomerDomainPartnerPortalActivity)), _mapper.MapAddCustomerDomainPartnerPortalArguments(command)); builder.AddActivity(Office365ServiceConstants.ActivityAddOffice365CustomerDomainToDatabase, _activityConfigurator.GetActivityExecuteUri(context, typeof(IAddCustomerDomainToDatabaseActivity)), _mapper.MapAddCustomerDomainToDatabaseArguments(command)); builder.AddActivity(Office365ServiceConstants.ActivityGetOffice365CustomerTxtRecords, _activityConfigurator.GetActivityExecuteUri(context, typeof(IGetCustomerDomainTxtRecordsActivity)), _mapper.MapGetCustomerTxtRecords(command)); builder.AddActivity(Office365ServiceConstants.ActivitySendOffice365CustomerTxtRecords, _activityConfigurator.GetActivityExecuteUri(context, typeof(ISendCustomerDomainTxtRecordsActivity)), _mapper.MapSendCustomerTxtRecords(command)); builder.AddVariable("domain", context.Message.Domain); builder.AddVariable("workflowActivityType", WorkflowActivityType.Office365AddAdditionalDomain.ToString()); builder.AddSubscription(Office365ServiceConstants.QueueOffice365RoutingSlipEventUri, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted | RoutingSlipEvents.ActivityCompleted | RoutingSlipEvents.ActivityFaulted | RoutingSlipEvents.ActivityCompensated | RoutingSlipEvents.ActivityCompensationFailed); var routingSlip = builder.Build(); await context.Send <IRoutingSlipStarted>(Office365ServiceConstants.QueueOffice365RoutingSlipStartedUri, new { builder.TrackingNumber, CreateTimestamp = DateTime.UtcNow, Arguments = context.Message, WorkflowActivityType = WorkflowActivityType.Office365AddAdditionalDomain.ToString() }); await context.Execute(routingSlip); }
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; }
public async Task Consume(ConsumeContext <ProcessOrderPayment> context) { RoutingSlipBuilder builder = new RoutingSlipBuilder(context.Message.CommandId); builder.AddActivity("LoyaltyPayment", new Uri("loopback://localhost/loyalty-payment-execute"), new { }); builder.SetVariables(new { context.Message.Order }); await context.Execute(builder.Build()); }
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); }
public void Setup() { _faulted = new TaskCompletionSource<RoutingSlipFaulted>(TestCancellationToken); _firstActivityCompleted = new TaskCompletionSource<RoutingSlipActivityCompleted>(TestCancellationToken); _firstActivityCompensated = new TaskCompletionSource<RoutingSlipActivityCompensated>(TestCancellationToken); LocalBus.SubscribeHandler<RoutingSlipFaulted>(x => _faulted.SetResult(x)); Assert.IsTrue(WaitForSubscription<RoutingSlipFaulted>()); LocalBus.SubscribeHandler<RoutingSlipActivityCompleted>(x => { if (x.ActivityName.Equals("Test")) _firstActivityCompleted.SetResult(x); }); Assert.IsTrue(WaitForSubscription<RoutingSlipActivityCompleted>()); LocalBus.SubscribeHandler<RoutingSlipActivityCompensated>(x => { if (x.ActivityName.Equals("Test")) _firstActivityCompensated.SetResult(x); }); Assert.IsTrue(WaitForSubscription<RoutingSlipActivityCompensated>()); var builder = new RoutingSlipBuilder(Guid.NewGuid()); 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"); _routingSlip = builder.Build(); LocalBus.Execute(_routingSlip); }
public async Task Should_publish_the_faulted_routing_slip_event() { var testActivity = GetActivityContext <TestActivity>(); var faultActivity = GetActivityContext <FaultyActivity>(); Task <ConsumeContext <RoutingSlipFaulted> > handled = ConnectPublishHandler <RoutingSlipFaulted>(); Task <ConsumeContext <RoutingSlipActivityCompensated> > compensated = ConnectPublishHandler <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 void Setup() { _limit = 1; ActivityTestContext testActivity = GetActivityContext <TestActivity>(); ActivityTestContext secondActivity = GetActivityContext <SecondTestActivity>(); for (int i = 0; i < _limit; i++) { var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri); RoutingSlip routingSlip = builder.Build(); Bus.Execute(routingSlip); _sentRoutingSlips.Add(routingSlip.TrackingNumber); } }
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 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())); }
public void Should_complete_the_additional_item() { 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<ReviseItineraryActivity>(); 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 add a new item!", }); 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() { 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 Setup() { var builder = new RoutingSlipBuilder(Guid.NewGuid()); ActivityTestContext testActivity = GetActivityContext<TestActivity>(); ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>(); 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); _routingSlip = builder.Build(); Await(() => Bus.Execute(_routingSlip)); }
public void Setup() { _limit = 100; ActivityTestContext testActivity = GetActivityContext<TestActivity>(); ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>(); for (int i = 0; i < _limit; i++) { var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri); builder.AddVariable("Value", "Hello"); RoutingSlip routingSlip = builder.Build(); Bus.Execute(routingSlip); _sentRoutingSlips.Add(routingSlip.TrackingNumber); } }
public async Task Setup() { var builder = new RoutingSlipBuilder(Guid.NewGuid()); ActivityTestContext testActivity = GetActivityContext<TestActivity>(); ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>(); 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); _routingSlip = builder.Build(); await Bus.Execute(_routingSlip); Console.WriteLine("Routing slip executed"); }
public async Task Setup() { _limit = 1; ActivityTestContext testActivity = GetActivityContext<TestActivity>(); ActivityTestContext secondActivity = GetActivityContext<SecondTestActivity>(); for (int i = 0; i < _limit; i++) { var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity(testActivity.Name, testActivity.ExecuteUri); builder.AddActivity(secondActivity.Name, secondActivity.ExecuteUri); RoutingSlip routingSlip = builder.Build(); await Bus.Execute(routingSlip); _sentRoutingSlips.Add(routingSlip.TrackingNumber); } }
public void Setup() { _test = TestFactory.ForConsumer<ExecuteActivityHost<TestActivity, TestArguments>>() .InSingleBusScenario() .New(x => { x.ConstructUsing( () => { var compensateAddress = new Uri("loopback://localhost/mt_server"); return new ExecuteActivityHost<TestActivity, TestArguments>( compensateAddress, new FactoryMethodExecuteActivityFactory <TestActivity, TestArguments>(_ => new TestActivity())); }); var builder = new RoutingSlipBuilder(Guid.NewGuid()); builder.AddActivity("test", new Uri("loopback://localhost/mt_client"), new { Value = "Hello", }); x.Send(builder.Build()); }); _test.Execute(); }