private EventData[] CreateIssueReceiptEventsData()
        {
            var command = new IssueReceiptCommand
            {
                Header  = new MessageHeader(Guid.NewGuid().ToString(), nameof(IssueReceiptCommand), nameof(Sources.Orchestrator)),
                Content = new IssueReceiptCommandContent
                {
                    Transaction = new TransactionDetails
                    {
                        AccountFromId = Guid.NewGuid().ToString(),
                        AccountToId   = Guid.NewGuid().ToString(),
                        Amount        = 100.00M
                    }
                }
            };

            string serializedMsg = JsonConvert.SerializeObject(command);

            byte[] messageBytes = Encoding.UTF8.GetBytes(serializedMsg);

            return(new EventData[]
            {
                new EventData(messageBytes)
            });
        }
        public static async Task <ActivityResult <ProducerResult> > ProduceIssueReceiptCommandAsync(
            TransactionItem item, IDurableOrchestrationContext context, ILogger log)
        {
            IssueReceiptCommand command = CommandFactory.BuildIssueReceiptCommand(item);
            string functionName         = nameof(ProducerActivity.ReceiptCommandProducerActivity);

            return(await RunProducerActivityAsync(functionName, command, context, log));
        }
Пример #3
0
        public static async Task <ProducerResult> ReceiptCommandProducerActivity(
            [EventHub(@"%ReceiptEventHubName%", Connection = @"EventHubsNamespaceConnection")] IAsyncCollector <EventData> messagesCollector,
            [ActivityTrigger] IssueReceiptCommand command,
            ILogger log)
        {
            Producer producer = new Producer(messagesCollector, log);

            return(await producer.ProduceCommandWithRetryAsync(command));
        }
Пример #4
0
        public void Receipt_command_should_be_built_with_valid_payload()
        {
            var item = new TransactionItem
            {
                Id            = Guid.NewGuid().ToString(),
                AccountFromId = Guid.NewGuid().ToString(),
                AccountToId   = Guid.NewGuid().ToString(),
                Amount        = 100.00M,
                State         = SagaState.Pending.ToString()
            };

            IssueReceiptCommand issueReceiptCommand = CommandFactory.BuildIssueReceiptCommand(item);

            Assert.NotNull(issueReceiptCommand);
            Assert.Equal(issueReceiptCommand.Header.TransactionId, item.Id);
            Assert.Equal(nameof(IssueReceiptCommand), issueReceiptCommand.Header.MessageType);
            Assert.Equal(nameof(Sources.Orchestrator), issueReceiptCommand.Header.Source);
        }