예제 #1
0
 public static async Task <Package> NetstandardWorkspaceCopy(
     [CallerMemberName] string testName = null,
     DirectoryInfo parentDirectory      = null) =>
 await PackageUtilities.Copy(
     await Default.NetstandardWorkspace(),
     testName,
     parentDirectory : parentDirectory);
예제 #2
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();
        }
예제 #3
0
        public async Task EnsureStarted_returns_the_web_server_base_uri()
        {
            var workspace = await PackageUtilities.Copy(await Default.WebApiWorkspace());

            using (var webServer = new WebServer(workspace))
            {
                var uri = await webServer.EnsureStarted();

                uri.Should().NotBeNull();

                uri.ToString().Should().Match("http://127.0.0.1:*");
            }
        }
예제 #4
0
        public async Task Multiple_WebServer_instances_can_be_run_concurrently_in_the_same_folder()
        {
            var workspace = await PackageUtilities.Copy(await Default.WebApiWorkspace());

            using (var webServer1 = new WebServer(workspace))
                using (var webServer2 = new WebServer(workspace))
                {
                    var response1 = await webServer1.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/custom/values"));

                    var response2 = await webServer2.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/custom/values"));

                    response1.EnsureSuccess();
                    response2.EnsureSuccess();
                }
        }
예제 #5
0
        public async Task A_package_copy_is_not_reinitialized_if_the_source_was_already_initialized()
        {
            var initializer = new TestPackageInitializer(
                "console",
                "MyProject");

            var original = Create.EmptyWorkspace(initializer: initializer);

            await original.CreateRoslynWorkspaceForLanguageServicesAsync(new TimeBudget(30.Seconds()));

            var copy = await PackageUtilities.Copy(original);

            await copy.CreateRoslynWorkspaceForLanguageServicesAsync(new TimeBudget(30.Seconds()));

            initializer.InitializeCount.Should().Be(1);
        }
예제 #6
0
        public async Task WebServer_lifecycle_events_can_be_viewed_via_StandardOutput()
        {
            var workspace = await PackageUtilities.Copy(await Default.WebApiWorkspace());

            var log = new StringBuilder();

            using (var webServer = new WebServer(workspace))
                using (webServer.StandardOutput.Subscribe(s => log.Append(s)))
                {
                    await webServer.EnsureStarted();

                    await Task.Delay(100);
                }

            log.ToString().Should().Match(
                "*Now listening on: http://127.0.0.1:*");
            log.ToString().Should().Match(
                "*Hosting environment: Production*");
        }
예제 #7
0
        public async Task When_aspnet_webapi_workspace_request_succeeds_then_standard_out_is_available_on_response()
        {
            var package = await PackageUtilities.Copy(await Default.WebApiWorkspace());

            await package.CreateRoslynWorkspaceForRunAsync(new TimeBudget(10.Minutes()));

            var workspace = WorkspaceFactory.CreateWorkspaceFromDirectory(package.Directory, package.Directory.Name);

            var request = new WorkspaceRequest(workspace, httpRequest: new HttpRequest("/api/values", "get"), requestId: "TestRun");

            var response = await CallRun(request.ToJson(), 30000);

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

            Log.Info("result: {x}", result);

            throw new NotImplementedException();
        }
예제 #8
0
        public async Task When_aspnet_webapi_workspace_request_fails_then_diagnostics_are_returned()
        {
            var package = await PackageUtilities.Copy(await Default.WebApiWorkspace());

            await package.CreateRoslynWorkspaceForRunAsync(new TimeBudget(10.Minutes()));

            var workspace          = WorkspaceFactory.CreateWorkspaceFromDirectory(package.Directory, package.Directory.Name);
            var nonCompilingBuffer = new Buffer("broken.cs", "this does not compile", 0);

            workspace = new Workspace(
                buffers: workspace.Buffers.Concat(new[] { nonCompilingBuffer }).ToArray(),
                files: workspace.Files.ToArray(),
                workspaceType: workspace.WorkspaceType);

            var request = new WorkspaceRequest(workspace, httpRequest: new HttpRequest("/api/values", "get"), requestId: "TestRun");

            var response = await CallRun(request.ToJson(), null);

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

            result.ShouldFailWithOutput("broken.cs(1,1): error CS1031: Type expected");
        }
예제 #9
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");
                }
        }
예제 #10
0
 public static async Task <Package> XunitWorkspaceCopy([CallerMemberName] string testName = null) =>
 await PackageUtilities.Copy(
     await Default.XunitWorkspace(),
     testName);
예제 #11
0
 public static async Task <Package> ConsoleWorkspaceCopy([CallerMemberName] string testName = null, bool isRebuildable = false, IScheduler buildThrottleScheduler = null) =>
 await PackageUtilities.Copy(
     await Default.ConsoleWorkspace(),
     testName,
     isRebuildable,
     buildThrottleScheduler);
        public async Task Get_documentation_with_signature_help_for_console_writeline()
        {
            #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 package = await PackageUtilities.Copy(await Default.ConsoleWorkspace());

            var workspace = new Workspace(workspaceType: package.Name, buffers: new[]
            {
                new Buffer("Program.cs", program),
                new Buffer("generators/FibonacciGenerator.cs", processed, position)
            });

            var request = new WorkspaceRequest(workspace, activeBufferId: "generators/FibonacciGenerator.cs");
            var server  = await GetLanguageServiceAsync();

            var result = await server.GetSignatureHelp(request);

            result.Signatures.Should().NotBeNullOrEmpty();

            var sample = result.Signatures.First(e => e.Label == "void Console.WriteLine(string format, params object[] arg)");
            sample.Documentation.Value.Should().Contain("Writes the text representation of the specified array of objects, followed by the current line terminator, to the standard output stream using the specified format information.");
            sample.Parameters.Should().HaveCount(2);

            sample.Parameters.ElementAt(0).Name.Should().Be("format");
            sample.Parameters.ElementAt(0).Label.Should().Be("string format");
            sample.Parameters.ElementAt(0).Documentation.Value.Should().Contain("A composite format string.");

            sample.Parameters.ElementAt(1).Name.Should().Be("arg");
            sample.Parameters.ElementAt(1).Label.Should().Be("params object[] arg");
            sample.Parameters.ElementAt(1).Documentation.Value.Should().Contain("An array of objects to write using format .");
        }