public void When_Handling_A_Command_Once_Only_With_Warn_Enabled() { _commandProcessor.Send(_command); _commandProcessor.Send(_command); MyStoredCommandToWarnHandler.ReceivedCount.Should().Be(1); }
public void When_Handling_A_Command_With_A_Command_Store_Enabled() { _commandProcessor.Send(_command); //should_store_the_command_to_the_command_store _commandstore.Get <MyCommand>(_command.Id, _contextKey).Value.Should().Be(_command.Value); }
public void When_Handling_A_Command_Only_Once() { _commandProcessor.Send(_command); Exception ex = Assert.Throws <OnceOnlyException>(() => _commandProcessor.Send(_command)); Assert.Equal($"A command with id {_command.Id} has already been handled", ex.Message); }
public HttpResponseMessage Delete(string name) { var deleteFeedCommand = new DeleteFeedCommand(feedName: name); commandProcessor.Send(deleteFeedCommand); return(Request.CreateResponse(HttpStatusCode.OK)); }
public HttpResponseMessage Delete(string name) { //TODO: Should support conditional DELETE based on ETag var deleteFeedCommand = new DeleteFeedCommand(feedName: name); commandProcessor.Send(deleteFeedCommand); return(Request.CreateResponse(HttpStatusCode.OK)); }
public override GreetingEvent Handle(GreetingEvent @event) { Console.WriteLine($"In the event handler for: {@event.Greeting}"); _commandProcessor.Send(new GreetingCommand(@event.Greeting, fail: false)); _commandProcessor.Send(new GreetingCommand(@event.Greeting, fail: true)); return(base.Handle(@event)); }
public void Initialise() { DailyOHLCVs = _queryProcessor.Execute(new GetDailyOHLCVsQuery(_baseCurrency, _quoteCurrency)); var newDailyOHLCVs = _queryProcessor.Execute(new FetchDailyOHLCVFromAPIQuery(_baseCurrency, _quoteCurrency, LastDailyOHLCVTime)); _commandProcessor.Send(new SaveDailyOHLCVCommand(newDailyOHLCVs)); // todo account for configuration changing over time and for different currencies _configuration = _queryProcessor.Execute(new GetPercentageOfChangeConfigurationQuery(_baseCurrency, _quoteCurrency)); }
public IActionResult Post([FromBody] TaskModel newTask) { var addTaskCommand = new AddTaskCommand( taskName: newTask.TaskName, taskDescription: newTask.TaskDescription, dueDate: DateTime.Parse(newTask.DueDate) ); _commandProcessor.Send(addTaskCommand); return(this.CreatedAtRoute("GetTask", new { id = addTaskCommand.TaskId }, null)); }
HttpResponseMessage AddFeed(string name, RestMSFeed feed) { var addFeedCommand = new AddFeedCommand( domainName: name, name: feed.Name, type: feed.Type, title: feed.Title); commandProcessor.Send(addFeedCommand); return(BuildDomainItemCreatedReponse(name)); }
public HttpResponseMessage PostJoinBetweenPipeAndFeed(string name, RestMSJoin join) { var addJoinCommand = new AddJoinToPipeCommand(name, join.Feed, join.Address); commandProcessor.Send(addJoinCommand); var retriever = new PipeRetriever(pipeRepository); var item = retriever.Retrieve(new Name(name)); var response = Request.CreateResponse(HttpStatusCode.Created, item); response.Headers.Location = new Uri(item.Href); return(response); }
public OperationResult Post(TaskModel newTask) { var addTaskCommand = new AddTaskCommand( taskName: newTask.TaskName, taskDescription: newTask.TaskDescription, dueDate: DateTime.Parse(newTask.DueDate) ); _commandProcessor.Send(addTaskCommand); return(new OperationResult.Created { RedirectLocation = new Uri(string.Format("{0}/tasks/{1}", _communicationContext.ApplicationBaseUri, addTaskCommand.TaskId)) }); }
public void When_Handling_A_Command_With_A_Command_Store_Enabled() { _commandProcessor.Send(_command); //should_store_the_command_to_the_command_store Assert.AreEqual(_command.Value, _commandstore.Get <MyCommand>(_command.Id).Value); }
public void When_Monitoring_Is_On_For_A_Handler() { _commandProcessor.Send(_command); _beforeEvent = _controlBusSender.Observe <MonitorEvent>(); _afterEvent = _controlBusSender.Observe <MonitorEvent>(); //_should_have_an_instance_name_before _beforeEvent.InstanceName.Should().Be("UnitTests"); //_should_post_the_event_type_to_the_control_bus_before _beforeEvent.EventType.Should().Be(MonitorEventType.EnterHandler); //_should_post_the_handler_fullname_to_the_control_bus_before _beforeEvent.HandlerFullAssemblyName.Should().Be(typeof(MyMonitoredHandler).AssemblyQualifiedName); //_should_post_the_handler_name_to_the_control_bus_before _beforeEvent.HandlerName.Should().Be(typeof(MyMonitoredHandler).FullName); //_should_include_the_underlying_request_details_before _beforeEvent.RequestBody.Should().Be(_originalRequestAsJson); //_should_post_the_time_of_the_request_before _beforeEvent.EventTime.AsUtc().Should().BeCloseTo(_at.AsUtc(), 1000); //_should_elapsed_before_as_zero _beforeEvent.TimeElapsedMs.Should().Be(0); //_should_have_an_instance_name_after _afterEvent.InstanceName.Should().Be("UnitTests"); //_should_post_the_handler_fullname_to_the_control_bus_after _afterEvent.EventType.Should().Be(MonitorEventType.ExitHandler); //_should_post_the_handler_fullname_to_the_control_bus_after _afterEvent.HandlerFullAssemblyName.Should().Be(typeof(MyMonitoredHandler).AssemblyQualifiedName); //_should_post_the_handler_name_to_the_control_bus_after _afterEvent.HandlerName.Should().Be(typeof(MyMonitoredHandler).FullName); //_should_include_the_underlying_request_details_after _afterEvent.RequestBody.Should().Be(_originalRequestAsJson); //should_post_the_time_of_the_request_after _afterEvent.EventTime.AsUtc().Should().BeAfter(_at.AsUtc()); }
protected void DispatchRequest(MessageHeader messageHeader, TRequest request) { _logger.Value.DebugFormat("MessagePump: Dispatching message {0} from {2} on thread # {1}", request.Id, Thread.CurrentThread.ManagedThreadId, Channel.Name); if (messageHeader.MessageType == MessageType.MT_COMMAND && request is IEvent) { throw new ConfigurationException(string.Format("Message {0} mismatch. Message type is '{1}' yet mapper produced message of type IEvent", request.Id, MessageType.MT_COMMAND)); } if (messageHeader.MessageType == MessageType.MT_EVENT && request is ICommand) { throw new ConfigurationException(string.Format("Message {0} mismatch. Message type is '{1}' yet mapper produced message of type ICommand", request.Id, MessageType.MT_EVENT)); } switch (messageHeader.MessageType) { case MessageType.MT_COMMAND: { _commandProcessor.Send(request); break; } case MessageType.MT_DOCUMENT: case MessageType.MT_EVENT: { _commandProcessor.Publish(request); break; } } }
public async Task <IActionResult> GetRequestedUserInfoAsync([FromQuery] string version) { var user = await _queryProcessor.ExecuteAsync(new GetUserQuery()); _commandProcessor.Send(new UpdateUserOnlineStatusCommand(user.Email)); return(Ok(user)); }
/// <summary> /// Handles the specified command. /// </summary> /// <param name="addMessageToFeedCommand">The command.</param> /// <returns>TRequest.</returns> public override AddMessageToFeedCommand Handle(AddMessageToFeedCommand addMessageToFeedCommand) { IEnumerable <Pipe> pipes; using (var scope = new TransactionScope()) { var feed = feedRepository[new Identity(addMessageToFeedCommand.FeedName)]; if (feed == null) { throw new FeedDoesNotExistException(); } pipes = feed.AddMessage( new Model.Message( new Address(addMessageToFeedCommand.Address), feed.Href, addMessageToFeedCommand.Headers, addMessageToFeedCommand.Attachment, !string.IsNullOrEmpty(addMessageToFeedCommand.ReplyTo) ? new Uri(addMessageToFeedCommand.ReplyTo) : null)); addMessageToFeedCommand.MatchingJoins = pipes.Count(); scope.Complete(); } pipes.Each(pipe => commandProcessor.Send(new InvalidateCacheCommand(pipe.Href))); return(base.Handle(addMessageToFeedCommand)); }
public void When_Monitoring_Is_On_For_A_Handler() { _commandProcessor.Send(_command); _beforeEvent = _controlBusSender.Observe <MonitorEvent>(); _afterEvent = _controlBusSender.Observe <MonitorEvent>(); //_should_have_an_instance_name_before Assert.AreEqual("UnitTests", _beforeEvent.InstanceName); //_should_post_the_event_type_to_the_control_bus_before Assert.AreEqual(MonitorEventType.EnterHandler, _beforeEvent.EventType); //_should_post_the_handler_fullname_to_the_control_bus_before Assert.AreEqual(typeof(MyMonitoredHandler).AssemblyQualifiedName, _beforeEvent.HandlerFullAssemblyName); //_should_post_the_handler_name_to_the_control_bus_before Assert.AreEqual(typeof(MyMonitoredHandler).FullName, _beforeEvent.HandlerName); //_should_include_the_underlying_request_details_before Assert.AreEqual(_originalRequestAsJson, _beforeEvent.RequestBody); //_should_post_the_time_of_the_request_before Assert.AreEqual(_at, _beforeEvent.EventTime); //_should_elapsed_before_as_zero Assert.AreEqual(0, _beforeEvent.TimeElapsedMs); //_should_have_an_instance_name_after Assert.AreEqual("UnitTests", _afterEvent.InstanceName); //_should_post_the_handler_fullname_to_the_control_bus_after Assert.AreEqual(MonitorEventType.ExitHandler, _afterEvent.EventType); //_should_post_the_handler_fullname_to_the_control_bus_after Assert.AreEqual(typeof(MyMonitoredHandler).AssemblyQualifiedName, _afterEvent.HandlerFullAssemblyName); //_should_post_the_handler_name_to_the_control_bus_after Assert.AreEqual(typeof(MyMonitoredHandler).FullName, _afterEvent.HandlerName); //_should_include_the_underlying_request_details_after Assert.AreEqual(_originalRequestAsJson, _afterEvent.RequestBody); //should_post_the_time_of_the_request_after Assert.Greater(_afterEvent.EventTime, _at); //should_post_the_elapsedtime_of_the_request_after Assert.AreEqual((_afterEvent.EventTime - _beforeEvent.EventTime).Milliseconds, _afterEvent.TimeElapsedMs); }
public MailOrderModule(IAmACommandProcessor messageProcessor) { Post["/mail/send"] = _ => { var request = this.Bind <SendMailRequestModel>(); try { messageProcessor.Send( new CreateSendMailOrderCommand( request.Sender, request.Destination, request.Body, request.Type, request.ScheduleAt )); } catch (MailOrderValidationException e) { Console.WriteLine(e); return(HttpStatusCode.BadRequest); } return(HttpStatusCode.OK); }; }
public void Send <T>(T command) where T : class, IRequest { if (!(command is CommandBase commandBase)) { _commandProcessor.Send(command); return; } if (!(commandBase is ISkipLogging)) { _commandQueryLogger.LogCommand(command); } commandBase.UserId = _userIdProvider.Get(); _commandProcessor.Send(command); }
public void When_A_Request_Logger_Is_In_The_Pipeline() { _commandProcessor.Send(_myCommand); //_should_log_the_request_handler_call _logger.Logs.Should().Contain(log => log.Message.Contains("Logging handler pipeline call")); //_should_log_the_type_of_handler_in_the_call _logger.Logs.Should().Contain(log => log.Message.Contains(typeof(MyCommand).ToString())); }
public void When_A_Request_Logger_Is_In_The_Pipeline() { _commandProcessor.Send(_myCommand); //_should_log_the_request_handler_call Assert.True(_logger.Logs.Any(log => log.Message.Contains("Logging handler pipeline call")), "Could not find the call to the logging pipeline"); //_should_log_the_type_of_handler_in_the_call Assert.True(_logger.Logs.Any(log => log.Message.Contains(typeof(MyCommand).ToString())), "Could not find the command in the logs"); }
public void Delete(string pipeName, string messageName) { var deleteMessageCommand = new DeleteMessageCommand( pipeName, Guid.Parse(messageName)); _commandProcessor.Send(deleteMessageCommand); Request.CreateResponse(HttpStatusCode.OK); }
private Response AddTask() { var cmd = new AddTaskCommand( Request.Form.taskName, Request.Form.taskDecription, DateTime.Parse(Request.Form.taskDueDate) ); commandProcessor.Send(cmd); return(TasksView()); }
public async Task Command_Is_Not_Stored_If_The_Handler_Is_Not_Succesful() { Guid id = Guid.NewGuid(); Catch.Exception(() => _commandProcessor.Send(new MyCommandToFail() { Id = id })); _commandStore.ExistsAsync <MyCommandToFail>(id, typeof(MyStoredCommandToFailHandlerAsync).FullName).Result.Should().BeFalse(); }
public ProductModel CreateProduct(AddProductModel newProduct) { var addProductCommand = new AddProductCommand( productName: newProduct.ProductName, productDescription: newProduct.ProductDescription, productPrice: newProduct.ProductPrice ); _commandProcessor.Send(addProductCommand); return(Get(addProductCommand.ProductId)); }
public OperationResult Post(VenueResource newVenueResource) { var addVenueCommand = new AddVenueCommand( venueName: newVenueResource.Name, address: newVenueResource.Address, mapURN: newVenueResource.MapURN, contact: newVenueResource.Contact); commandProcessor.Send(addVenueCommand); var venue = new VenueTranslator().Translate( new VenueReader(_unitOfWorkFactory, false) .Get(addVenueCommand.Id) ); return(new OperationResult.Created() { ResponseResource = venue, CreatedResourceUrl = new Uri(venue.Links[0].HRef) }); }
/// <summary> /// Handles the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns>TRequest.</returns> public override AddPipeCommand Handle(AddPipeCommand command) { var pipe = new Pipe(command.Id.ToString(), command.Type, command.Title); using (var scope = new TransactionScope()) { pipeRepository.Add(pipe); scope.Complete(); } if (pipe.Type == PipeType.Default) { //a default pipe always hasa join to the default feed. //this allows a sender to address us directly, by name commandProcessor.Send(new AddJoinToPipeCommand(pipe.Name.Value, GetDefaultFeedUri(), pipe.Name.Value)); } commandProcessor.Send(new AddPipeToDomainCommand(command.DomainName, pipe.Name.Value)); return(base.Handle(command)); }
public OrganizationCommandModule(IAmACommandProcessor commandProcessor, ICommandFactory <AddOrganizationCommand> createCommandFactory, ICommandFactory <ChangeOrganizationCommand> modifyCommandFactory) { //this.RequiresOwinAuthentication(); _commandProcessor = commandProcessor; _createCommandFactory = createCommandFactory; _modifyCommandFactory = modifyCommandFactory; Post["/Organizations"] = parameters => { var addPMCommand = _createCommandFactory.CreateCommand(this); _commandProcessor.Send(addPMCommand); return(this.CreatedResponse("/Organization", addPMCommand.OrganizationId)); }; Put["/Organizations/{OrganizationId}"] = parameters => { var changePMCommand = _modifyCommandFactory.CreateCommand(this); _commandProcessor.Send(changePMCommand); return(HttpStatusCode.OK); }; Post["/Organizations/{OrganizationId}/addresses"] = parameters => { return(HttpStatusCode.OK); }; Post["/Organizations/{OrganizationId}/ibans"] = parameters => { return(HttpStatusCode.OK); }; Delete["/Organizations/{OrganizationId}"] = parameters => { return(HttpStatusCode.OK); }; }
public void Consume(Uri uri) { _consumeFeed = true; _controlTask = Task.Factory.StartNew( () => { _logger.DebugFormat("Running Consumer loop: reading reference data."); while (_consumeFeed) { _retryPolicy.Execute(() => { foreach (var entry in _atomFeedGateway.GetFeedEntries(uri)) { _logger.Debug("Writing Reference Data change"); switch (entry.Type) { case ProductEntryType.Created: _commandProcessor.Send(new AddProductCommand(entry.ProductName, entry.ProductDescription, entry.Price)); break; case ProductEntryType.Updated: _commandProcessor.Send(new ChangeProductCommand(entry.ProductId, entry.ProductName, entry.ProductDescription, entry.Price)); break; case ProductEntryType.Deleted: _commandProcessor.Send(new RemoveProductCommand(entry.ProductId)); break; } } Task.Delay(s_delay); }); } }, TaskCreationOptions.LongRunning ); }
/// <summary> /// Handles the specified command. /// </summary> /// <param name="deleteMessageCommand">The command.</param> /// <returns>TRequest.</returns> /// <exception cref="PipeDoesNotExistException"></exception> public override DeleteMessageCommand Handle(DeleteMessageCommand deleteMessageCommand) { var pipe = pipeRepository[new Identity(deleteMessageCommand.PipeName)]; if (pipe == null) { throw new PipeDoesNotExistException(string.Format("Could not find pipe {0}", deleteMessageCommand.PipeName)); } pipe.DeleteMessage(deleteMessageCommand.MessageId); commandProcessor.Send(new InvalidateCacheCommand(pipe.Href)); return(base.Handle(deleteMessageCommand)); }
public EmailsModule(IAmACommandProcessor commandProcessor) : base("/emails") { Post["/"] = _ => { var request = this.Bind<EmailRequest>(); commandProcessor.Send( new CreateAnEmailCommand( email: new Email( id: Guid.NewGuid(), from: request.From, to: request.To, subject: request.Subject, body: request.Body))); return HttpStatusCode.OK; }; }
public TasksModule(IRetrieveTaskViewModels taskViewModelRetriever, IBuildViews<TaskViewModel, TaskView> taskViewBuilder, IAmACommandProcessor commandProcessor) { this.taskViewModelRetriever = taskViewModelRetriever; this.taskViewBuilder = taskViewBuilder; this.commandProcessor = commandProcessor; Get["/tasks/{id}"] = _ => { var viewModel = taskViewModelRetriever.Get(_.id); return taskViewBuilder.Build(viewModel); }; Delete["/tasks/{id}"] = _ => { var command = new CompleteTaskCommand(_.id, DateTime.UtcNow); commandProcessor.Send(command); return Negotiate.WithStatusCode(HttpStatusCode.OK); }; }