public async Task AddsHttpCookies()
        {
            var result = new RawScriptResult(null, null)
            {
                Headers = new Dictionary<string, object>(),
                Cookies = new List<Tuple<string, string, CookieOptions>>()
                {
                    new Tuple<string, string, CookieOptions>("firstCookie", "cookieValue", new CookieOptions()
                    {
                        SameSite = SameSiteMode.Lax
                    }),
                    new Tuple<string, string, CookieOptions>("secondCookie", "cookieValue2", new CookieOptions()
                    {
                        Path = "/",
                        HttpOnly = true,
                        MaxAge = TimeSpan.FromSeconds(20),
                        SameSite = (SameSiteMode)(-1)
                    })
                }
            };

            var context = new ActionContext() { HttpContext = new DefaultHttpContext() };
            context.HttpContext.Response.Body = new MemoryStream();
            await result.ExecuteResultAsync(context);
            context.HttpContext.Response.Headers.TryGetValue("Set-Cookie", out StringValues cookies);

            Assert.Equal(2, cookies.Count);
            Assert.Equal("firstCookie=cookieValue; path=/; samesite=lax", cookies[0]);
            Assert.Equal("secondCookie=cookieValue2; max-age=20; path=/; httponly", cookies[1]);
        }
        public async Task HandlesStringContent_WithHeader()
        {
            var obj           = "{ \"a\": 1 }";
            var contentHeader = "application/json";
            var result        = new RawScriptResult(null, obj)
            {
                Headers = new Dictionary <string, object>()
            };
            var context = new ActionContext()
            {
                HttpContext = new DefaultHttpContext()
            };

            context.HttpContext.Response.Headers.Add("Content-Type", contentHeader);
            context.HttpContext.Response.Body = new MemoryStream();
            await result.ExecuteResultAsync(context);

            var body = await TestHelpers.ReadStreamToEnd(context.HttpContext.Response.Body);

            StringValues value;

            Assert.True(context.HttpContext.Response.Headers.TryGetValue("Content-Type", out value));
            Assert.Equal("application/json; charset=utf-8", value);
            Assert.Equal(obj, body);
            Assert.Equal(200, context.HttpContext.Response.StatusCode);
        }
 public async Task HandlesStringContent()
 {
     var obj = "{ \"a\": 1 }";
     var result = new RawScriptResult(null, obj) { Headers = new Dictionary<string, object>() };
     var context = new ActionContext() { HttpContext = new DefaultHttpContext() };
     context.HttpContext.Response.Body = new MemoryStream();
     await result.ExecuteResultAsync(context);
     var body = await TestHelpers.ReadStreamToEnd(context.HttpContext.Response.Body);
     Assert.Equal(obj, body);
     Assert.Equal(200, context.HttpContext.Response.StatusCode);
 }