예제 #1
0
파일: TestCommand.cs 프로젝트: wtgodbe/cli
        public int DoRun(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var dotnetTestParams = new DotnetTestParams();

            try
            {
                dotnetTestParams.Parse(args);

                if (dotnetTestParams.Help)
                {
                    return(0);
                }

                // Register for parent process's exit event
                if (dotnetTestParams.ParentProcessId.HasValue)
                {
                    RegisterForParentProcessExit(dotnetTestParams.ParentProcessId.Value);
                }

                return(RunTest(dotnetTestParams));
            }
            catch (InvalidOperationException ex)
            {
                TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                return(-1);
            }
            catch (Exception ex) when(!(ex is GracefulException))
            {
                Console.WriteLine(ex.ToString());
                TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                return(-2);
            }
        }
예제 #2
0
        private int DoBuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
        {
            var strings = new List <string>
            {
                $"{dotnetTestParams.ProjectOrAssemblyPath}",
                $"--configuration", dotnetTestParams.Config,
                "--framework", projectContext.TargetFramework.ToString()
            };

            // Build the test specifically for the target framework \ rid of the ProjectContext.
            // This avoids building the project for tfms that the user did not request.

            if (!string.IsNullOrEmpty(dotnetTestParams.BuildBasePath))
            {
                strings.Add("--build-base-path");
                strings.Add(dotnetTestParams.BuildBasePath);
            }

            if (!string.IsNullOrEmpty(dotnetTestParams.Output))
            {
                strings.Add("--output");
                strings.Add(dotnetTestParams.Output);
            }

            if (!string.IsNullOrEmpty(projectContext.RuntimeIdentifier))
            {
                strings.Add("--runtime");
                strings.Add(projectContext.RuntimeIdentifier);
            }

            var result = Command.CreateDotNet("build", strings).Execute().ExitCode;

            return(result);
        }
예제 #3
0
        private void HandleDesignTimeMessages(DotnetTestParams dotnetTestParams)
        {
            var reportingChannelFactory = new ReportingChannelFactory();
            var adapterChannel          = reportingChannelFactory.CreateAdapterChannel(dotnetTestParams.Port.Value);

            try
            {
                var pathToAssemblyUnderTest = _assemblyUnderTest;
                var messages = new TestMessagesCollection();
                using (var dotnetTest = new DotnetTest(messages, pathToAssemblyUnderTest))
                {
                    var testRunnerFactory =
                        new TestRunnerFactory(_testRunnerNameResolver.ResolveTestRunner(), _commandFactory);

                    dotnetTest
                    .AddNonSpecificMessageHandlers(messages, adapterChannel)
                    .AddTestDiscoveryMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory)
                    .AddTestRunMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory)
                    .AddTestRunnnersMessageHandlers(adapterChannel, reportingChannelFactory);

                    dotnetTest.StartListeningTo(adapterChannel);

                    adapterChannel.Connect();

                    dotnetTest.StartHandlingMessages();
                }
            }
            catch (Exception ex)
            {
                adapterChannel.SendError(ex);
            }
        }
