<commit_before>﻿using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

#if NETSTANDARD2_0
using Microsoft.AspNetCore.Authentication;
#endif

namespace Alba
{
    public static class SystemUnderTestExtensions
    {
        // SAMPLE: ScenarioSignature
        /// <summary>
        /// Define and execute an integration test by running an Http request through
        /// your ASP.Net Core system
        /// </summary>
        /// <param name="system"></param>
        /// <param name="configure"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public static async Task<IScenarioResult> Scenario(
            this ISystemUnderTest system,
            Action<Scenario> configure)
        // ENDSAMPLE
        {
            using (var scope = system.Services.GetService<IServiceScopeFactory>().CreateScope())
            {
                var scenario = new Scenario(system, scope);

                var contextAccessor = scope.ServiceProvider.GetService<IHttpContextAccessor>();
                contextAccessor.HttpContext = scenario.Context;

                configure(scenario);

                scenario.Rewind();

                try
                {
                    await system.BeforeEach(scenario.Context).ConfigureAwait(false);

                    if (scenario.Context.Request.Path == null)
                    {
                        throw new InvalidOperationException("This scenario has no defined url");<commit_msg>Made alba more resilient to missing HttpContextAccessor<commit_after>﻿using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

#if NETSTANDARD2_0
using Microsoft.AspNetCore.Authentication;
#endif

namespace Alba
{
    public static class SystemUnderTestExtensions
    {
        // SAMPLE: ScenarioSignature
        /// <summary>
        /// Define and execute an integration test by running an Http request through
        /// your ASP.Net Core system
        /// </summary>
        /// <param name="system"></param>
        /// <param name="configure"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public static async Task<IScenarioResult> Scenario(
            this ISystemUnderTest system,
            Action<Scenario> configure)
        // ENDSAMPLE
        {
            using (var scope = system.Services.GetService<IServiceScopeFactory>().CreateScope())
            {
                var scenario = new Scenario(system, scope);

                var contextAccessor = scope.ServiceProvider.GetService<IHttpContextAccessor>();
                if (contextAccessor != null)
                {
                    contextAccessor.HttpContext = scenario.Context;
                }

                configure(scenario);

                scenario.Rewind();

                try
                {
                    await system.BeforeEach(scenario.Context).ConfigureAwait(false);

                    if (scenario.Context.Request.Path == null)
                    {
                        throw new InvalidOperationException("This scenario has no defined url");
{'fraction_non_alphanumeric': 0.09469583458195985, 'fraction_numerical': 0.001198681450404555, 'mean_word_length': 2.009918845807033, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6703710', 'n_tokens_mistral': 791, 'n_tokens_neox': 758, 'n_words': 186}