Ejemplo n.º 1
0
        public async Task When_Run_times_out_in_user_code_then_the_response_code_is_417(
            string workspaceType,
            string code)
        {
            await Default.ConsoleWorkspace();

            Clock.Reset();

            Workspace workspace = null;

            if (workspaceType == "script")
            {
                workspace = Workspace.FromSource(code, "script");
            }
            else
            {
                var package = Create.EmptyWorkspace();
                var build   = await Create.NewPackage(package.Name, package.Directory, Create.ConsoleConfiguration);

                workspace = Workspace.FromSource(code, build.Name);
            }



            var requestJson = new WorkspaceRequest(workspace).ToJson();
            var response    = await CallRun(requestJson, 10000);

            Log.Info("{response}", await response.Content.ReadAsStringAsync());

            response.StatusCode.Should().Be(HttpStatusCode.ExpectationFailed);
        }
Ejemplo n.º 2
0
        public async Task The_Compile_contract_for_compiling_code_has_not_been_broken()
        {
            var package = await Package.Copy(await Default.ConsoleWorkspace());

            var viewport = ViewportCode();

            var requestJson = new WorkspaceRequest(
                new Workspace(
                    workspaceType: package.Name,
                    buffers: new[]
            {
                EntrypointCode(),
                viewport
            }),
                activeBufferId: viewport.Id,
                requestId: "TestRun");

            var response = await CallCompile(requestJson.ToJson());

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

            var compileResult = result.FromJsonTo <CompileResult>();

            compileResult.Base64Assembly.Should().NotBeNullOrWhiteSpace();
            compileResult = new CompileResult(
                compileResult.Succeeded,
                "",
                compileResult.GetFeature <Diagnostics>(),
                compileResult.RequestId);

            result = compileResult.ToJson().FormatJson();

            this.Assent(result, configuration);
        }
Ejemplo n.º 3
0
        public async Task The_Run_contract_for_noncompiling_code_has_not_been_broken()
        {
            var package = await Package.Copy(await Default.ConsoleWorkspace());

            var viewport = ViewportCode("doesn't compile");

            var request = new WorkspaceRequest(
                new Workspace(
                    workspaceType: package.Name,
                    buffers: new[]
            {
                EntrypointCode(),
                viewport
            }),
                activeBufferId: viewport.Id,
                requestId: "TestRun");

            var requestBody = request.ToJson();

            var response = await CallRun(requestBody);

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

            this.Assent(RemoveMachineSpecificPaths(result).FormatJson(), configuration);
        }
Ejemplo n.º 4
0
        public async Task The_workspace_endpoint_will_prevent_compiling_if_is_in_language_service_mode()
        {
            var output  = Guid.NewGuid().ToString();
            var package = await PackageUtilities.Copy(await Default.ConsoleWorkspace());

            var requestJson = Create.SimpleWorkspaceRequestAsJson(output, package.Name);

            var response = await CallRun(requestJson, options : new StartupOptions(true, true, string.Empty));

            response.Should().BeNotFound();
        }
Ejemplo n.º 5
0
        public async Task Returns_200_if_the_package_exists()
        {
            await Default.ConsoleWorkspace();

            var packageVersion = "1.0.0";

            using (var agent = new AgentService())
            {
                var response = await agent.GetAsync($@"/packages/console/{packageVersion}");

                response.StatusCode.Should().Be(HttpStatusCode.OK);
            }
        }
Ejemplo n.º 6
0
        public async Task When_Run_times_out_in_console_workspace_server_code_then_the_response_code_is_504()
        {
            await Default.ConsoleWorkspace();

            var code = @"public class Program { public static void Main()  {  Console.WriteLine();  }  }";

            var workspace = Workspace.FromSource(code.EnforceLF(), "console");

            var requestJson = new WorkspaceRequest(workspace).ToJson();

            var response = await CallRun(requestJson, timeoutMs : 1);

            response.StatusCode.Should().Be(HttpStatusCode.GatewayTimeout);
        }
Ejemplo n.º 7
0
        public async Task The_workspace_endpoint_compiles_code_using_dotnet_when_a_non_script_workspace_type_is_specified()
        {
            await Default.ConsoleWorkspace();

            var output      = Guid.NewGuid().ToString();
            var requestJson = Create.SimpleWorkspaceRequestAsJson(output, "console");

            var response = await CallRun(requestJson);

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

            VerifySucceeded(result);

            result.ShouldSucceedWithOutput(output);
        }