예제 #4
0
        private int RunTest(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
        {
            var testRunner       = projectContext.ProjectFile.TestRunner;
            var dotnetTestRunner = _dotnetTestRunnerFactory.Create(dotnetTestParams.Port);

            return(dotnetTestRunner.RunTests(projectContext, dotnetTestParams, workspace));
        }
예제 #5
0
        public ITestRunnerNameResolver Create(DotnetTestParams dotnetTestParams)
        {
            var testRunnerResolver = dotnetTestParams.IsTestingAssembly ?
                                     GetAssemblyTestRunnerResolver(dotnetTestParams) :
                                     GetProjectJsonTestRunnerResolver(dotnetTestParams);

            return(testRunnerResolver);
        }
예제 #6
0
        internal override int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
        {
            Console.WriteLine("Listening on port {0}", dotnetTestParams.Port.Value);

            HandleDesignTimeMessages(projectContext, dotnetTestParams);

            return(0);
        }
예제 #7
0
        internal override int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
        {
            Console.WriteLine("Listening on port {0}", dotnetTestParams.Port.Value);

            HandleDesignTimeMessages(projectContext, dotnetTestParams);

            return 0;
        }
예제 #8
0
        public int RunTests(DotnetTestParams dotnetTestParams)
        {
            Console.WriteLine("Listening on port {0}", dotnetTestParams.Port.Value);

            HandleDesignTimeMessages(dotnetTestParams);

            return(0);
        }
예제 #9
0
        public int RunTests(DotnetTestParams dotnetTestParams)
        {
            var projectPath        = GetProjectPath(dotnetTestParams.ProjectOrAssemblyPath);
            var runtimeIdentifiers = !string.IsNullOrEmpty(dotnetTestParams.Runtime)
                ? new[] { dotnetTestParams.Runtime }
                : RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers();
            var exitCode = 0;

            // Create a workspace
            var workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment());

            if (dotnetTestParams.Framework != null)
            {
                var projectContext = workspace.GetProjectContext(projectPath, dotnetTestParams.Framework);
                if (projectContext == null)
                {
                    Reporter.Error.WriteLine(
                        $"Project '{projectPath}' does not support framework: {dotnetTestParams.UnparsedFramework}");
                    return(1);
                }
                projectContext = workspace.GetRuntimeContext(projectContext, runtimeIdentifiers);

                exitCode = RunTests(projectContext, dotnetTestParams);
            }
            else
            {
                var summary         = new Summary();
                var projectContexts = workspace.GetProjectContextCollection(projectPath)
                                      .EnsureValid(projectPath)
                                      .FrameworkOnlyContexts
                                      .Select(c => workspace.GetRuntimeContext(c, runtimeIdentifiers))
                                      .ToList();

                // Execute for all TFMs the project targets.
                foreach (var projectContext in projectContexts)
                {
                    var result = RunTests(projectContext, dotnetTestParams);
                    if (result == 0)
                    {
                        summary.Passed++;
                    }
                    else
                    {
                        summary.Failed++;
                        if (exitCode == 0)
                        {
                            // If tests fail in more than one TFM, we'll have it use the result of the first one
                            // as the exit code.
                            exitCode = result;
                        }
                    }
                }

                summary.Print();
            }

            return(exitCode);
        }
예제 #10
0
        private int BuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
        {
            if (dotnetTestParams.NoBuild)
            {
                return 0;
            }

            return DoBuildTestProject(projectContext, dotnetTestParams, workspace);
        }
예제 #11
0
        private int BuildTestProject(DotnetTestParams dotnetTestParams)
        {
            if (dotnetTestParams.NoBuild)
            {
                return 0;
            }

            return DoBuildTestProject(dotnetTestParams);
        }
예제 #12
0
        private int BuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
        {
            if (dotnetTestParams.NoBuild)
            {
                return(0);
            }

            return(DoBuildTestProject(projectContext, dotnetTestParams, workspace));
        }
예제 #13
0
        private int BuildTestProject(DotnetTestParams dotnetTestParams)
        {
            if (dotnetTestParams.NoBuild)
            {
                return(0);
            }

            return(DoBuildTestProject(dotnetTestParams));
        }
        public void It_throws_InvalidOperationException_if_an_invalid_parent_process_id_is_passed_to_it()
        {
            var dotnetTestParams = new DotnetTestParams();
            const string invalidParentProcessId = "daddy";
            Action action = () => dotnetTestParams.Parse(new [] { "--parentProcessId", invalidParentProcessId });

            action
                .ShouldThrow<InvalidOperationException>()
                .WithMessage($"Invalid process id '{invalidParentProcessId}'. Process id must be an integer.");
        }
예제 #15
0
 public int RunTests(DotnetTestParams dotnetTestParams)
 {
     return(_commandFactory.Create(
                _testRunnerNameResolver.ResolveTestRunner(),
                GetCommandArgs(dotnetTestParams),
                _framework,
                dotnetTestParams.Config)
            .Execute()
            .ExitCode);
 }
