/// <summary> /// Prepares the <see cref="ExecutionContext"/> using the specified <paramref name="username"/>, whilst also ensuring that the <see cref="LocalServiceProvider"/> scope is correctly configured. /// </summary> /// <param name="username">The username (<c>null</c> indicates to use the <see cref="TestSetUp.DefaultUsername"/>).</param> /// <param name="args">Optional argument that will be passed into the creation of the <see cref="ExecutionContext"/> (via the <see cref="TestSetUp.CreateExecutionContext"/> function).</param> /// <returns>The <see cref="AgentTesterWaf{TStartup}"/> instance to support fluent/chaining usage.</returns> /// <remarks>The <see cref="ExecutionContext"/> must be created by the <see cref="AgentTesterBase"/> as the <see cref="ExecutionContext.ServiceProvider"/> must be set to <see cref="LocalServiceProvider"/>.</remarks> public void PrepareExecutionContext(string?username, object?args = null) { ExecutionContext.Reset(); var ec = TestSetUp.CreateExecutionContext(username ?? TestSetUp.DefaultUsername, args); ec.ServiceProvider = LocalServiceProvider; ExecutionContext.SetCurrent(ec); }
/// <summary> /// Prepares the <see cref="ExecutionContext"/> using the <see cref="TestSetUpAttribute"/> configuration, whilst also ensuring that the <see cref="LocalServiceProvider"/> scope is correctly configured. /// </summary> public void PrepareExecutionContext() { ExecutionContext.Reset(); var ec = TestSetUp.CreateExecutionContext(TestSetUpAttribute.Username, TestSetUpAttribute.Args); ec.ServiceProvider = LocalServiceProvider; ExecutionContext.SetCurrent(ec); }
/// <summary> /// Prepares the <see cref="ExecutionContext"/> using the specified <paramref name="username"/>, whilst also ensuring that the <see cref="LocalServiceProvider"/> scope is correctly configured. /// </summary> /// <param name="username">The username (<c>null</c> indicates to use the <see cref="TestSetUp.DefaultUsername"/>).</param> /// <param name="args">Optional argument that will be passed into the creation of the <see cref="ExecutionContext"/> (via the <see cref="TestSetUp.CreateExecutionContext"/> function).</param> /// <returns>The <see cref="AgentTesterWaf{TStartup}"/> instance to support fluent/chaining usage.</returns> /// <remarks>The <see cref="ExecutionContext"/> must be created by the <see cref="AgentTesterBase"/> as the <see cref="ExecutionContext.ServiceProvider"/> must be set to <see cref="LocalServiceProvider"/>.</remarks> public void PrepareExecutionContext(string?username, object?args = null) { ExecutionContext.Reset(); var ec = TestSetUp.CreateExecutionContext(username ?? TestSetUp.DefaultUsername, args); ec.ServiceProvider = LocalServiceProvider; ec.Properties.Add(ServiceCollectionKey, _serviceCollection); if (string.IsNullOrEmpty(ec.CorrelationId)) { ec.CorrelationId = Guid.NewGuid().ToString(); } ExecutionContext.SetCurrent(ec); }