public void ShouldRunDiagnosticsIfSyncIsFalse() { var notificaitonManager = new Mock <INotificationManager>(); var confManager = new Mock <IConfigurationHelper>(); var helper = new Mock <IVsEnvironmentHelper>(); var rest = new Mock <ISonarRestService>(); var dictionaryprops = new Dictionary <string, string>(); dictionaryprops.Add("sonar.roslyn.sync.type", "false"); var dictionaryplugins = new Dictionary <string, string>(); dictionaryplugins.Add("Roslyn", "1.0"); rest.Setup(caller => caller.GetInstalledPlugins(It.IsAny <ISonarConfiguration>())).Returns(dictionaryplugins); rest.Setup(caller => caller.GetProperties(It.IsAny <ISonarConfiguration>(), It.IsAny <Resource>())).Returns(dictionaryprops); var conf = new ConnectionConfiguration("http://localhost:9000", "admin", "admin", 5.3); IAnalysisPlugin plugin = new AnalysisPlugin(notificaitonManager.Object, confManager.Object, rest.Object, helper.Object); var project = new Resource(); project.Key = "Tekla.Tools.RoslynRunner"; project.SolutionRoot = Path.Combine(execpath, "TestData"); project.SolutionName = "RoslynRunner.sln"; var profiledata = new Dictionary <string, Profile>(); var profile = new Profile(null, null); profile.AddRule(new Rule { Repo = "roslyn-cs", Key = "SA140", IsParamsRetrivedFromServer = true, ConfigKey = "roslyn-cs:SA140" }); profile.AddRule(new Rule { Repo = "roslyn-cs", Key = "SA1001", IsParamsRetrivedFromServer = true, ConfigKey = "roslyn-cs:SA1001" }); profile.AddRule(new Rule { Repo = "roslyn-cs", Key = "SA1200", IsParamsRetrivedFromServer = true, ConfigKey = "roslyn-cs:SA1200" }); profiledata.Add("cs", profile); plugin.AssociateProject(project, conf, profiledata, "14.0"); var vsfile = new VsFileItem(); var vsproject = new VsProjectItem(); vsproject.ProjectName = "ClassLibrary1"; vsproject.ProjectFilePath = Path.Combine(project.SolutionRoot, "ClassLibrary1", "ClassLibrary1.csproj"); vsfile.Project = vsproject; vsfile.FilePath = Path.Combine(project.SolutionRoot, "ClassLibrary1", "Class1.cs"); vsfile.FileName = "Class1.cs"; vsfile.SonarResource = new Resource() { Key = "ProjectKey" }; var issues = plugin.GetLocalAnalysisExtension(conf).ExecuteAnalysisOnFile(vsfile, project, conf, false); Assert.That(issues.Count, Is.EqualTo(5)); }
/// <summary>The vs file item.</summary> /// <param name="filename">The filename.</param> /// <param name="associatedProject">The associated project.</param> /// <param name="fileResource">The file resource.</param> /// <returns>The <see cref="VsFileItem"/>.</returns> public VsFileItem VsFileItem(string filename, Resource associatedProject, Resource fileResource) { try { if (string.IsNullOrEmpty(filename)) { return(null); } string driveLetter = filename.Substring(0, 1); ProjectItem item = this.environment.Solution.FindProjectItem(filename); if (item == null) { return(null); } string documentName = Path.GetFileName(filename); string documentPath = driveLetter + this.GetProperFilePathCapitalization(filename).Substring(1); string projectName = item.ContainingProject.Name; string projectPath = driveLetter + this.GetProperFilePathCapitalization(item.ContainingProject.FullName).Substring(1); string solutionName = this.ActiveSolutionName(); string solutionPath = driveLetter + this.ActiveSolutionPath().Substring(1); var itemToReturn = new VsFileItem { FileName = documentName, FilePath = documentPath, SonarResource = fileResource, Project = new VsProjectItem { ProjectName = projectName, ProjectFilePath = projectPath, Solution = new VsSolutionItem { SolutionName = solutionName, SolutionPath = solutionPath, SonarProject = associatedProject } } }; return(itemToReturn); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } }
private void RunCommand(VsFileItem itemInView) { if (this.isRunning) { return; } this.isRunning = true; this.model.CanRunAnalysis = false; this.model.AnalysisIsRunning = true; try { var bw = new BackgroundWorker { WorkerReportsProgress = true }; bw.RunWorkerCompleted += delegate { this.isRunning = false; this.model.CanRunAnalysis = true; this.model.AnalysisIsRunning = false; }; bw.DoWork += delegate { var commandIssues = PluginOperation.ExecuteCommand(itemInView); Application.Current.Dispatcher.Invoke( delegate { this.model.UpdateLocalIssues(this, new LocalAnalysisEventCommandAnalsysisComplete(itemInView, commandIssues)); }); }; bw.RunWorkerAsync(); } catch (Exception ex) { this.notification.ReportMessage(new Message() { Id = "PluginWrapper", Data = "Failed to Run Command : " + this.Name }); this.notification.ReportException(ex); } }
/// <summary>The vs file item.</summary> /// <param name="fullPath">The full Path.</param> /// <param name="projectFullPath">The project Full Path.</param> /// <param name="associatedProject">The associated project.</param> /// <param name="fileResource">The file resource.</param> /// <returns>The <see cref="VsFileItem"/>.</returns> public VsFileItem VsFileItem(string fullPath, string projectFullPath, Resource associatedProject, Resource fileResource) { if (string.IsNullOrEmpty(fullPath)) { return(null); } string driveLetter = fullPath.Substring(0, 1); string documentName = Path.GetFileNameWithoutExtension(fullPath); string documentPath = driveLetter + this.GetProperFilePathCapitalization(fullPath).Substring(1); string projectName = Path.GetFileNameWithoutExtension(projectFullPath); string projectPath = driveLetter + this.GetProperFilePathCapitalization(projectFullPath).Substring(1); string solutionName = this.ActiveSolutionName(); string solutionPath = driveLetter + this.ActiveSolutionPath().Substring(1); var itemToReturn = new VsFileItem { FileName = documentName, FilePath = documentPath, SonarResource = fileResource, Project = new VsProjectItem { ProjectName = projectName, ProjectFilePath = projectPath, Solution = new VsSolutionItem { SolutionName = solutionName, SolutionPath = solutionPath, SonarProject = associatedProject } } }; return(itemToReturn); }