예제 #16
0
        private IEnumerable <string> GetCommandArgs(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
        {
            var commandArgs = new List <string>
            {
                new AssemblyUnderTest(projectContext, dotnetTestParams).Path
            };

            commandArgs.AddRange(dotnetTestParams.RemainingArguments);

            return(commandArgs);
        }
예제 #17
0
        private IEnumerable <string> GetCommandArgs(DotnetTestParams dotnetTestParams)
        {
            var commandArgs = new List <string>
            {
                _assemblyUnderTest
            };

            commandArgs.AddRange(dotnetTestParams.RemainingArguments);

            return(commandArgs);
        }
예제 #18
0
        private IEnumerable<string> GetCommandArgs(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
        {
            var commandArgs = new List<string>
            {
                new AssemblyUnderTest(projectContext, dotnetTestParams).Path
            };

            commandArgs.AddRange(dotnetTestParams.RemainingArguments);

            return commandArgs;
        }
예제 #19
0
        public int RunTests(DotnetTestParams dotnetTestParams)
        {
            var assembly         = new FileInfo(dotnetTestParams.ProjectOrAssemblyPath);
            var publishDirectory = assembly.Directory.FullName;
            var applicationName  = Path.GetFileNameWithoutExtension(dotnetTestParams.ProjectOrAssemblyPath);

            var commandFactory = new PublishedPathCommandFactory(publishDirectory, applicationName);

            var assemblyUnderTest = dotnetTestParams.ProjectOrAssemblyPath;

            return(_nextRunner(commandFactory, assemblyUnderTest).RunTests(dotnetTestParams));
        }
예제 #20
0
        private ITestRunnerNameResolver GetAssemblyTestRunnerResolver(DotnetTestParams dotnetTestParams)
        {
            ITestRunnerNameResolver testRunnerNameResolver = null;

            if (dotnetTestParams.HasTestRunner)
            {
                testRunnerNameResolver = new ParameterTestRunnerNameResolver(dotnetTestParams.TestRunner);
            }
            else
            {
                testRunnerNameResolver = new AssemblyTestRunnerNameResolver(dotnetTestParams.ProjectOrAssemblyPath);
            }

            return(testRunnerNameResolver);
        }
예제 #21
0
        internal override int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
        {
            var commandFactory =
                new ProjectDependenciesCommandFactory(
                    projectContext.TargetFramework,
                    dotnetTestParams.Config,
                    dotnetTestParams.Output,
                    dotnetTestParams.BuildBasePath,
                    projectContext.ProjectDirectory);

            return commandFactory.Create(
                    GetCommandName(projectContext.ProjectFile.TestRunner),
                    GetCommandArgs(projectContext, dotnetTestParams),
                    projectContext.TargetFramework,
                    dotnetTestParams.Config)
                .Execute()
                .ExitCode;
        }
예제 #22
0
        internal override int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
        {
            var commandFactory =
                new ProjectDependenciesCommandFactory(
                    projectContext.TargetFramework,
                    dotnetTestParams.Config,
                    dotnetTestParams.Output,
                    dotnetTestParams.BuildBasePath,
                    projectContext.ProjectDirectory);

            return(commandFactory.Create(
                       GetCommandName(projectContext.ProjectFile.TestRunner),
                       GetCommandArgs(projectContext, dotnetTestParams),
                       projectContext.TargetFramework,
                       dotnetTestParams.Config)
                   .Execute()
                   .ExitCode);
        }
예제 #23
0
        public int DoRun(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var dotnetTestParams = new DotnetTestParams();

            dotnetTestParams.Parse(args);

            try
            {
                if (dotnetTestParams.Help)
                {
                    return(0);
                }

                // Register for parent process's exit event
                if (dotnetTestParams.ParentProcessId.HasValue)
                {
                    RegisterForParentProcessExit(dotnetTestParams.ParentProcessId.Value);
                }

                var projectContexts = CreateProjectContexts(dotnetTestParams.ProjectPath);

                var projectContext = projectContexts.First();

                var testRunner = projectContext.ProjectFile.TestRunner;

                IDotnetTestRunner dotnetTestRunner = _dotnetTestRunnerFactory.Create(dotnetTestParams.Port);

                return(dotnetTestRunner.RunTests(projectContext, dotnetTestParams));
            }
            catch (InvalidOperationException ex)
            {
                TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                return(-1);
            }
            catch (Exception ex)
            {
                TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                return(-2);
            }
        }
예제 #24
0
        private static void HandleDesignTimeMessages(
            ProjectContext projectContext,
            DotnetTestParams dotnetTestParams)
        {
            var reportingChannelFactory = new ReportingChannelFactory();
            var adapterChannel = reportingChannelFactory.CreateAdapterChannel(dotnetTestParams.Port.Value);

            try
            {
                var pathToAssemblyUnderTest = new AssemblyUnderTest(projectContext, dotnetTestParams).Path;
                var messages = new TestMessagesCollection();
                using (var dotnetTest = new DotnetTest(messages, pathToAssemblyUnderTest))
                {
                    var commandFactory =
                        new ProjectDependenciesCommandFactory(
                            projectContext.TargetFramework,
                            dotnetTestParams.Config,
                            dotnetTestParams.Output,
                            dotnetTestParams.BuildBasePath,
                            projectContext.ProjectDirectory);

                    var testRunnerFactory =
                        new TestRunnerFactory(GetCommandName(projectContext.ProjectFile.TestRunner), commandFactory);

                    dotnetTest
                        .AddNonSpecificMessageHandlers(messages, adapterChannel)
                        .AddTestDiscoveryMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory)
                        .AddTestRunMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory)
                        .AddTestRunnnersMessageHandlers(adapterChannel, reportingChannelFactory);

                    dotnetTest.StartListeningTo(adapterChannel);

                    adapterChannel.Connect();

                    dotnetTest.StartHandlingMessages();
                }
            }
            catch (Exception ex)
            {
                adapterChannel.SendError(ex);
            }
        }
