Пример #1
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);
                }

                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
        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
        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;
            }
        }