/// <summary> /// Spawns a new test worker configurable with <paramref name="options"/>. /// </summary> /// <param name="options">The configurable options to influence the content of the test worker.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="options"/> or <paramref name="logger"/> is <c>null</c>.</exception> public static async Task <Worker> StartNewAsync(WorkerOptions options, [CallerMemberName] string memberName = null) { Guard.NotNull(options, nameof(options), "Requires a options instance that influence the test worker implementation"); Console.WriteLine("Start '{0}' integration test", memberName); IHostBuilder hostBuilder = Host.CreateDefaultBuilder(); options.ApplyOptions(hostBuilder); IHost host = hostBuilder.Build(); var worker = new Worker(host, memberName); await worker._host.StartAsync(); return(worker); }
/// <summary> /// Adds an <see cref="IEventGridPublisher"/> instance to the <paramref name="options"/>. /// </summary> /// <param name="options">The options to add the publisher to.</param> /// <param name="config">The test configuration which will be used to retrieve the Azure Event Grid authentication information.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="options"/> or the <paramref name="config"/> is <c>null</c>.</exception> public static WorkerOptions AddEventGridPublisher(this WorkerOptions options, TestConfig config) { Guard.NotNull(options, nameof(options), "Requires a set of worker options to add the Azure Event Grid publisher to"); Guard.NotNull(config, nameof(config), "Requires a test configuration instance to retrieve the Azure Event Grid authentication inforation"); options.Services.AddTransient(svc => { string eventGridTopic = config.GetTestInfraEventGridTopicUri(); string eventGridKey = config.GetTestInfraEventGridAuthKey(); return(EventGridPublisherBuilder .ForTopic(eventGridTopic) .UsingAuthenticationKey(eventGridKey) .Build()); }); return(options); }