예제 #25
0
        private static void HandleDesignTimeMessages(
            ProjectContext projectContext,
            DotnetTestParams dotnetTestParams)
        {
            var reportingChannelFactory = new ReportingChannelFactory();
            var adapterChannel          = reportingChannelFactory.CreateAdapterChannel(dotnetTestParams.Port.Value);

            try
            {
                var pathToAssemblyUnderTest = new AssemblyUnderTest(projectContext, dotnetTestParams).Path;
                var messages = new TestMessagesCollection();
                using (var dotnetTest = new DotnetTest(messages, pathToAssemblyUnderTest))
                {
                    var commandFactory =
                        new ProjectDependenciesCommandFactory(
                            projectContext.TargetFramework,
                            dotnetTestParams.Config,
                            dotnetTestParams.Output,
                            dotnetTestParams.BuildBasePath,
                            projectContext.ProjectDirectory);

                    var testRunnerFactory =
                        new TestRunnerFactory(GetCommandName(projectContext.ProjectFile.TestRunner), commandFactory);

                    dotnetTest
                    .AddNonSpecificMessageHandlers(messages, adapterChannel)
                    .AddTestDiscoveryMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory)
                    .AddTestRunMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory)
                    .AddTestRunnnersMessageHandlers(adapterChannel, reportingChannelFactory);

                    dotnetTest.StartListeningTo(adapterChannel);

                    adapterChannel.Connect();

                    dotnetTest.StartHandlingMessages();
                }
            }
            catch (Exception ex)
            {
                adapterChannel.SendError(ex);
            }
        }
예제 #26
0
파일: Program.cs 프로젝트: krytarowski/cli
        public int DoRun(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var dotnetTestParams = new DotnetTestParams();

            dotnetTestParams.Parse(args);

            try
            {
                if (dotnetTestParams.Help)
                {
                    return 0;
                }

                // Register for parent process's exit event
                if (dotnetTestParams.ParentProcessId.HasValue)
                {
                    RegisterForParentProcessExit(dotnetTestParams.ParentProcessId.Value);
                }

                var projectContexts = CreateProjectContexts(dotnetTestParams.ProjectPath);

                var projectContext = projectContexts.First();

                var testRunner = projectContext.ProjectFile.TestRunner;

                IDotnetTestRunner dotnetTestRunner = _dotnetTestRunnerFactory.Create(dotnetTestParams.Port);

                return dotnetTestRunner.RunTests(projectContext, dotnetTestParams);
            }
            catch (InvalidOperationException ex)
            {
                TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                return -1;
            }
            catch (Exception ex)
            {
                TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                return -2;
            }
        }
