public void DiscoverTests(IEnumerable <string> sources, IDiscoveryContext discoveryContext, IMessageLogger log, ITestCaseDiscoverySink discoverySink) { log.Version(); RemotingUtility.CleanUpRegisteredChannels(); foreach (var assemblyPath in sources) { try { if (AssemblyDirectoryContainsFixie(assemblyPath)) { log.Info("Processing " + assemblyPath); var sourceLocationProvider = new SourceLocationProvider(assemblyPath); using (var environment = new ExecutionEnvironment(assemblyPath)) { var methodGroups = environment.DiscoverTestMethodGroups(new Options()); foreach (var methodGroup in methodGroups) { var testCase = new TestCase(methodGroup.FullName, VsTestExecutor.Uri, assemblyPath); try { SourceLocation sourceLocation; if (sourceLocationProvider.TryGetSourceLocation(methodGroup, out sourceLocation)) { testCase.CodeFilePath = sourceLocation.CodeFilePath; testCase.LineNumber = sourceLocation.LineNumber; } } catch (Exception exception) { log.Error(exception); } discoverySink.SendTestCase(testCase); } } } else { log.Info("Skipping " + assemblyPath + " because it is not a test assembly."); } } catch (Exception exception) { log.Error(exception); } } }
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger log, ITestCaseDiscoverySink discoverySink) { log.Version(); RemotingUtility.CleanUpRegisteredChannels(); foreach (var assemblyPath in sources) { try { if (AssemblyDirectoryContainsFixie(assemblyPath)) { log.Info("Processing " + assemblyPath); var sourceLocationProvider = new SourceLocationProvider(assemblyPath); using (var environment = new ExecutionEnvironment(assemblyPath)) { var methodGroups = environment.DiscoverTestMethodGroups(new Options()); foreach (var methodGroup in methodGroups) { var testCase = new TestCase(methodGroup.FullName, VsTestExecutor.Uri, assemblyPath); try { SourceLocation sourceLocation; if (sourceLocationProvider.TryGetSourceLocation(methodGroup, out sourceLocation)) { testCase.CodeFilePath = sourceLocation.CodeFilePath; testCase.LineNumber = sourceLocation.LineNumber; } } catch (Exception exception) { log.Error(exception); } discoverySink.SendTestCase(testCase); } } } else { log.Info("Skipping " + assemblyPath + " because it is not a test assembly."); } } catch (Exception exception) { log.Error(exception); } } }
public void Record(PipeMessage.TestDiscovered testDiscovered) { var test = testDiscovered.Test; SourceLocation sourceLocation = null; try { sourceLocationProvider.TryGetSourceLocation(test.Class, test.Method, out sourceLocation); } catch (Exception exception) { log.Error(exception.ToString()); } var discoveredTest = new TestCase(test.Name, VsTestExecutor.Uri, assemblyPath) { DisplayName = test.Name }; if (sourceLocation != null) { discoveredTest.CodeFilePath = sourceLocation.CodeFilePath; discoveredTest.LineNumber = sourceLocation.LineNumber; } discoverySink.SendTestCase(discoveredTest); }
public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { IMessageLogger log = frameworkHandle; log.Version(); HandlePoorVisualStudioImplementationDetails(runContext, frameworkHandle); foreach (var assemblyPath in sources) { try { if (AssemblyDirectoryContainsFixie(assemblyPath)) { log.Info("Processing " + assemblyPath); var listener = new VisualStudioListener(frameworkHandle, assemblyPath); using (var environment = new ExecutionEnvironment(assemblyPath)) { environment.RunAssembly(new Options(), listener); } } else { log.Info("Skipping " + assemblyPath + " because it is not a test assembly."); } } catch (Exception exception) { log.Error(exception); } } }
static void DiscoverTests(IMessageLogger log, ITestCaseDiscoverySink discoverySink, string assemblyPath) { 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)) { pipe.WaitForConnection(); pipe.Send <PipeMessage.DiscoverTests>(); var recorder = new DiscoveryRecorder(log, discoverySink, assemblyPath); while (true) { var messageType = pipe.ReceiveMessage(); if (messageType == typeof(PipeMessage.TestDiscovered).FullName) { var testDiscovered = pipe.Receive <PipeMessage.TestDiscovered>(); recorder.Record(testDiscovered); } 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 { throw new TestProcessExitException(process.TryGetExitCode()); } } } }
private void OnMessageConsume(Message message) { try { _logger.Begin(message); var processor = _processorFactory.MakeProcessorFor(message); processor.Execute(); } catch (Exception exp) { _logger.Error(message, exp); } finally { _logger.End(message); } }
public void Run(MessageConfiguration config) { Bind(config.Handler.FullName, config.RoutingKey, connectionConfiguration.Exchange); Channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false); var consumer = new EventingBasicConsumer(Channel); consumer.Received += (sender, e) => { try { var message = Encoding.UTF8.GetString(e.Body); messageLogger.Info($" [x] Received '{e.RoutingKey}':'{message}'"); var handler = handlerFactory.Resolve(config.Handler.FullName); handler.Handle(message); handlerFactory.Release(handler); Channel.BasicAck(deliveryTag: e.DeliveryTag, multiple: false); } catch (Exception exception) { Channel.BasicReject(deliveryTag: e.DeliveryTag, requeue: false); if (e.BasicProperties.Headers == null) { e.BasicProperties.Headers = new Dictionary <string, object>(); } e.BasicProperties.Headers.Add("Queue", config.Handler.FullName); Channel.BasicPublish(exchange: connectionConfiguration.PoisionExchange, routingKey: config.RoutingKey, basicProperties: e.BasicProperties, body: e.Body); messageLogger.Error(exception); throw; } }; Channel.BasicConsume(queue: config.Handler.FullName, autoAck: false, consumer: consumer); }
public void RunTests(IEnumerable <TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle) { IMessageLogger log = frameworkHandle; log.Version(); HandlePoorVisualStudioImplementationDetails(runContext, frameworkHandle); var assemblyGroups = tests.GroupBy(tc => tc.Source); foreach (var assemblyGroup in assemblyGroups) { var assemblyPath = assemblyGroup.Key; try { if (AssemblyDirectoryContainsFixie(assemblyPath)) { log.Info("Processing " + assemblyPath); var methodGroups = assemblyGroup.Select(x => new MethodGroup(x.FullyQualifiedName)).ToArray(); var listener = new VisualStudioListener(frameworkHandle, assemblyPath); using (var environment = new ExecutionEnvironment(assemblyPath)) { environment.RunMethods(new Options(), listener, methodGroups); } } else { log.Info("Skipping " + assemblyPath + " because it is not a test assembly."); } } catch (Exception exception) { log.Error(exception); } } }
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; } } } }