NServiceBus.AcceptanceTesting.Support.EndpointRunner.Whens C# (CSharp) Method

Whens() public method

public Whens ( CancellationToken token ) : Task
token System.Threading.CancellationToken
return Task
        public async Task Whens(CancellationToken token)
        {
            try
            {
                if (behavior.Whens.Count != 0)
                {
                    await Task.Run(async () =>
                    {
                        var executedWhens = new List<Guid>();

                        while (!token.IsCancellationRequested)
                        {
                            if (executedWhens.Count == behavior.Whens.Count)
                            {
                                break;
                            }

                            if (token.IsCancellationRequested)
                            {
                                break;
                            }

                            foreach (var when in behavior.Whens)
                            {
                                if (token.IsCancellationRequested)
                                {
                                    break;
                                }

                                if (executedWhens.Contains(when.Id))
                                {
                                    continue;
                                }

                                if (await when.ExecuteAction(scenarioContext, endpointInstance).ConfigureAwait(false))
                                {
                                    executedWhens.Add(when.Id);
                                }
                            }
                        }
                    }, token).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"Failed to execute Whens on endpoint{configuration.EndpointName}", ex);

                throw;
            }
        }

Usage Example

Example #1
0
        static async Task ExecuteWhens(EndpointRunner endpoint, CancellationTokenSource cts)
        {
            var token = cts.Token;

            try
            {
                await endpoint.Whens(token).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                cts.Cancel();
                throw new ScenarioException("Whens failed to execute", ex);
            }
        }
All Usage Examples Of NServiceBus.AcceptanceTesting.Support.EndpointRunner::Whens