public void HttpNotebookFrontendEnvironment_can_complete_if_the_uri_is_supplied_after_execution_is_invoked()
        {
            var testCommand = new TestCommand();

            testCommand.SetToken("token-abcd");
            var context      = KernelInvocationContext.Establish(testCommand);
            var events       = context.KernelEvents.ToSubscribedList();
            var httpFrontend = new HtmlNotebookFrontendEnvironment(TimeSpan.FromSeconds(2));

            _ = httpFrontend.ExecuteClientScript("console.log('test');", context);

            httpFrontend.SetApiUri(new Uri("http://test-uri"));

            events
            .Should()
            .ContainSingle <DisplayedValueProduced>()
            .Which
            .FormattedValues
            .Should()
            .ContainSingle()
            .Which
            .Value
            .Should()
            .ContainAll(
                "http://test-uri",
                @"console.log(\u0027test\u0027);"
                );
        }
예제 #2
0
    public async Task RouteAsync(RouteContext context)
    {
        if (context.HttpContext.Request.Method == HttpMethods.Post)
        {
            var segments =
                context.HttpContext
                .Request
                .Path
                .Value
                .Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            if (segments[0] == "discovery")
            {
                using var reader = new StreamReader(context.HttpContext.Request.Body);
                var source = await reader.ReadToEndAsync();

                var apiUri = new Uri(source);
                _frontendEnvironment.SetApiUri(apiUri);

                context.Handler = async httpContext =>
                {
                    await httpContext.Response.CompleteAsync();
                };
            }
        }
    }