예제 #27
0
        public IDotnetTestRunner Create(DotnetTestParams dotnetTestParams)
        {
            Func <ICommandFactory, string, NuGetFramework, IDotnetTestRunner> nextTestRunner =
                (commandFactory, assemblyUnderTest, framework) =>
            {
                var dotnetTestRunnerResolver = _dotnetTestRunnerResolverFactory.Create(dotnetTestParams);

                IDotnetTestRunner testRunner =
                    new ConsoleTestRunner(dotnetTestRunnerResolver, commandFactory, assemblyUnderTest, framework);
                if (dotnetTestParams.Port.HasValue)
                {
                    testRunner = new DesignTimeRunner(dotnetTestRunnerResolver, commandFactory, assemblyUnderTest);
                }

                return(testRunner);
            };

            return(dotnetTestParams.IsTestingAssembly
                ? CreateTestRunnerForAssembly(nextTestRunner)
                : CreateTestRunnerForProjectJson(nextTestRunner));
        }
        public GivenThatWeWantToParseArgumentsForDotnetTest()
        {
            _dotnetTestFullParams = new DotnetTestParams();
            _emptyDotnetTestParams = new DotnetTestParams();

            _dotnetTestFullParams.Parse(new[]
            {
                ProjectJson,
                "--parentProcessId", ParentProcessId.ToString(),
                "--port", Port.ToString(),
                "--framework", Framework,
                "--output", Output,
                "--build-base-path", BuildBasePath,
                "--configuration", Config,
                "--runtime", Runtime,
                "--no-build",
                "--additional-parameters", "additional-parameter-value"
            });

            _emptyDotnetTestParams.Parse(new string[] { });
        }
예제 #29
0
        internal override int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
        {
            try
            {
                var commandFactory =
                    new ProjectDependenciesCommandFactory(
                        projectContext.TargetFramework,
                        dotnetTestParams.Config,
                        dotnetTestParams.Output,
                        dotnetTestParams.BuildBasePath,
                        projectContext.ProjectDirectory);

                return(commandFactory.Create(
                           GetCommandName(projectContext.ProjectFile.TestRunner),
                           GetCommandArgs(projectContext, dotnetTestParams),
                           projectContext.TargetFramework,
                           dotnetTestParams.Config)
                       .ForwardStdErr()
                       .ForwardStdOut()
                       .Execute()
                       .ExitCode);
            }
            catch (CommandUnknownException e)
            {
                var commandFactory =
                    new DotNetCommandFactory();

                return(commandFactory.Create(
                           GetDotNetCommandName(projectContext.ProjectFile.TestRunner),
                           GetCommandArgs(projectContext, dotnetTestParams),
                           projectContext.TargetFramework,
                           dotnetTestParams.Config)
                       .ForwardStdErr()
                       .ForwardStdOut()
                       .Execute()
                       .ExitCode);
            }
        }
예제 #30
0
        private int RunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
        {
            var result = _testProjectBuilder.BuildTestProject(projectContext, dotnetTestParams);

            if (result == 0)
            {
                var commandFactory =
                    new ProjectDependenciesCommandFactory(
                        projectContext.TargetFramework,
                        dotnetTestParams.Config,
                        dotnetTestParams.Output,
                        dotnetTestParams.BuildBasePath,
                        projectContext.ProjectDirectory);

                var assemblyUnderTest = new AssemblyUnderTest(projectContext, dotnetTestParams);

                var framework = projectContext.TargetFramework;

                result = _nextRunner(commandFactory, assemblyUnderTest.Path, framework).RunTests(dotnetTestParams);
            }

            return(result);
        }
