Ejemplo n.º 1
0
        // 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
        {
            var scenario = new Scenario(system);


            configure(scenario);

            scenario.Rewind();

            HttpContext context = null;

            try
            {
                context = await system.Invoke(c =>
                {
                    system.BeforeEach(c).GetAwaiter().GetResult();

                    c.Request.Body.Position = 0;


                    scenario.SetupHttpContext(c);

                    if (c.Request.Path == null)
                    {
                        throw new InvalidOperationException("This scenario has no defined url");
                    }
                });

                scenario.RunAssertions(context);
            }
            finally
            {
                await system.AfterEach(context);
            }

            if (context.Response.Body.CanSeek)
            {
                context.Response.Body.Position = 0;
            }


            return(new ScenarioResult(context, system));
        }