public void ShouldReturnWhenContstrainsAreNotMet() { var data = new ExtensionDataModel(this.service, this.vshelper, null, null); data.UpdateIssuesInEditorLocationWithModifiedBuffer("data"); Assert.AreEqual(string.Empty, data.ErrorMessage); Assert.AreEqual(0, data.GetIssuesInEditor("file").Count); data.UpdateIssuesInEditorLocationWithModifiedBuffer("data"); Assert.AreEqual(0, data.GetIssuesInEditor("file").Count); Assert.IsNull(data.ResourceInEditor); }
public void UpdatesResourceWithoutAnyIssues() { var source = new Source { Lines = new[] { "line1", "line2", "line3", "line4" } }; this.vshelper.Expect( mp => mp.CurrentSelectedDocumentLanguage()) .Return("c++"); this.vshelper.Expect( mp => mp.ActiveFileFullPath()) .Return("c:\\src\\file.cpp"); this.vshelper.Expect( mp => mp.ActiveSolutionPath()) .Return("c:\\src"); this.service.Expect( mp => mp.GetSourceForFileResource(Arg <ISonarConfiguration> .Is.Anything, Arg <string> .Is.Anything)) .Return(source); var element = new Resource { Date = new DateTime(2000, 1, 1), Key = "resourceKey" }; this.service.Expect( mp => mp.GetResourcesData(Arg <ISonarConfiguration> .Is.Anything, Arg <string> .Is.Anything)) .Return(new List <Resource> { element }) .Repeat.Twice(); this.analysisPlugin.Expect(mp => mp.IsSupported(Arg <ISonarConfiguration> .Is.Anything, Arg <Resource> .Is.Anything)).Return(true).Repeat.Once(); this.analysisPlugin.Expect( mp => mp.GetResourceKey( Arg <VsProjectItem> .Is.Anything, Arg <string> .Is.Anything, Arg <bool> .Is.Anything)).Return("key").Repeat.Once(); var data = new ExtensionDataModel(this.service, this.vshelper, null, null); var localAnalyser = this.mocks.Stub <ISonarLocalAnalyser>(); data.LocalAnalyserModule = localAnalyser; using (this.mocks.Record()) { SetupResult.For(localAnalyser.GetResourceKey(Arg <VsProjectItem> .Is.Anything, Arg <Resource> .Is.Anything, Arg <ISonarConfiguration> .Is.Anything, Arg <bool> .Is.Equal(true))).Return("Key1"); SetupResult.For(localAnalyser.GetResourceKey(Arg <VsProjectItem> .Is.Anything, Arg <Resource> .Is.Anything, Arg <ISonarConfiguration> .Is.Anything, Arg <bool> .Is.Equal(false))).Return("Key2"); } data.AssociatedProject = new Resource { Key = "KEY" }; data.RefreshDataForResource("c:\\src\\file.cpp"); Assert.AreEqual(0, data.GetIssuesInEditor("file").Count); }
public void TestSetIssuesInEditor() { var issueWithId = new Issue { Id = 20, Component = "asdaskjd:sdaskjd:aksjdkas/asdkasj.cs", Key = new Guid() }; var model = new ExtensionDataModel(this.service, this.vshelper, null, null); model.ResourceInEditor = new Resource { Key = "asdaskjd:sdaskjd:aksjdkas/asdkasj.cs" }; model.DocumentInView = "aksjdkas/asdkasj.cs"; model.ReplaceAllIssuesInCache(new List <Issue> { issueWithId }); Assert.AreEqual(1, model.GetIssuesInEditor("asdaskjd:sdaskjd:aksjdkas/asdkasj.cs").Count); Assert.AreEqual(string.Empty, model.ErrorMessage); }
public void UpdateIssueDataForResourceWithNewDateDataTestWithCache() { var fileSource = new Source { Lines = new[] { "line1", "line2", "line3", "line4" } }; var newResource = new Resource { Date = DateTime.Now, Key = "resource" }; var source1 = new SourceCoverage(); source1.SetLineCoverageData("1=0;2=3;3=3"); source1.SetBranchCoverageData("1=0;2=3;3=3", "1=0;2=3;3=3"); this.service.Expect( mp => mp.GetResourcesData(Arg <ISonarConfiguration> .Is.Anything, Arg <string> .Is.Anything)) .Return(new List <Resource> { newResource }); this.service.Expect( mp => mp.GetSourceForFileResource(Arg <ISonarConfiguration> .Is.Anything, Arg <string> .Is.Anything)) .Return(fileSource) .Repeat.Once(); this.service.Expect( mp => mp.GetIssuesInResource(Arg <ISonarConfiguration> .Is.Anything, Arg <string> .Is.Anything)) .Return(new List <Issue> { new Issue { Severity = Severity.CRITICAL, Line = 1 } }) .Repeat.Once(); this.service.Expect( mp => mp.GetCoverageInResource(Arg <ISonarConfiguration> .Is.Anything, Arg <string> .Is.Anything)) .Return(source1) .Repeat.Once(); this.analysisPlugin.Expect( mp => mp.GetResourceKey(Arg <VsProjectItem> .Is.Anything, Arg <string> .Is.Anything, Arg <bool> .Is.Anything)) .Return("resource"); var data = new ExtensionDataModel(this.service, this.vshelper, null, null); data.AssociatedProject = new Resource { Key = "sonar.com:common" }; var localAnalyser = this.mocks.Stub <ISonarLocalAnalyser>(); data.LocalAnalyserModule = localAnalyser; using (this.mocks.Record()) { SetupResult.For(localAnalyser.GetResourceKey(Arg <VsProjectItem> .Is.Anything, Arg <Resource> .Is.Anything, Arg <ISonarConfiguration> .Is.Anything, Arg <bool> .Is.Equal(true))).Return("Key1"); SetupResult.For(localAnalyser.GetResourceKey(Arg <VsProjectItem> .Is.Anything, Arg <Resource> .Is.Anything, Arg <ISonarConfiguration> .Is.Anything, Arg <bool> .Is.Equal(false))).Return("Key2"); } data.RefreshDataForResource("resource"); Assert.AreEqual(1, data.GetIssuesInEditor("line1\r\nline2\r\nline3\r\nline4\r\n").Count); }