예제 #31
0
        private int DoBuildTestProject(DotnetTestParams dotnetTestParams)
        {
            var strings = new List<string>
            {
                $"--configuration",
                dotnetTestParams.Config,
                $"{dotnetTestParams.ProjectPath}"
            };

            if (dotnetTestParams.Framework != null)
            {
                strings.Add("--framework");
                strings.Add($"{dotnetTestParams.Framework}");
            }

            if (!string.IsNullOrEmpty(dotnetTestParams.BuildBasePath))
            {
                strings.Add("--build-base-path");
                strings.Add(dotnetTestParams.BuildBasePath);
            }

            if (!string.IsNullOrEmpty(dotnetTestParams.Output))
            {
                strings.Add("--output");
                strings.Add(dotnetTestParams.Output);
            }

            if (!string.IsNullOrEmpty(dotnetTestParams.Runtime))
            {
                strings.Add("--runtime");
                strings.Add(dotnetTestParams.Runtime);
            }

            var result = Build.BuildCommand.Run(strings.ToArray());

            return result;
        }
예제 #32
0
        private int DoBuildTestProject(DotnetTestParams dotnetTestParams)
        {
            var strings = new List <string>
            {
                $"--configuration",
                dotnetTestParams.Config,
                $"{dotnetTestParams.ProjectPath}"
            };

            if (dotnetTestParams.Framework != null)
            {
                strings.Add("--framework");
                strings.Add($"{dotnetTestParams.Framework}");
            }

            if (!string.IsNullOrEmpty(dotnetTestParams.BuildBasePath))
            {
                strings.Add("--build-base-path");
                strings.Add(dotnetTestParams.BuildBasePath);
            }

            if (!string.IsNullOrEmpty(dotnetTestParams.Output))
            {
                strings.Add("--output");
                strings.Add(dotnetTestParams.Output);
            }

            if (!string.IsNullOrEmpty(dotnetTestParams.Runtime))
            {
                strings.Add("--runtime");
                strings.Add(dotnetTestParams.Runtime);
            }

            var result = Build.BuildCommand.Run(strings.ToArray());

            return(result);
        }
예제 #33
0
        private int DoBuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
        {
            var strings = new List<string>
            {
                $"--configuration",
                dotnetTestParams.Config,
                $"{dotnetTestParams.ProjectPath}"
            };

            // Build the test specifically for the target framework \ rid of the ProjectContext. This avoids building the project
            // for tfms that the user did not request.
            strings.Add("--framework");
            strings.Add(projectContext.TargetFramework.ToString());

            if (!string.IsNullOrEmpty(dotnetTestParams.BuildBasePath))
            {
                strings.Add("--build-base-path");
                strings.Add(dotnetTestParams.BuildBasePath);
            }

            if (!string.IsNullOrEmpty(dotnetTestParams.Output))
            {
                strings.Add("--output");
                strings.Add(dotnetTestParams.Output);
            }

            if (!string.IsNullOrEmpty(projectContext.RuntimeIdentifier))
            {
                strings.Add("--runtime");
                strings.Add(projectContext.RuntimeIdentifier);
            }

            var result = Build.BuildCommand.Run(strings.ToArray(), workspace);

            return result;
        }
예제 #34
0
        private int DoBuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
        {
            var strings = new List <string>
            {
                $"--configuration",
                dotnetTestParams.Config,
                $"{dotnetTestParams.ProjectPath}"
            };

            // Build the test specifically for the target framework \ rid of the ProjectContext. This avoids building the project
            // for tfms that the user did not request.
            strings.Add("--framework");
            strings.Add(projectContext.TargetFramework.ToString());

            if (!string.IsNullOrEmpty(dotnetTestParams.BuildBasePath))
            {
                strings.Add("--build-base-path");
                strings.Add(dotnetTestParams.BuildBasePath);
            }

            if (!string.IsNullOrEmpty(dotnetTestParams.Output))
            {
                strings.Add("--output");
                strings.Add(dotnetTestParams.Output);
            }

            if (!string.IsNullOrEmpty(projectContext.RuntimeIdentifier))
            {
                strings.Add("--runtime");
                strings.Add(projectContext.RuntimeIdentifier);
            }

            var result = Build.BuildCommand.Run(strings.ToArray(), workspace);

            return(result);
        }
