IEnumerable <string> SetupSinks() { IEnumerable <string> testList = Enumerable.Empty <string>(); if (_options.PortSpecified) { _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _socket.Connect(new IPEndPoint(IPAddress.Loopback, _options.Port)); var networkStream = new NetworkStream(_socket); SetupRemoteTestSinks(networkStream); if (_options.WaitCommand) { var reader = new BinaryReader(networkStream); _testExecutionSink.SendWaitingCommand(); var rawMessage = reader.ReadString(); var message = JsonConvert.DeserializeObject <Message>(rawMessage); testList = message.Payload.ToObject <RunTestsMessage>().Tests; } } else { SetupConsoleTestSinks(); } return(testList); }
public int Run(string[] args) { try { var reporters = GetAvailableRunnerReporters(); if (args.Length == 0 || args.Any(arg => arg == "-?" || arg == "-help")) { PrintHeader(); PrintUsage(reporters); return(2); } #if !NETCOREAPP1_0 AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; #endif var commandLine = CommandLine.Parse(reporters, args); #if !NETCOREAPP1_0 if (commandLine.Debug) { Debugger.Launch(); } #else if (commandLine.Debug) { Console.WriteLine("Debug support is not available in .NET Core."); return(2); } #endif logger = new ConsoleRunnerLogger(!commandLine.NoColor); reporterMessageHandler = MessageSinkWithTypesAdapter.Wrap(commandLine.Reporter.CreateMessageHandler(logger)); if (!commandLine.NoLogo) { PrintHeader(); } var testsToRun = commandLine.DesignTimeTestUniqueNames; if (commandLine.Port.HasValue) { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); var ipEndPoint = new IPEndPoint(IPAddress.Loopback, commandLine.Port.Value); socket.Connect(ipEndPoint); var networkStream = new NetworkStream(socket); UseTestSinksWithSockets(networkStream); if (commandLine.WaitCommand) { var reader = new BinaryReader(networkStream); testExecutionSink.SendWaitingCommand(); var rawMessage = reader.ReadString(); var message = JsonConvert.DeserializeObject <Message>(rawMessage); testsToRun = message.Payload.ToObject <RunTestsMessage>().Tests; } } else { UseTestSinksWithStandardOutputStreams(); } var failCount = RunProject(commandLine.Project, commandLine.ParallelizeAssemblies, commandLine.ParallelizeTestCollections, commandLine.MaxParallelThreads, commandLine.DiagnosticMessages, commandLine.NoColor, commandLine.AppDomains, commandLine.FailSkips, commandLine.DesignTime, commandLine.List, testsToRun); if (commandLine.Wait) { WaitForInput(); } return(failCount > 0 ? 1 : 0); } catch (ArgumentException ex) { Console.WriteLine("error: {0}", ex.Message); return(3); } catch (BadImageFormatException ex) { Console.WriteLine("{0}", ex.Message); return(4); } finally { Console.ResetColor(); } }