public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { ValidateArg.NotNull(frameworkHandle, "frameworkHandle"); ValidateArg.NotNullOrEmpty(sources, "sources"); if (!this.MSTestDiscoverer.AreValidSources(sources)) { throw new NotSupportedException(); } // Populate the runsettings. MSTestSettings.PopulateSettings(runContext); // Scenarios that include testsettings or forcing a run via the legacy adapter are currently not supported in MSTestAdapter. if (MSTestSettings.IsLegacyScenario(frameworkHandle)) { return; } sources = PlatformServiceProvider.Instance.TestSource.GetTestSources(sources); this.cancellationToken = new TestRunCancellationToken(); this.TestExecutionManager.RunTests(sources, runContext, frameworkHandle, this.cancellationToken); this.cancellationToken = null; }
/// <summary> /// Adds tests to document and saves document to file /// </summary> /// <param name="testSequence"> /// The test Sequence. /// </param> /// <param name="filePath"> /// The file Path. /// </param> /// <returns>File path</returns> public string WriteTestSequence(List <TestCase> testSequence, string filePath) { ValidateArg.NotNull(testSequence, nameof(testSequence)); ValidateArg.NotNullOrEmpty(filePath, nameof(filePath)); filePath = filePath + ".xml"; // Writing test sequence var xmlDocument = new XmlDocument(); var xmlDeclaration = xmlDocument.CreateNode(XmlNodeType.XmlDeclaration, string.Empty, string.Empty); var blameTestRoot = xmlDocument.CreateElement(Constants.BlameRootNode); xmlDocument.AppendChild(xmlDeclaration); foreach (var testCase in testSequence) { var testElement = xmlDocument.CreateElement(Constants.BlameTestNode); testElement.SetAttribute(Constants.TestNameAttribute, testCase.FullyQualifiedName); testElement.SetAttribute(Constants.TestSourceAttribute, testCase.Source); blameTestRoot.AppendChild(testElement); } xmlDocument.AppendChild(blameTestRoot); using (var stream = this.fileHelper.GetStream(filePath, FileMode.Create)) { xmlDocument.Save(stream); } return(filePath); }
/// <summary> /// Initializes a new instance of the <see cref="TestRunCriteria"/> class. /// </summary> /// /// <param name="sources">Sources which contains tests that should be executed.</param> /// <param name="frequencyOfRunStatsChangeEvent">Frequency of run stats event.</param> /// <param name="keepAlive"> /// Whether the execution process should be kept alive after the run is finished or not. /// </param> /// <param name="testSettings">Settings used for this run.</param> /// <param name="runStatsChangeEventTimeout"> /// Timeout that triggers sending results regardless of cache size. /// </param> /// <param name="testHostLauncher"> /// Test host launcher. If null then default will be used. /// </param> /// <param name="testCaseFilter">Test case filter.</param> /// <param name="filterOptions">Filter options.</param> /// <param name="testSessionInfo">The test session info object.</param> /// <param name="debugEnabledForTestSession"> /// Indicates if debugging should be enabled when we have test session info available. /// </param> public TestRunCriteria( IEnumerable <string> sources, long frequencyOfRunStatsChangeEvent, bool keepAlive, string testSettings, TimeSpan runStatsChangeEventTimeout, ITestHostLauncher testHostLauncher, string testCaseFilter, FilterOptions filterOptions, TestSessionInfo testSessionInfo, bool debugEnabledForTestSession) : base( frequencyOfRunStatsChangeEvent, keepAlive, testSettings, runStatsChangeEventTimeout, testHostLauncher) { var testSources = sources as IList <string> ?? sources.ToList(); ValidateArg.NotNullOrEmpty(testSources, nameof(sources)); this.AdapterSourceMap = new Dictionary <string, IEnumerable <string> >(); this.AdapterSourceMap.Add(Constants.UnspecifiedAdapterPath, testSources); this.TestCaseFilter = testCaseFilter; this.FilterOptions = filterOptions; this.TestSessionInfo = testSessionInfo; this.DebugEnabledForTestSession = debugEnabledForTestSession; }
public void RunTests(IEnumerable <TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle) { ValidateArg.NotNull(frameworkHandle, "frameworkHandle"); ValidateArg.NotNullOrEmpty(tests, "tests"); if (!this.MSTestDiscoverer.AreValidSources(from test in tests select test.Source)) { throw new NotSupportedException(); } // Populate the runsettings. try { MSTestSettings.PopulateSettings(runContext); } catch (AdapterSettingsException ex) { frameworkHandle.SendMessage(TestMessageLevel.Error, ex.Message); return; } // Scenarios that include testsettings or forcing a run via the legacy adapter are currently not supported in MSTestAdapter. if (MSTestSettings.IsLegacyScenario(frameworkHandle)) { return; } this.cancellationToken = new TestRunCancellationToken(); this.TestExecutionManager.RunTests(tests, runContext, frameworkHandle, this.cancellationToken); this.cancellationToken = null; }
public StackFrame GetStackFrame(string line) { ValidateArg.NotNullOrEmpty(line, "line"); Match match = frameWithFileInfoRegex.Match(line); if (match.Success) { string methodName = match.Groups["methodName"].Value; string fileName = match.Groups["fileName"].Value; int lineNumber; if (!int.TryParse(match.Groups["lineNumber"].Value, out lineNumber)) { lineNumber = 0; } return(new StackFrame(methodName, fileName, lineNumber)); } match = frameWithoutFileInfoRegex.Match(line); if (match.Success) { string methodName = match.Groups["methodName"].Value; return(new StackFrame(methodName)); } return(null); }
public NSpecTestContainer( ITestContainerDiscoverer containerDiscoverer, string sourcePath, IEnumerable <Guid> debugEngines, IFileService fileService) { ValidateArg.NotNull(containerDiscoverer, "containerDiscoverer"); ValidateArg.NotNullOrEmpty(sourcePath, "sourcePath"); ValidateArg.NotNull(debugEngines, "debugEngines"); ValidateArg.NotNull(fileService, "fileService"); this.containerDiscoverer = containerDiscoverer; this.sourcePath = sourcePath; this.debugEngines = debugEngines; this.fileService = fileService; if (fileService.Exists(sourcePath)) { timeStamp = fileService.LastModified(sourcePath); } else { timeStamp = DateTime.MinValue; } }
public void AddWatch(string path) { ValidateArg.NotNullOrEmpty(path, "path"); if (!String.IsNullOrEmpty(path)) { var directoryName = Path.GetDirectoryName(path); if (!Directory.Exists(directoryName)) { return; } var fileName = Path.GetFileName(path); FileWatcherInfo watcherInfo; if (!fileWatchers.TryGetValue(path, out watcherInfo)) { var watcher = new FileSystemWatcher(directoryName, fileName); watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; watcherInfo = new FileWatcherInfo(watcher); fileWatchers.Add(path, watcherInfo); watcherInfo.Watcher.Changed += OnChanged; watcherInfo.Watcher.Created += OnChanged; watcherInfo.Watcher.Deleted += OnChanged; watcherInfo.Watcher.Renamed += OnChanged; watcherInfo.Watcher.EnableRaisingEvents = true; } } }
public void AddWatch(string path) { ValidateArg.NotNullOrEmpty(path, "path"); if (!String.IsNullOrEmpty(path)) { var directoryName = Path.GetDirectoryName(path); var fileName = Path.GetFileName(path); FileWatcherInfo watcherInfo; if (!fileWatchers.TryGetValue(path, out watcherInfo)) { watcherInfo = new FileWatcherInfo(new FileSystemWatcher(directoryName, fileName)); if (fileWatchers.TryAdd(path, watcherInfo)) { watcherInfo.Watcher.Changed += OnChanged; // We are monitoring for this file to be renamed. // This is needed to catch file modifications in VS2013+. In these version VS won't update an existing file. // It will create a new file, and then delete old one and swap in the new one transactionally watcherInfo.Watcher.Renamed += OnRenamed; watcherInfo.Watcher.EnableRaisingEvents = true; } } } }
public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from sources."); ValidateArg.NotNull(frameworkHandle, "frameworkHandle"); ValidateArg.NotNullOrEmpty(sources, "sources"); if (!this.MSTestDiscoverer.AreValidSources(sources)) { throw new NotSupportedException(); } // Populate the runsettings. try { MSTestSettings.PopulateSettings(runContext); } catch (AdapterSettingsException ex) { frameworkHandle.SendMessage(TestMessageLevel.Error, ex.Message); return; } // Scenarios that include testsettings or forcing a run via the legacy adapter are currently not supported in MSTestAdapter. if (MSTestSettings.IsLegacyScenario(frameworkHandle)) { return; } sources = PlatformServiceProvider.Instance.TestSource.GetTestSources(sources); this.cancellationToken = new TestRunCancellationToken(); this.TestExecutionManager.RunTests(sources, runContext, frameworkHandle, this.cancellationToken); this.cancellationToken = null; }
public void AddWatch(string path) { ValidateArg.NotNullOrEmpty(path, "path"); if (string.IsNullOrEmpty(path)) { return; } var directoryName = Path.GetDirectoryName(path); var fileName = Path.GetFileName(path); FileWatcherInfo watcherInfo; if (this._fileWatchers.TryGetValue(path, out watcherInfo)) { return; } Debug.Assert(directoryName != null, "directoryName != null"); watcherInfo = new FileWatcherInfo(new FileSystemWatcher(directoryName, fileName)) { Hash = ComputeHash( Path.Combine(directoryName, fileName)) }; this._fileWatchers.Add(path, watcherInfo); watcherInfo.Watcher.Changed += this.OnChanged; watcherInfo.Watcher.Deleted += this.OnDeleted; watcherInfo.Watcher.EnableRaisingEvents = true; }
/// <summary> /// Initializes a new instance of the <see cref="AILoadout"/> class. /// </summary> /// <param name="oldLabel"></param> public AILoadout(string oldLabel) { ValidateArg.NotNullOrEmpty(oldLabel, nameof(oldLabel)); label = LoadoutManager.GetIncrementalLabel(oldLabel); Init(); }
/// <summary> /// Gets property value /// </summary> /// <param name="property"> /// Property name /// </param> public object GetPropertyValue(string property) { ValidateArg.NotNullOrEmpty(property, "property"); this.Properties.TryGetValue(property, out object propertyValue); return(propertyValue); }
/// <summary> /// Initializes a new instance of the <see cref="TestRunCriteria"/> class. /// </summary> /// <param name="tests"> /// Sources which contains tests that should be executed /// </param> /// <param name="frequencyOfRunStatsChangeEvent"> /// Frequency of run stats event /// </param> /// <param name="keepAlive"> /// Whether or not to keep the test executor process alive after run completion /// </param> /// <param name="testSettings"> /// Settings used for this run. /// </param> /// <param name="runStatsChangeEventTimeout"> /// Timeout that triggers sending results regardless of cache size. /// </param> /// <param name="testHostLauncher"> /// Test host launcher. If null then default will be used. /// </param> public TestRunCriteria(IEnumerable <TestCase> tests, long frequencyOfRunStatsChangeEvent, bool keepAlive, string testSettings, TimeSpan runStatsChangeEventTimeout, ITestHostLauncher testHostLauncher) : base(frequencyOfRunStatsChangeEvent, keepAlive, testSettings, runStatsChangeEventTimeout, testHostLauncher) { var testCases = tests as IList <TestCase> ?? tests.ToList(); ValidateArg.NotNullOrEmpty(testCases, "tests"); this.Tests = testCases; }
private static IEnumerable <string> TokenizeCondition(string conditionString) { ValidateArg.NotNullOrEmpty(conditionString, nameof(conditionString)); var token = new StringBuilder(conditionString.Length); var escaped = false; for (int i = 0; i < conditionString.Length; i++) { var c = conditionString[i]; if (escaped) { token.Append(c); escaped = false; continue; } switch (c) { case '=': case '~': case '!': if (token.Length > 0) { yield return(token.ToString()); token.Clear(); } if (c == '!') { var op = conditionString[i + 1]; if (op == '~' || op == '=') { yield return(token.ToString() + conditionString[++i]); continue; } } yield return(c.ToString()); continue; default: token.Append(c); break; } } if (token.Length > 0) { yield return(token.ToString()); } }
/// <summary> /// Initializes a new instance of the <see cref="TestRunCriteria"/> class. /// </summary> /// <param name="tests"> /// Tests which should be executed /// </param> /// <param name="baseTestRunCriteria"> /// The BaseTestRunCriteria /// </param> public TestRunCriteria(IEnumerable <TestCase> tests, BaseTestRunCriteria baseTestRunCriteria) : base(baseTestRunCriteria) { var testCases = tests as IList <TestCase> ?? tests.ToList(); ValidateArg.NotNullOrEmpty(testCases, "tests"); this.Tests = testCases; }
// <inheritdoc /> public void SendData(DataCollectionContext dataCollectionContext, string key, string value) { ValidateArg.NotNullOrEmpty(key, "key"); ValidateArg.NotNullOrEmpty(value, "value"); ValidateArg.NotNullOrEmpty(dataCollectionContext.TestCase.Id.ToString(), "dataCollectionContext.TestCase.Id"); var testCaseId = dataCollectionContext.TestCase.Id; this.AddKeyValuePairToDictionary(testCaseId, key, value); }
public Stacktrace(string stackTrace) { ValidateArg.NotNullOrEmpty(stackTrace, "stackTrace"); var stackFrameParser = StackFrameParser.CreateStackFrameParser(); var lines = stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); stackFrames = lines.Select(stackFrameParser.GetStackFrame).Where(stackFrame => stackFrame != null).ToList(); }
/// <summary> /// Initializes a new instance of the <see cref="TestRunCriteria"/> class. /// Create the TestRunCriteria for a test run /// </summary> /// <param name="sources"> /// Sources which contains tests that should be executed /// </param> /// <param name="baseTestRunCriteria"> /// The BaseTestRunCriteria /// </param> public TestRunCriteria(IEnumerable <string> sources, BaseTestRunCriteria baseTestRunCriteria) : base(baseTestRunCriteria) { var testSources = sources as IList <string> ?? sources.ToArray(); ValidateArg.NotNullOrEmpty(testSources, "sources"); this.AdapterSourceMap = new Dictionary <string, IEnumerable <string> >(); this.AdapterSourceMap.Add(Constants.UnspecifiedAdapterPath, testSources); }
/// <summary> /// Initializes a new instance of the <see cref="BlameTestObject"/> class. /// </summary> /// <param name="fullyQualifiedName"> /// Fully qualified name of the test case. /// </param> /// <param name="executorUri"> /// The Uri of the executor to use for running this test. /// </param> /// <param name="source"> /// Test container source from which the test is discovered. /// </param> public BlameTestObject(string fullyQualifiedName, Uri executorUri, string source) { ValidateArg.NotNullOrEmpty(fullyQualifiedName, "fullyQualifiedName"); ValidateArg.NotNull(executorUri, "executorUri"); ValidateArg.NotNullOrEmpty(source, "source"); this.Id = Guid.Empty; this.FullyQualifiedName = fullyQualifiedName; this.ExecutorUri = executorUri; this.Source = source; this.IsCompleted = false; }
/// <summary> /// Initializes a new instance of the <see cref="DataCollectionEnvironmentVariable"/> class. /// </summary> /// <param name="variable"> /// Variable name and requested value. /// </param> /// <param name="requestingDataCollectorFriendlyName"> /// Friendly name of the data collector requesting it. /// </param> public DataCollectionEnvironmentVariable( KeyValuePair <string, string> variable, string requestingDataCollectorFriendlyName) { ValidateArg.NotNullOrEmpty(variable.Key, nameof(variable.Key)); ValidateArg.NotNullOrEmpty(requestingDataCollectorFriendlyName, nameof(requestingDataCollectorFriendlyName)); this.variable = variable; this.dataCollectorsThatRequested = new List <string> { requestingDataCollectorFriendlyName }; }
/// <summary> /// Initializes a new instance of the <see cref="TestRunCriteria"/> class. /// </summary> /// <param name="adapterSourceMap"> /// Sources which contains tests that should be executed /// </param> /// <param name="frequencyOfRunStatsChangeEvent"> /// Frequency of run stats event /// </param> /// <param name="keepAlive"> /// Whether the execution process should be kept alive after the run is finished or not. /// </param> /// <param name="testSettings"> /// Settings used for this run. /// </param> /// <param name="runStatsChangeEventTimeout"> /// Timeout that triggers sending results regardless of cache size. /// </param> /// <param name="testHostLauncher"> /// Test host launcher. If null then default will be used. /// </param> public TestRunCriteria( Dictionary <string, IEnumerable <string> > adapterSourceMap, long frequencyOfRunStatsChangeEvent, bool keepAlive, string testSettings, TimeSpan runStatsChangeEventTimeout, ITestHostLauncher testHostLauncher) : base(frequencyOfRunStatsChangeEvent, keepAlive, testSettings, runStatsChangeEventTimeout, testHostLauncher) { ValidateArg.NotNullOrEmpty(adapterSourceMap, "adapterSourceMap"); this.AdapterSourceMap = adapterSourceMap; }
/// <summary> /// Initializes FilterExpressionWrapper with given filterString. /// </summary> public FilterExpressionWrapper(string filterString) { ValidateArg.NotNullOrEmpty(filterString, "filterString"); this.FilterString = filterString; try { this.filterExpression = FilterExpression.Parse(filterString); } catch (FormatException ex) { this.ParseError = ex.Message; } }
/// <summary> /// Runs 'all' the tests present in the specified 'sources'. /// </summary> /// <param name="sources">Path to test container files to look for tests in.</param> /// <param name="runContext">Context to use when executing the tests.</param> /// <param name="frameworkHandle">Handle to the framework to record results and to do framework operations.</param> public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { ValidateArg.NotNullOrEmpty(sources, nameof(sources)); ValidateArg.NotNull(runContext, nameof(runContext)); ValidateArg.NotNull(frameworkHandle, nameof(frameworkHandle)); if (!Client.Connected) { Client.Start(); } foreach (string source in sources) { if (!Client.CheckAssemblyHash(source, out byte[] _, out byte[] _))
/// <summary> /// Initializes a new instance of the <see cref="TestRunCriteria"/> class. /// Create the TestRunCriteria for a test run. /// </summary> /// /// <param name="sources">Sources which contains tests that should be executed.</param> /// <param name="testRunCriteria">The test run criteria.</param> public TestRunCriteria( IEnumerable <string> sources, TestRunCriteria testRunCriteria) : base(testRunCriteria) { var testSources = sources as IList <string> ?? sources.ToArray(); ValidateArg.NotNullOrEmpty(testSources, nameof(sources)); this.AdapterSourceMap = new Dictionary <string, IEnumerable <string> >(); this.AdapterSourceMap.Add(Constants.UnspecifiedAdapterPath, testSources); this.TestCaseFilter = testRunCriteria.testCaseFilter; this.FilterOptions = testRunCriteria.filterOptions; }
public JsTestContainer(ITestContainerDiscoverer discoverer, string source, Uri executorUri, IEnumerable <Guid> debugEngines) { ValidateArg.NotNullOrEmpty(source, "source"); ValidateArg.NotNull(executorUri, "executorUri"); ValidateArg.NotNull(debugEngines, "debugEngines"); ValidateArg.NotNull(discoverer, "discoverer"); this.Source = source; this.ExecutorUri = executorUri; this.TargetFramework = FrameworkVersion.None; this.TargetPlatform = Architecture.AnyCPU; this.DebugEngines = debugEngines; this.timeStamp = GetTimeStamp(); this.discoverer = discoverer; }
/// <summary> /// Get <see cref="INavigationData"/> for <paramref name="methodName"/>. /// </summary> /// <param name="source"> Source of <paramref name="declaringTypeName"/>. </param> /// <param name="declaringTypeName"> Name of declaring type for <paramref name="methodName"/>. </param> /// <param name="methodName"> Name of the method. </param> /// <returns> Navigation data for <paramref name="methodName"/>. </returns> public static INavigationData GetNavDataForMethod(string source, string declaringTypeName, string methodName) { ValidateArg.NotNullOrEmpty(source, nameof(source)); ValidateArg.NotNullOrEmpty(declaringTypeName, nameof(declaringTypeName)); ValidateArg.NotNullOrEmpty(methodName, nameof(methodName)); if (_cache.TryGetValue(source, out DiaSession diaSession)) { return(diaSession.GetNavigationDataForMethod(declaringTypeName, methodName)); } else { return(null); } }
/// <summary> /// Initializes a new instance of the <see cref="TestRunCriteria"/> class. /// </summary> /// <param name="sources"> /// Sources which contains tests that should be executed /// </param> /// <param name="frequencyOfRunStatsChangeEvent"> /// Frequency of run stats event /// </param> /// <param name="keepAlive"> /// Whether the execution process should be kept alive after the run is finished or not. /// </param> /// <param name="testSettings"> /// Settings used for this run. /// </param> /// <param name="runStatsChangeEventTimeout"> /// Timeout that triggers sending results regardless of cache size. /// </param> /// <param name="testHostLauncher"> /// Test host launcher. If null then default will be used. /// </param> public TestRunCriteria( IEnumerable <string> sources, long frequencyOfRunStatsChangeEvent, bool keepAlive, string testSettings, TimeSpan runStatsChangeEventTimeout, ITestHostLauncher testHostLauncher) : base(frequencyOfRunStatsChangeEvent, keepAlive, testSettings, runStatsChangeEventTimeout, testHostLauncher) { var testSources = sources as IList <string> ?? sources.ToList(); ValidateArg.NotNullOrEmpty(testSources, "sources"); this.AdapterSourceMap = new Dictionary <string, IEnumerable <string> >(); this.AdapterSourceMap.Add(Constants.UnspecifiedAdapterPath, testSources); }
public void AddWatch(string path) { ValidateArg.NotNullOrEmpty(path, "path"); if (!fileWatchers.ContainsKey(path)) { string directoryName = Path.GetDirectoryName(path); string fileName = Path.GetFileName(path); FileWatcherInfo watcherInfo = new FileWatcherInfo(new FileSystemWatcher(directoryName, fileName)); fileWatchers.Add(path, watcherInfo); watcherInfo.Watcher.Changed += OnChanged; watcherInfo.Watcher.Renamed += OnRenamed; watcherInfo.Watcher.EnableRaisingEvents = true; } }
public void RemoveWatch(string path) { ValidateArg.NotNullOrEmpty(path, "path"); FileWatcherInfo watcherInfo; if (fileWatchers.TryGetValue(path, out watcherInfo)) { watcherInfo.Watcher.EnableRaisingEvents = false; fileWatchers.Remove(path); watcherInfo.Watcher.Changed -= OnChanged; watcherInfo.Watcher.Renamed -= OnRenamed; watcherInfo.Watcher.Dispose(); watcherInfo.Watcher = null; } }
public void RemoveWatch(string path) { ValidateArg.NotNullOrEmpty(path, "path"); if (!string.IsNullOrEmpty(path)) { FileWatcherInfo watcherInfo; if (this.fileWatchers.TryRemove(path, out watcherInfo)) { watcherInfo.Watcher.EnableRaisingEvents = false; watcherInfo.Watcher.Changed -= this.OnChanged; watcherInfo.Watcher.Dispose(); watcherInfo.Watcher = null; } } }