Ejemplo n.º 8
0
        public async Task The_compile_endpoint_returns_bad_request_if_workspace_type_is_scripting()
        {
            await Default.ConsoleWorkspace();

            var output = Guid.NewGuid().ToString();

            var requestJson = new WorkspaceRequest(
                Workspace.FromSource(
                    source: $@"Console.WriteLine(""{output}"");".EnforceLF(),
                    workspaceType: "script"
                    ),
                requestId: "TestRun").ToJson();

            var response = await CallCompile(requestJson);

            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
Ejemplo n.º 9
0
        public async Task Returns_IsWasmSupported_false_if_the_package_does_not_contain_wasm_runner()
        {
            await Default.ConsoleWorkspace();

            var packageVersion = "1.0.0";

            using (var agent = new AgentService())
            {
                var response = await agent.GetAsync($@"/packages/console/{packageVersion}");

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

                result.FromJsonTo <Package>()
                .IsWasmSupported
                .Should()
                .BeFalse();
            }
        }
Ejemplo n.º 10
0
        public async Task When_they_run_a_snippet_then_they_get_diagnostics_for_the_first_line()
        {
            await Default.ConsoleWorkspace();

            var output = Guid.NewGuid().ToString();

            using (var agent = new AgentService())
            {
                var json =
                    new WorkspaceRequest(
                        Workspace.FromSource(
                            $@"Console.WriteLine(""{output}""".EnforceLF(),
                            workspaceType: "script"),
                        requestId: "TestRun")
                    .ToJson();

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

                var response = await agent.SendAsync(request);

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

                var diagnostics = result.GetFeature <Diagnostics>();

                diagnostics.Should().Contain(d =>
                                             d.Start == 56 &&
                                             d.End == 56 &&
                                             d.Message == "(1,57): error CS1026: ) expected" &&
                                             d.Id == "CS1026");
            }
        }
Ejemplo n.º 11
0
        public async Task The_run_contract_with_no_instrumentation_has_not_been_broken()
        {
            var package = await Package.Copy(await Default.ConsoleWorkspace());

            var requestJson = new WorkspaceRequest(
                new Workspace(
                    workspaceType: package.Name,
                    buffers: new[]
            {
                EntrypointCode("int a = 1; int b = 2; a = 3; b = a;")
            },
                    includeInstrumentation: false),
                requestId: "TestRun"
                ).ToJson();

            var response = await CallRun(requestJson);

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

            this.Assent(RemoveMachineSpecificPaths(result).FormatJson(), configuration);
        }
Ejemplo n.º 12
0
        public async Task When_a_non_script_workspace_type_is_specified_then_code_fragments_cannot_be_compiled_successfully()
        {
            await Default.ConsoleWorkspace();

            var requestJson =
                new WorkspaceRequest(
                    Workspace.FromSource(
                        @"Console.WriteLine(""hello!"");",
                        workspaceType: "console",
                        id: "Program.cs")).ToJson();

            var response = await CallRun(requestJson);

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

            result.ShouldFailWithOutput(
                "*Program.cs(1,1): error CS8400: Feature 'top-level statements' is not available in C# 8.0. Please use language version 9.0 or greater.*"
                );
        }
Ejemplo n.º 13
0
        public async Task When_a_non_script_workspace_type_is_specified_then_code_fragments_cannot_be_compiled_successfully()
        {
            await Default.ConsoleWorkspace();

            var requestJson =
                new WorkspaceRequest(
                    Workspace.FromSource(
                        @"Console.WriteLine(""hello!"");",
                        workspaceType: "console",
                        id: "Program.cs")).ToJson();

            var response = await CallRun(requestJson);

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

            result.ShouldFailWithOutput(
                "Program.cs(1,19): error CS1022: Type or namespace definition, or end-of-file expected",
                "Program.cs(1,19): error CS1026: ) expected"
                );
        }
Ejemplo n.º 14
0
        public async Task A_script_snippet_workspace_can_be_used_to_get_diagnostics()
        {
            await Default.ConsoleWorkspace();

            var log = new LogEntryList();

            var(processed, position) = CodeManipulation.ProcessMarkup("adddd");
            using (LogEvents.Subscribe(log.Add))
                using (var agent = new AgentService())
                {
                    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/diagnostics")
                    {
                        Content = new StringContent(
                            json,
                            Encoding.UTF8,
                            "application/json")
                    };

                    var response = await agent.SendAsync(request);

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

                    result.Diagnostics.Should().NotBeNullOrEmpty();
                    result.Diagnostics.Should().Contain(signature => signature.Message == "default.cs(1,1): error CS0103: The name \'adddd\' does not exist in the current context");
                }
        }
Ejemplo n.º 15
0
        public async Task A_script_snippet_workspace_can_be_used_to_get_signature_help()
        {
            await Default.ConsoleWorkspace();

            var log = new LogEntryList();

            var(processed, position) = CodeManipulation.ProcessMarkup("Console.WriteLine($$)");
            using (LogEvents.Subscribe(log.Add))
                using (var agent = new AgentService())
                {
                    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/signaturehelp")
                    {
                        Content = new StringContent(
                            json,
                            Encoding.UTF8,
                            "application/json")
                    };

                    var response = await agent.SendAsync(request);

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

                    result.Signatures.Should().NotBeNullOrEmpty();
                    result.Signatures.Should().Contain(signature => signature.Label == "void Console.WriteLine(string format, params object[] arg)");
                }
        }
Ejemplo n.º 16
0
        public async Task When_Run_times_out_in_console_workspace_server_code_then_the_response_code_is_504()
        {
            var code    = @"public class Program { public static void Main()  {  Console.WriteLine();  }  }";
            var package = await WorkspaceServer.Packaging.Package.Copy(await Default.ConsoleWorkspace());

            var workspace = Workspace.FromSource(code.EnforceLF(), package.Name);

            var requestJson = new WorkspaceRequest(workspace).ToJson();

            ((VirtualClock)Clock.Current).OnBudgetEntryRecorded((virtualClock, budget, entry) =>
            {
                Log.Info("Budget entry created: {entry}", entry);

                if (entry.Name == "CompileWorker")
                {
                    budget.Cancel();
                }
            });

            var response = await CallRun(requestJson);

            response.StatusCode.Should().Be(HttpStatusCode.GatewayTimeout);
        }
Ejemplo n.º 17
0
        public async Task The_signature_help_contract_has_not_been_broken()
        {
            var package = await Package.Copy(await Default.ConsoleWorkspace());

            var viewport = ViewportCode("Console.Write($$);");

            var requestJson = new WorkspaceRequest(
                new Workspace(
                    workspaceType: package.Name,
                    buffers: new[]
            {
                EntrypointCode(),
                viewport
            }),
                activeBufferId: viewport.Id,
                requestId: "TestRun").ToJson();

            var response = await CallSignatureHelp(requestJson);

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

            this.Assent(result.FormatJson(), configuration);
        }
Ejemplo n.º 18
0
        public async Task The_workspace_snippet_endpoint_compiles_code_using_scripting_when_a_workspace_type_is_specified_as_script()
        {
            await Default.ConsoleWorkspace();

            var output = Guid.NewGuid().ToString();

            var requestJson = new WorkspaceRequest(
                Workspace.FromSource(
                    source: $@"Console.WriteLine(""{output}"");".EnforceLF(),
                    workspaceType: "script"
                    ),
                requestId: "TestRun").ToJson();

            var response = await CallRun(requestJson);

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

            VerifySucceeded(result);

            result.ShouldSucceedWithOutput(output);
        }
Ejemplo n.º 19
0
        public async Task A_script_snippet_workspace_can_be_used_to_get_completions()
        {
            await Default.ConsoleWorkspace();

            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");
            }
        }
