private List <CoverageProject> GetCoverageProjects(TestConfiguration testConfiguration) { var userRunSettings = testConfiguration.UserRunSettings; var runSettingsRetriever = new RunSettingsRetriever(); var testContainers = testConfiguration.Containers; return(testConfiguration.Containers.Select(container => { var project = new CoverageProject(); project.ProjectName = container.ProjectName; project.TestDllFile = container.Source; project.Is64Bit = container.TargetPlatform.ToString().ToLower().Equals("x64"); var containerData = container.ProjectData; project.ProjectFile = container.ProjectData.ProjectFilePath; project.RunSettingsFile = ThreadHelper.JoinableTaskFactory.Run(() => runSettingsRetriever.GetRunSettingsFileAsync(userRunSettings, containerData)); return project; }).ToList()); }
private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) { try { if (e.State == TestOperationStates.TestExecutionStarting) { StopCoverageProcess(); // just to be sure } if (e.State == TestOperationStates.TestExecutionFinished) { var settings = AppOptions.Get(); if (!settings.Enabled) { FCCEngine.CoverageLines.Clear(); UpdateMarginTags?.Invoke(this, null); UpdateOutputWindow?.Invoke(this, null); return; } Logger.Log("================================== START =================================="); var darkMode = CurrentTheme.Equals("Dark", StringComparison.OrdinalIgnoreCase); CoverageProject[] projects = null; try { var testConfiguration = new Operation(e.Operation).Configuration; var userRunSettings = testConfiguration.UserRunSettings; var runSettingsRetriever = new RunSettingsRetriever(); var testContainers = testConfiguration.Containers; projects = testConfiguration.Containers.Select(container => { var project = new CoverageProject(); project.ProjectName = container.ProjectName; project.TestDllFile = container.Source; project.Is64Bit = container.TargetPlatform.ToString().ToLower().Equals("x64"); var containerData = container.ProjectData; project.ProjectFile = container.ProjectData.ProjectFilePath; project.RunSettingsFile = ThreadHelper.JoinableTaskFactory.Run(() => runSettingsRetriever.GetRunSettingsFileAsync(userRunSettings, containerData)); return(project); }).ToArray(); }catch (Exception exc) { throw new Exception("Error test container discoverer reflection", exc); } _reloadCoverageThread = new Thread(() => { try { // compute coverage FCCEngine.ReloadCoverage(projects, darkMode); // update margins { UpdateMarginTagsEventArgs updateMarginTagsEventArgs = null; try { updateMarginTagsEventArgs = new UpdateMarginTagsEventArgs { }; } catch { // ignore } finally { UpdateMarginTags?.Invoke(this, updateMarginTagsEventArgs); } } // update output window { UpdateOutputWindowEventArgs updateOutputWindowEventArgs = null; try { updateOutputWindowEventArgs = new UpdateOutputWindowEventArgs { HtmlContent = File.ReadAllText(FCCEngine.HtmlFilePath) }; } catch { // ignore } finally { UpdateOutputWindow?.Invoke(this, updateOutputWindowEventArgs); } } // log Logger.Log("================================== DONE ==================================="); } catch (Exception exception) { if (!(exception is ThreadAbortException) && _reloadCoverageThread != null) { Logger.Log("Error", exception); Logger.Log("================================== ERROR =================================="); } } }); _reloadCoverageThread.Start(); } } catch (Exception exception) { Logger.Log("Error processing unit test events", exception); } }
private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) { try { if (e.State == TestOperationStates.TestExecutionStarting) { StopCoverageProcess(); // just to be sure } if (e.State == TestOperationStates.TestExecutionFinished) { var settings = AppOptions.Get(); if (!settings.Enabled) { FCCEngine.CoverageLines.Clear(); UpdateMarginTags?.Invoke(this, null); UpdateOutputWindow?.Invoke(this, null); return; } Logger.Log("================================== START =================================="); var operationType = e.Operation.GetType(); var darkMode = CurrentTheme.Equals("Dark", StringComparison.OrdinalIgnoreCase); var testConfiguration = (operationType.GetProperty("Configuration") ?? operationType.GetProperty("Configuration", BindingFlags.Instance | BindingFlags.NonPublic)).GetValue(e.Operation); var userRunSettings = testConfiguration.GetType().GetProperty("UserRunSettings", BindingFlags.Instance | BindingFlags.Public).GetValue(testConfiguration); var runSettingsRetriever = new RunSettingsRetriever(); var testContainers = ((IEnumerable <object>)testConfiguration.GetType().GetProperty("Containers").GetValue(testConfiguration)).ToArray(); var projects = new List <CoverageProject>(); foreach (var container in testContainers) { var project = new CoverageProject(); var containerType = container.GetType(); var containerData = containerType.GetProperty("ProjectData").GetValue(container); var containerDataType = containerData.GetType(); project.ProjectGuid = containerType.GetProperty("ProjectGuid").GetValue(container).ToString(); project.ProjectName = containerType.GetProperty("ProjectName").GetValue(container).ToString(); project.TestDllFile = containerType.GetProperty("Source").GetValue(container).ToString(); project.Is64Bit = containerType.GetProperty("TargetPlatform").GetValue(container).ToString().ToLower().Equals("x64"); project.ProjectFile = containerDataType.GetProperty("ProjectFilePath", BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic).GetValue(containerData).ToString(); project.RunSettingsFile = ThreadHelper.JoinableTaskFactory.Run(() => runSettingsRetriever.GetRunSettingsFileAsync(userRunSettings, container)); try { var defaultOutputFolder = Path.GetDirectoryName(containerDataType.GetProperty("DefaultOutputPath", BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic).GetValue(containerData).ToString()); var legacyWorkFolder = Path.Combine(Path.GetDirectoryName(defaultOutputFolder), "fine-code-coverage"); Directory.Delete(legacyWorkFolder, true); } catch { // ignore } projects.Add(project); } _reloadCoverageThread = new Thread(() => { try { // compute coverage FCCEngine.ReloadCoverage(projects.ToArray(), darkMode); // update margins { UpdateMarginTagsEventArgs updateMarginTagsEventArgs = null; try { updateMarginTagsEventArgs = new UpdateMarginTagsEventArgs { }; } catch { // ignore } finally { UpdateMarginTags?.Invoke(this, updateMarginTagsEventArgs); } } // update output window { UpdateOutputWindowEventArgs updateOutputWindowEventArgs = null; try { updateOutputWindowEventArgs = new UpdateOutputWindowEventArgs { HtmlContent = File.ReadAllText(FCCEngine.HtmlFilePath) }; } catch { // ignore } finally { UpdateOutputWindow?.Invoke(this, updateOutputWindowEventArgs); } } // log Logger.Log("================================== DONE ==================================="); } catch (Exception exception) { if (!(exception is ThreadAbortException) && _reloadCoverageThread != null) { Logger.Log("Error", exception); Logger.Log("================================== ERROR =================================="); } } }); _reloadCoverageThread.Start(); } } catch (Exception exception) { Logger.Log("Error processing unit test events", exception); } }