public static async Task TransferMoney( [EventHubTrigger(@"%TransferEventHubName%", Connection = @"EventHubsNamespaceConnection")] EventData[] eventsData, [EventHub(@"%ReplyEventHubName%", Connection = @"EventHubsNamespaceConnection")] IAsyncCollector <EventData> eventCollector, [CosmosDB( databaseName: @"%CosmosDbDatabaseName%", collectionName: @"%CosmosDbTransferCollectionName%", ConnectionStringSetting = @"CosmosDbConnectionString")] IAsyncCollector <CheckingAccountLine> stateCollector, ILogger logger) { IMessageProducer eventProducer = new EventHubMessageProducer(eventCollector); IRepository <CheckingAccountLine> repository = new CosmosDbRepository <CheckingAccountLine>(stateCollector); var processors = TransferServiceCommandProcessorFactory.BuildProcessorMap(eventProducer, repository); var dispatcher = new CommandProcessorDispatcher(processors); foreach (EventData eventData in eventsData) { try { var commandContainer = CommandContainerFactory.BuildCommandContainer(eventData); await dispatcher.ProcessCommandAsync(commandContainer); } catch (Exception ex) { logger.LogError(ex, ex.Message); } } }
public void Container_should_be_built_with_valid_event_data() { var command = new DefaultCommand { Header = new MessageHeader(Guid.NewGuid().ToString(), nameof(DefaultCommand), nameof(Sources.Orchestrator)), }; string serializedMsg = JsonConvert.SerializeObject(command); byte[] messageBytes = Encoding.UTF8.GetBytes(serializedMsg); var eventData = new EventData(messageBytes); var commandContainer = CommandContainerFactory.BuildCommandContainer(eventData); var newCommand = commandContainer.ParseCommand <DefaultCommand>(); Assert.NotEqual(command.Header.MessageId, newCommand.Header.MessageId); Assert.NotEqual(command.Header.CreationDate, newCommand.Header.CreationDate); Assert.Equal(command.Header.TransactionId, newCommand.Header.TransactionId); Assert.Equal(command.Header.MessageType, newCommand.Header.MessageType); Assert.Equal(command.Header.Source, newCommand.Header.Source); }