Ejemplo n.º 20
0
        public async Task A_console_workspace_can_be_used_to_get_signature_help()
        {
            await Default.ConsoleWorkspace();

            #region bufferSources

            var program   = @"using System;
using System.Linq;

namespace FibonacciTest
{
    public class Program
    {
        public static void Main()
        {
            foreach (var i in FibonacciGenerator.Fibonacci().Take(20))
            {
                Console.WriteLine(i);
            }
        }       
    }
}".EnforceLF();
            var generator = @"using System.Collections.Generic;
using System;
namespace FibonacciTest
{
    public static class FibonacciGenerator
    {
        public static IEnumerable<int> Fibonacci()
        {
            int current = 1, next = 1;
            while (true)
            {
                yield return current;
                next = current + (current = next);
                Console.WriteLine($$);
            }
        }
    }
}".EnforceLF();
            #endregion
            var(processed, position) = CodeManipulation.ProcessMarkup(generator);
            var log = new LogEntryList();
            using (LogEvents.Subscribe(log.Add))
                using (var agent = new AgentService())
                {
                    var json =
                        new WorkspaceRequest(activeBufferId: "generators/FibonacciGenerator.cs",
                                             requestId: "TestRun",
                                             workspace: Workspace.FromSources(
                                                 workspaceType: "console",
                                                 language: "csharp",
                                                 ("Program.cs", program, 0),
                                                 ("generators/FibonacciGenerator.cs", processed, position)
                                                 )).ToJson();

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

                    var response = await agent.SendAsync(request);

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

                    result.Signatures.Should().NotBeNullOrEmpty();
                    result.Signatures.Should().Contain(diagnostic => diagnostic.Label == "void Console.WriteLine(string format, params object[] arg)");
                }
        }
