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); }
static void AssertNoLineNumber(string className, string methodName) { var sourceLocationProvider = new SourceLocationProvider(TestAssemblyPath); SourceLocation location; var success = sourceLocationProvider.TryGetSourceLocation(new MethodGroup(className + "." + methodName), out location); success.ShouldBeFalse(); location.ShouldBeNull(); }
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); } } }
static void AssertLineNumber(string className, string methodName, int debugLine, int releaseLine) { var sourceLocationProvider = new SourceLocationProvider(TestAssemblyPath); SourceLocation location; var success = sourceLocationProvider.TryGetSourceLocation(new MethodGroup(className + "." + methodName), out location); location.CodeFilePath.EndsWith("SourceLocationSamples.cs").ShouldBeTrue(); #if DEBUG location.LineNumber.ShouldEqual(debugLine); #else location.LineNumber.ShouldEqual(releaseLine); #endif }