Esempio n. 1
0
        public async Task RunResult_does_not_show_exception_for_test_failures()
        {
            var(runner, workspace) = await GetRunnerAndWorkspace();

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

            workspaceModel = workspaceModel
                             .ReplaceFile(
                "UnitTest1.cs",
                @"
using System; 
using Xunit;

namespace MyUnitTestNamespace
{
    public class MyUnitTestClass 
    {
#region facts
#endregion
    }
}")
                             .RemoveBuffer("UnitTest1.cs")
                             .AddBuffer("UnitTest1.cs@facts", "[Fact] public void failing() => throw new Exception(\"oops!\");");

            var runResult = await runner.Run(new WorkspaceRequest(workspaceModel));

            Log.Info("Output: {output}", runResult.Output);

            runResult.Exception.Should().BeNullOrEmpty();
        }
Esempio n. 2
0
        public async Task When_aspnet_webapi_workspace_request_succeeds_then_output_shows_web_response()
        {
            var workspaceType = await Create.WebApiWorkspaceCopy();

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

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

            var json = request.ToJson();

            var response = await CallRun(json);

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

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

            result.ShouldSucceedWithOutput(
                "Status code: 200 OK",
                "Content headers:",
                "  Date:*",
                // the order of these two varies for some reason
                "  *", // e.g. Transfer-Encoding: chunked
                "  *", // e.g. Server: Kestrel
                "  Content-Type: application/json; charset=utf-8",
                "Content:",
                "[",
                "  \"value1\",",
                "  \"value2\"",
                "]");
        }
        public async void Syntax_Tree_Has_Same_Language_As_Package()
        {
            var package = await Create.ConsoleWorkspaceCopy();

            var         workspace             = WorkspaceFactory.CreateWorkspaceFromDirectory(package.Directory, package.Name, includeInstrumentation: true);
            var         roslynWorkspaceServer = new RoslynWorkspaceServer(package);
            Func <Task> run = () => roslynWorkspaceServer.Run(new WorkspaceRequest(workspace));

            run.Should().NotThrow();
        }
Esempio n. 4
0
        public async Task Run_starts_the_kestrel_server_and_provides_a_WebServer_feature_that_can_receive_requests()
        {
            var(server, package) = await GetRunnerAndWorkspace();

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

            using (var runResult = await server.Run(new WorkspaceRequest(workspace, "Program.cs")))
            {
                var webServer = runResult.GetFeature <WebServer>();

                var response = await webServer.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/api/values")).CancelIfExceeds(new TimeBudget(35.Seconds()));

                var result = await response.EnsureSuccess()
                             .DeserializeAs <string[]>();

                result.Should().Equal("value1", "value2");
            }
        }
        public async Task Run_starts_the_kestrel_server_and_provides_a_WebServer_feature_that_can_receive_requests()
        {
            var registry = Default.PackageFinder;
            var server   = new RoslynWorkspaceServer(registry);
            var package  = await registry.Get <IHaveADirectory>("aspnet.webapi");

            var workspace = WorkspaceFactory.CreateWorkspaceFromDirectory(package.Directory, "aspnet.webapi");

            using (var runResult = await server.Run(new WorkspaceRequest(workspace, "Program.cs")))
            {
                var webServer = runResult.GetFeature <WebServer>();

                var response = await webServer.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/api/values")).CancelIfExceeds(new TimeBudget(35.Seconds()));

                var result = await response.EnsureSuccess()
                             .DeserializeAs <string[]>();

                result.Should().Equal("value1", "value2");
            }
        }
Esempio n. 6
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();
        }
Esempio n. 7
0
        public async Task Run_executes_unit_tests_and_prints_test_results_to_output()
        {
            var(runner, workspaceBuild) = await GetRunnerAndWorkspace();

            var workspace = WorkspaceFactory.CreateWorkspaceFromDirectory(
                workspaceBuild.Directory,
                workspaceBuild.Name)
                            .AddFile(
                "MyUnitTestClass.cs",
                @"
using Xunit;

namespace MyUnitTestNamespace
{
    public class MyUnitTestClass 
    {
        [Fact] public void passing() {  }
    }
}");

            var runResult = await runner.Run(
                new WorkspaceRequest(
                    workspace,
                    "MyUnitTestClass.cs",
                    requestId : "TestRun"));

            Log.Info("Output: {output}", runResult.Output);

            runResult.Output.ShouldMatch(
                "PASSED*(*s)",
                "  MyUnitTestNamespace*(*s)",
                "    MyUnitTestClass*(*s)",
                "      passing*(*s)",
                "",
                "SUMMARY:",
                "Passed: 1, Failed: 0, Not run: 0",
                ""
                );
        }
Esempio n. 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");
        }
Esempio n. 9
0
        public static WorkspaceRequest CreateRequestFromDirectory(DirectoryInfo directory, string workspaceType)
        {
            var workspace = WorkspaceFactory.CreateWorkspaceFromDirectory(directory, workspaceType);

            return(new WorkspaceRequest(workspace));
        }
Esempio n. 10
0
        public async Task Subsequent_runs_update_test_output()
        {
            var(runner, workspace) = await GetRunnerAndWorkspace();

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

            workspaceModel = workspaceModel
                             .ReplaceFile(
                "UnitTest1.cs",
                @"
using System; 
using Xunit;

namespace MyUnitTestNamespace
{
    public class MyUnitTestClass 
    {
#region facts
#endregion
    }
}")
                             .RemoveBuffer("UnitTest1.cs")
                             .AddBuffer("UnitTest1.cs@facts", "[Fact] public void passing() {  }");

            var runResult1 = await runner.Run(new WorkspaceRequest(workspaceModel));

            Log.Info("Output1: {output}", runResult1.Output);

            runResult1.Output.ShouldMatch(
                "PASSED*(*s)",
                "  MyUnitTestNamespace*(*s)",
                "    MyUnitTestClass*(*s)",
                "      passing*(*s)",
                "",
                "SUMMARY:",
                "Passed: 1, Failed: 0, Not run: 0"
                );

            workspaceModel = workspaceModel.ReplaceBuffer(
                id: "UnitTest1.cs@facts",
                text: @"
[Fact] public void still_passing() {  } 
[Fact] public void failing() => throw new Exception(""oops!"");
");

            var runResult2 = await runner.Run(new WorkspaceRequest(workspaceModel));

            Log.Info("Output2: {output}", runResult2.Output);

            runResult2.Output.ShouldMatch(
                "PASSED*(*s)",
                "  MyUnitTestNamespace*(*s)",
                "    MyUnitTestClass*(*s)",
                "      still_passing*(*s)",
                "",
                "FAILED*(*s)",
                "  MyUnitTestNamespace*(*s)",
                "    MyUnitTestClass*(*s)",
                "      failing*(*s)",
                "        System.Exception : oops!",
                "        Stack trace:",
                "           at MyUnitTestNamespace.MyUnitTestClass.failing()",
                "",
                "SUMMARY:",
                "Passed: 1, Failed: 1, Not run: 0"
                );
        }