Ejemplo n.º 21
0
        public async Task A_console_project_can_be_used_to_get_diagnostics()
        {
            await Default.ConsoleWorkspace();

            #region bufferSources

            var program = @"using System;
using System.Linq;

namespace FibonacciTest
{
    public class Program
    {
        public static void Main()
        {
            foreach (var i in FibonacciGenerator.Fibonacci().Take(20))
            {
                Console.WriteLine(i);
            }
        }       
    }
}".EnforceLF();

            var generator = @"using System.Collections.Generic;
using System;
namespace FibonacciTest
{
    public static class FibonacciGenerator
    {
        public static IEnumerable<int> Fibonacci()
        {
            int current = 1, next = 1;
            while (true)
            {   
                adddd
                yield return current;
                next = current + (current = next);
                Cons$$
            }
        }
    }
}".EnforceLF();

            #endregion
            var(processed, position) = CodeManipulation.ProcessMarkup(generator);
            var log = new LogEntryList();
            using (LogEvents.Subscribe(log.Add))
                using (var agent = new AgentService())
                {
                    var json =
                        new WorkspaceRequest(activeBufferId: "generators/FibonacciGenerator.cs",
                                             requestId: "TestRun",
                                             workspace: Workspace.FromSources(
                                                 "console",
                                                 language: "csharp",
                                                 ("Program.cs", program, 0),
                                                 ("generators/FibonacciGenerator.cs", processed, position)
                                                 )).ToJson();

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

                    var response = await agent.SendAsync(request);

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

                    result.Diagnostics.Should().NotBeNullOrEmpty();
                    result.Diagnostics.Should().Contain(diagnostic => diagnostic.Message == "generators/FibonacciGenerator.cs(12,17): error CS0246: The type or namespace name \'adddd\' could not be found (are you missing a using directive or an assembly reference?)");
                }
        }
Ejemplo n.º 22
0
        public async Task A_console_project_can_be_used_to_get_type_completion_with_a_space_in_the_name()
        {
            await Default.ConsoleWorkspace();

            #region bufferSources

            var program = @"using System;
using System.Linq;

namespace FibonacciTest
{
    public class Program
    {
        public static void Main()
        {
            foreach (var i in FibonacciGenerator.Fibonacci().Take(20))
            {
                Console.WriteLine(i);
            }
        }       
    }
}".EnforceLF();

            var generator = @"using System.Collections.Generic;
using System;
namespace FibonacciTest
{
    public static class FibonacciGenerator
    {
        public static IEnumerable<int> Fibonacci()
        {
            int current = 1, next = 1;
            while (true)
            {
                yield return current;
                next = current + (current = next);
                Cons$$
            }
        }
    }
}".EnforceLF();

            #endregion
            var package = await PackageUtilities.Copy(await Default.ConsoleWorkspace(), "a space");

            var(processed, position) = CodeManipulation.ProcessMarkup(generator);
            var log = new LogEntryList();
            using (LogEvents.Subscribe(log.Add))
                using (var agent = new AgentService())
                {
                    var json =
                        new WorkspaceRequest(activeBufferId: "generators/FibonacciGenerator.cs",
                                             requestId: "TestRun",
                                             workspace: Workspace.FromSources(
                                                 package.Name,
                                                 language: "csharp",
                                                 ("Program.cs", program, 0),
                                                 ("generators/FibonacciGenerator.cs", processed, 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().NotBeNullOrEmpty();
                    result.Items.Should().Contain(completion => completion.SortText == "Console");
                }
        }