System.Net.Http.CookieTests.Setting_cookie_when_headers_are_sent_then_should_have_cookie_in_container C# (CSharp) Method

Setting_cookie_when_headers_are_sent_then_should_have_cookie_in_container() private method

private Setting_cookie_when_headers_are_sent_then_should_have_cookie_in_container ( ) : System.Threading.Tasks.Task
return System.Threading.Tasks.Task
        public async Task Setting_cookie_when_headers_are_sent_then_should_have_cookie_in_container()
        {
            const string cookieName1 = "testcookie1";

            var uri = new Uri("http://localhost/");

            AppFunc inner = async env =>
            {
                var context = new OwinContext(env);
                context.Response.Headers.Append("Location", "/");
                await context.Response.WriteAsync("Test");
            };

            AppFunc appFunc = async env =>
            {
                var context = new OwinContext(env);
                context.Response.OnSendingHeaders(_ =>
                {
                    context.Response.Cookies.Append(cookieName1, "c1");
                }, null);
                await inner(env);
            };

            var handler = new OwinHttpMessageHandler(appFunc) { UseCookies = true };
            using (var client = new HttpClient(handler))
            {
                await client.GetAsync(uri);
            }

            handler
                .CookieContainer
                .GetCookies(uri)[cookieName1]
                .ShouldNotBeNull();
        }
    }