public void UpdateCoverageDataForResourceWithNewDateDataTest() { 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(new Source { Lines = new[] { "line1", "line2", "line3", "line4" } }) .Repeat.Once(); this.service.Expect( mp => mp.GetIssuesInResource(Arg <ISonarConfiguration> .Is.Anything, Arg <string> .Is.Anything)) .Return(new List <Issue>()) .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" }; data.CoverageInEditorEnabled = true; 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"); var data1 = data.GetCoverageInEditor("ghfggfgf\r\nghfggfgf\r\nghfggfgf\r\nghfggfgf\r\n"); Assert.IsNotNull(data1); }
public void ErrorWhenOnPluginsAreInstalled() { var data = new ExtensionDataModel(this.service, this.vshelper, null, null); data.RefreshDataForResource(@"e:\test\src.cs"); Assert.AreEqual("Extension Not Ready", data.ErrorMessage); 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); }