예제 #35
0
 public AssemblyUnderTest(ProjectContext projectContext, DotnetTestParams dotentTestParams)
 {
     _projectContext   = projectContext;
     _dotentTestParams = dotentTestParams;
 }
예제 #36
0
 internal abstract int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams);
예제 #37
0
        public int RunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
        {
            var result = BuildTestProject(projectContext, dotnetTestParams, workspace);

            return result == 0 ? DoRunTests(projectContext, dotnetTestParams) : result;
        }
        public void It_throws_InvalidOperationException_if_an_invalid_port_is_passed_to_it()
        {
            var dotnetTestParams = new DotnetTestParams();
            const string invalidPort = "door";
            Action action = () => dotnetTestParams.Parse(new[] { "--port", invalidPort });

            action
                .ShouldThrow<InvalidOperationException>()
                .WithMessage($"{invalidPort} is not a valid port number.");
        }
예제 #39
0
        public int RunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
        {
            var result = BuildTestProject(projectContext, dotnetTestParams, workspace);

            return(result == 0 ? DoRunTests(projectContext, dotnetTestParams) : result);
        }
예제 #40
0
 internal abstract int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams);
예제 #41
0
 private int RunTest(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
 {
     var testRunner = projectContext.ProjectFile.TestRunner;
     var dotnetTestRunner = _dotnetTestRunnerFactory.Create(dotnetTestParams.Port);
     return dotnetTestRunner.RunTests(projectContext, dotnetTestParams, workspace);
 }
        public void It_sets_the_framework_to_unsupported_when_an_invalid_framework_is_passed_in()
        {
            var dotnetTestParams = new DotnetTestParams();
            dotnetTestParams.Parse(new[] { "--framework", "farm work" });

            dotnetTestParams.Framework.DotNetFrameworkName.Should().Be("Unsupported,Version=v0.0");
        }
        public void It_sets_Help_to_true_when_help_is_passed_in()
        {
            var dotnetTestParams = new DotnetTestParams();
            dotnetTestParams.Parse(new[] { "--help" });

            dotnetTestParams.Help.Should().BeTrue();
        }
예제 #44
0
파일: TestCommand.cs 프로젝트: wtgodbe/cli
        private int RunTest(DotnetTestParams dotnetTestParams)
        {
            var dotnetTestRunner = _dotnetTestRunnerFactory.Create(dotnetTestParams);

            return(dotnetTestRunner.RunTests(dotnetTestParams));
        }
예제 #45
0
 public int BuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
 {
     return(dotnetTestParams.NoBuild ? 0 : DoBuildTestProject(projectContext, dotnetTestParams));
 }
예제 #46
0
        public int DoRun(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var dotnetTestParams = new DotnetTestParams();

            try
            {
                dotnetTestParams.Parse(args);

                if (dotnetTestParams.Help)
                {
                    return(0);
                }

                // Register for parent process's exit event
                if (dotnetTestParams.ParentProcessId.HasValue)
                {
                    RegisterForParentProcessExit(dotnetTestParams.ParentProcessId.Value);
                }

                var projectPath        = GetProjectPath(dotnetTestParams.ProjectPath);
                var runtimeIdentifiers = !string.IsNullOrEmpty(dotnetTestParams.Runtime) ?
                                         new[] { dotnetTestParams.Runtime } :
                RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers();
                var exitCode = 0;

                // Create a workspace
                var workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment());

                if (dotnetTestParams.Framework != null)
                {
                    var projectContext = workspace.GetProjectContext(projectPath, dotnetTestParams.Framework);
                    if (projectContext == null)
                    {
                        Reporter.Error.WriteLine($"Project '{projectPath}' does not support framework: {dotnetTestParams.UnparsedFramework}");
                        return(1);
                    }
                    projectContext = workspace.GetRuntimeContext(projectContext, runtimeIdentifiers);

                    exitCode = RunTest(projectContext, dotnetTestParams, workspace);
                }
                else
                {
                    var summary         = new Summary();
                    var projectContexts = workspace.GetProjectContextCollection(projectPath)
                                          .EnsureValid(projectPath)
                                          .FrameworkOnlyContexts
                                          .Select(c => workspace.GetRuntimeContext(c, runtimeIdentifiers))
                                          .ToList();

                    // Execute for all TFMs the project targets.
                    foreach (var projectContext in projectContexts)
                    {
                        var result = RunTest(projectContext, dotnetTestParams, workspace);
                        if (result == 0)
                        {
                            summary.Passed++;
                        }
                        else
                        {
                            summary.Failed++;
                            if (exitCode == 0)
                            {
                                // If tests fail in more than one TFM, we'll have it use the result of the first one
                                // as the exit code.
                                exitCode = result;
                            }
                        }
                    }

                    summary.Print();
                }

                return(exitCode);
            }
            catch (InvalidOperationException ex)
            {
                TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                return(-1);
            }
            catch (Exception ex) when(!(ex is GracefulException))
            {
                TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                return(-2);
            }
        }
