public async Task GreetingHandler_Should_Return_Correct_Greeting()
        {
            personRepository.GetPersonName(Arg.Any <int>()).Returns("John");
            var request = new GreetingsRequest {
                PersonId = 1
            };

            var response = await greetingHandler.Handle(request, CancellationToken.None);

            response.Greeting.Should().Be("Hello John");
        }
示例#2
0
        public async Task <ActionResult <string> > GetGreeting(int personId)
        {
            try
            {
                var request = new GreetingsRequest {
                    PersonId = personId
                };
                var response = await mediator.Send(request);

                return(Ok(response.Greeting));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public static async Task <string> RunOrchestrator(
            [OrchestrationTrigger] DurableOrchestrationContext context, ILogger log)
        {
            log.LogInformation($"************** RunOrchestrator method executing ********************");

            GreetingsRequest greetingsRequest = context.GetInput <GreetingsRequest>();

            // Fanning out
            log.LogInformation($"************** Fanning out ********************");
            var parallelActivities = new List <Task <string> >();

            foreach (var greeting in greetingsRequest.Greetings)
            {
                // Start a new activity function and capture the task reference
                Task <string> task = context.CallActivityAsync <string>("FanOutIn_ActivityFunction", greeting);

                // Store the task reference for later
                parallelActivities.Add(task);
            }

            // Wait until all the activity functions have done their work
            log.LogInformation($"************** 'Waiting' for parallel results ********************");
            await Task.WhenAll(parallelActivities);

            log.LogInformation($"************** All activity functions complete ********************");

            // Now that all parallel activity functions have completed,
            // fan in AKA aggregate the results, in this case into a single
            // string using a StringBuilder
            log.LogInformation($"************** fanning in ********************");
            var sb = new StringBuilder();

            foreach (var completedParallelActivity in parallelActivities)
            {
                sb.AppendLine(completedParallelActivity.Result);
            }

            return(sb.ToString());
        }