static void RunTests(IMessageLogger log, IFrameworkHandle frameworkHandle, string assemblyPath, Action <NamedPipeServerStream> sendCommand) { if (!IsTestAssembly(assemblyPath)) { log.Info("Skipping " + assemblyPath + " because it is not a test assembly."); return; } log.Info("Processing " + assemblyPath); var pipeName = Guid.NewGuid().ToString(); Environment.SetEnvironmentVariable("FIXIE_NAMED_PIPE", pipeName); using (var pipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Message)) using (var process = Start(assemblyPath, frameworkHandle)) { pipe.WaitForConnection(); sendCommand(pipe); var recorder = new ExecutionRecorder(frameworkHandle, assemblyPath); PipeMessage.CaseStarted lastCaseStarted = null; while (true) { var messageType = pipe.ReceiveMessage(); if (messageType == typeof(PipeMessage.CaseStarted).FullName) { var message = pipe.Receive <PipeMessage.CaseStarted>(); lastCaseStarted = message; recorder.Record(message); } else if (messageType == typeof(PipeMessage.CaseSkipped).FullName) { var testResult = pipe.Receive <PipeMessage.CaseSkipped>(); recorder.Record(testResult); } else if (messageType == typeof(PipeMessage.CasePassed).FullName) { var testResult = pipe.Receive <PipeMessage.CasePassed>(); recorder.Record(testResult); } else if (messageType == typeof(PipeMessage.CaseFailed).FullName) { var testResult = pipe.Receive <PipeMessage.CaseFailed>(); recorder.Record(testResult); } else if (messageType == typeof(PipeMessage.Exception).FullName) { var exception = pipe.Receive <PipeMessage.Exception>(); throw new RunnerException(exception); } else if (messageType == typeof(PipeMessage.Completed).FullName) { var completed = pipe.Receive <PipeMessage.Completed>(); break; } else if (!string.IsNullOrEmpty(messageType)) { var body = pipe.ReceiveMessage(); log.Error($"The test runner received an unexpected message of type {messageType}: {body}"); } else { var exception = new TestProcessExitException(process.TryGetExitCode()); if (lastCaseStarted != null) { recorder.Record(new PipeMessage.CaseFailed { Test = lastCaseStarted.Test, Name = lastCaseStarted.Name, Exception = new PipeMessage.Exception(exception) }); } throw exception; } } } }
public void Record(PipeMessage.CaseStarted message) { var testCase = ToVsTestCase(message.Test); log.RecordStart(testCase); }