예제 #47
0
 public AssemblyUnderTest(ProjectContext projectContext, DotnetTestParams dotentTestParams)
 {
     _projectContext = projectContext;
     _dotentTestParams = dotentTestParams;
 }
예제 #48
0
        public int RunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
        {
            var result = BuildTestProject(dotnetTestParams);

            return result == 0 ? DoRunTests(projectContext, dotnetTestParams) : result;
        }
예제 #49
0
        private ITestRunnerNameResolver GetProjectJsonTestRunnerResolver(DotnetTestParams dotnetTestParams)
        {
            var project = _projectReader.ReadProject(dotnetTestParams.ProjectOrAssemblyPath);

            return(new ProjectJsonTestRunnerNameResolver(project));
        }
예제 #50
0
        public int DoRun(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var dotnetTestParams = new DotnetTestParams();

            try
            {
                dotnetTestParams.Parse(args);
            
                if (dotnetTestParams.Help)
                {
                    return 0;
                }

                // Register for parent process's exit event
                if (dotnetTestParams.ParentProcessId.HasValue)
                {
                    RegisterForParentProcessExit(dotnetTestParams.ParentProcessId.Value);
                }

                var projectPath = GetProjectPath(dotnetTestParams.ProjectPath);
                var runtimeIdentifiers = !string.IsNullOrEmpty(dotnetTestParams.Runtime) ?
                    new[] { dotnetTestParams.Runtime } :
                    RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers();
                var exitCode = 0;

                // Create a workspace
                var workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment());

                if (dotnetTestParams.Framework != null)
                {
                    var projectContext = workspace.GetProjectContext(projectPath, dotnetTestParams.Framework);
                    if (projectContext == null)
                    {
                        Reporter.Error.WriteLine($"Project '{projectPath}' does not support framework: {dotnetTestParams.UnparsedFramework}");
                        return 1;
                    }
                    projectContext = workspace.GetRuntimeContext(projectContext, runtimeIdentifiers);

                    exitCode = RunTest(projectContext, dotnetTestParams, workspace);
                }
                else
                {
                    var summary = new Summary();
                    var projectContexts = workspace.GetProjectContextCollection(projectPath)
                        .EnsureValid(projectPath)
                        .FrameworkOnlyContexts
                        .Select(c => workspace.GetRuntimeContext(c, runtimeIdentifiers))
                        .ToList();

                    // Execute for all TFMs the project targets.
                    foreach (var projectContext in projectContexts)
                    {
                        var result = RunTest(projectContext, dotnetTestParams, workspace);
                        if (result == 0)
                        {
                            summary.Passed++;
                        }
                        else
                        {
                            summary.Failed++;
                            if (exitCode == 0)
                            {
                                // If tests fail in more than one TFM, we'll have it use the result of the first one
                                // as the exit code.
                                exitCode = result;
                            }
                        }
                    }

                    summary.Print();
                }

                return exitCode;
            }
            catch (InvalidOperationException ex)
            {
                TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                return -1;
            }
            catch (Exception ex) when (!(ex is GracefulException))
            {
                TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                return -2;
            }
        }