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); }
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"); } }
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..."); } }
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..."); } }
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"); } }