示例#1
0
        private static async Task <HttpResponseMessage> Call(
            string relativeUrl,
            string requestBody,
            int?timeoutMs          = null,
            StartupOptions options = null)
        {
            HttpResponseMessage response;

            using (var agent = new AgentService(options ?? StartupOptions.FromCommandLine("hosted")))
            {
                var request = new HttpRequestMessage(
                    HttpMethod.Post,
                    relativeUrl)
                {
                    Content = new StringContent(
                        requestBody,
                        Encoding.UTF8,
                        "application/json")
                };

                if (timeoutMs != null)
                {
                    request.Headers.Add("Timeout", timeoutMs.Value.ToString("F0"));
                }

                response = await agent.SendAsync(request);
            }

            return(response);
        }
示例#2
0
        public async Task A_script_snippet_workspace_can_be_used_to_get_completions()
        {
            var(processed, position) = CodeManipulation.ProcessMarkup("Console.$$");
            using (var agent = new AgentService(StartupOptions.FromCommandLine("hosted")))
            {
                var json = new WorkspaceRequest(
                    requestId: "TestRun",
                    activeBufferId: "default.cs",
                    workspace: Workspace.FromSource(
                        processed,
                        "script",
                        id: "default.cs",
                        position: position))
                           .ToJson();

                var request = new HttpRequestMessage(
                    HttpMethod.Post,
                    @"/workspace/completion")
                {
                    Content = new StringContent(
                        json,
                        Encoding.UTF8,
                        "application/json")
                };

                var response = await agent.SendAsync(request);

                var result = await response
                             .EnsureSuccess()
                             .DeserializeAs <CompletionResult>();

                result.Items.Should().ContainSingle(item => item.DisplayText == "WriteLine");
            }
        }
示例#3
0
        public async Task Can_serve_nodatime_code_runner()
        {
            using (var agent = new AgentService(StartupOptions.FromCommandLine("hosted")))
            {
                var response = await agent.GetAsync(@"/LocalCodeRunner/blazor-nodatime.api");

                response.Should().BeSuccessful();
                var result = await response.Content.ReadAsStringAsync();

                result.Should().Contain("Loading...");
            }
        }
示例#4
0
        public async Task Can_serve_nodatime_code_runner()
        {
            var registry = await Default.PackageRegistry.ValueAsync();

            var nodatime = await registry.Get <WorkspaceServer.Packaging.Package2>("blazor-nodatime.api");

            using (var agent = new AgentService(StartupOptions.FromCommandLine("hosted")))
            {
                var response = await agent.GetAsync(@"/LocalCodeRunner/blazor-nodatime.api");

                response.Should().BeSuccessful();
                var result = await response.Content.ReadAsStringAsync();

                result.Should().Contain("Loading...");
            }
        }
示例#5
0
        public async Task Can_serve_from_webassembly_controller()
        {
            var(name, addSource) = await Create.NupkgWithBlazorEnabled();

            using (var agent = new AgentService(new StartupOptions(addPackageSource: new WorkspaceServer.PackageSource(addSource.FullName))))
            {
                var response = await agent.GetAsync($@"/LocalCodeRunner/{name}");

                response.EnsureSuccess();
                var result = await response.Content.ReadAsStringAsync();

                result.Should().Contain("Loading...");

                response = await agent.GetAsync($@"/LocalCodeRunner/{name}/interop.js");

                response.EnsureSuccess();
                result = await response.Content.ReadAsStringAsync();

                result.Should().Contain("invokeMethodAsync");
            }

            // Now do the same thing in hosted mode using the already installed package
            using (var agent = new AgentService(StartupOptions.FromCommandLine("hosted")))
            {
                var response = await agent.GetAsync($@"/LocalCodeRunner/{name}");

                response.EnsureSuccess();
                var result = await response.Content.ReadAsStringAsync();

                result.Should().Contain("Loading...");

                response = await agent.GetAsync($@"/LocalCodeRunner/{name}/interop.js");

                response.EnsureSuccess();
                result = await response.Content.ReadAsStringAsync();

                result.Should().Contain("invokeMethodAsync");
            }
        }