public void VerifyResetVisibilitiesWhenStatusIsNotDefined()
        {
            var data = new ExtensionDataModel(this.service, this.vshelper, null, null)
            {
                SelectedIssuesInView =
                    new List <Issue>
                {
                    new Issue {
                        Status = IssueStatus.UNDEFINED
                    }
                }
            };

            Assert.AreEqual(Visibility.Hidden, data.IsReopenVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsResolveVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsFalsePositiveVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsCommentingVisible);
            Assert.AreEqual(Visibility.Hidden, data.UserInputTextBoxVisibility);
            Assert.AreEqual(Visibility.Hidden, data.IsConfirmVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsUnconfirmVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsAssignVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsOpenExternallyVisible);
            var lentthCrl    = data.UserControlsHeight;
            var lenthTextCrl = data.UserTextControlsHeight;

            Assert.AreEqual(0.0, lenthTextCrl.Value);
            Assert.AreEqual(0.0, lentthCrl.Value);
            Assert.AreEqual(1, data.SelectedIssuesInView.Count);
        }
        public void TesRestOfProperties()
        {
            var issue       = new Issue();
            var connector   = new SonarRestService(new JsonSonarConnector());
            var projectAsso = new Resource {
                Key = "proj"
            };
            var model = new ExtensionDataModel(this.service, this.vshelper, null, null)
            {
                AssociatedProjectKey = "proj",
                CommentData          = "comment",
                SelectedIssue        = issue,
                SonarInfo            = "ver",
                SelectedUser         = new User {
                    Login = "******"
                },
                DiagnosticMessage = "MessageData",
                DisableEditorTags = false,
                RestService       = connector,
                AssociatedProject = projectAsso,
            };

            Assert.AreEqual("Selected Project: proj", model.AssociatedProjectKey);
            Assert.AreEqual(issue, model.SelectedIssue);
            Assert.AreEqual("comment", model.CommentData);
            Assert.AreEqual("login", model.SelectedUser.Login);
            Assert.AreEqual("ver", model.SonarInfo);
            Assert.AreEqual("MessageData", model.DiagnosticMessage);
            Assert.IsFalse(model.DisableEditorTags);
            Assert.AreEqual(connector, model.RestService);
            Assert.AreEqual(projectAsso, model.AssociatedProject);
        }
        public void VerifyResolvedTest()
        {
            var data = new ExtensionDataModel(this.service, this.vshelper, null, null)
            {
                SelectedIssuesInView =
                    new List <Issue>
                {
                    new Issue {
                        Status = IssueStatus.RESOLVED
                    }
                }
            };

            Assert.AreEqual(Visibility.Visible, data.IsReopenVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsResolveVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsFalsePositiveVisible);
            Assert.AreEqual(Visibility.Visible, data.IsCommentingVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsConfirmVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsUnconfirmVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsAssignVisible);
            Assert.AreEqual(Visibility.Visible, data.IsOpenExternallyVisible);
            var lentthCrl    = data.UserControlsHeight;
            var lenthTextCrl = data.UserTextControlsHeight;

            Assert.AreEqual(50.0, lenthTextCrl.Value);
            Assert.AreEqual(25.0, lentthCrl.Value);
        }
        /// <summary>
        ///     The test window.
        /// </summary>
        public void TestWindow()
        {
            var mocks         = new MockRepository();
            var mockHttpReq   = mocks.Stub <IHttpSonarConnector>();
            var mockVsHelpers = mocks.Stub <IVsEnvironmentHelper>();
            var config        = new ConnectionConfiguration("serveraddr", "login", "password");

            // set expectations
            using (mocks.Record())
            {
                SetupResult.For(mockHttpReq.HttpSonarGetRequest(config, "/api/issues/search?components=resource"))
                .Return(File.ReadAllText("TestData/issuessearchbycomponent.txt"));
                SetupResult.For(mockHttpReq.HttpSonarGetRequest(config, "/api/users/search")).Return(File.ReadAllText("TestData/userList.txt"));
            }

            ISonarRestService service = new SonarRestService(mockHttpReq);

            service.GetIssuesInResource(config, "resource");
            var associatedProject = new Resource {
                Key = "core:Common"
            };

            this.model = new ExtensionDataModel(service, mockVsHelpers, associatedProject, null);
            var t = new Thread(this.Threadprc);

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
        }
        public void TestAssociationWithSolution()
        {
            this.mocks    = new MockRepository();
            this.service  = this.mocks.Stub <ISonarRestService>();
            this.vshelper = this.mocks.Stub <IVsEnvironmentHelper>();
            var resource = new Resource {
                Key = "KEY"
            };
            var resources = new List <Resource> {
                resource
            };

            using (this.mocks.Record())
            {
                SetupResult.For(this.service.GetServerInfo(Arg <ISonarConfiguration> .Is.Anything)).Return(3.6);
                SetupResult.For(this.service.AuthenticateUser(Arg <ISonarConfiguration> .Is.Anything)).Return(true);
                SetupResult.For(this.service.GetResourcesData(Arg <ISonarConfiguration> .Is.Anything, Arg <string> .Is.Equal("KEY"))).Return(resources);
                SetupResult.For(this.vshelper.ReadSavedOption("Sonar Options", "General", "SonarHost")).Return("serveraddr");
                SetupResult.For(this.vshelper.ReadSavedOption("Sonar Options", "General", "SonarUserPassword")).Return("password");
                SetupResult.For(this.vshelper.ReadSavedOption("Sonar Options", "General", "SonarUserName")).Return("login");
                SetupResult.For(this.vshelper.ActiveSolutionName()).Return("Solution");
                SetupResult.For(this.vshelper.ReadOptionFromApplicationData("Solution", "PROJECTKEY")).Return("KEY");
            }

            var model = new ExtensionDataModel(this.service, this.vshelper, null, null);

            model.AssociateProjectToSolution();
            Assert.AreEqual("Selected Project: KEY", model.AssociatedProjectKey);
            model.AssociateProjectToSolution();
            Assert.AreEqual("Selected Project: KEY", model.AssociatedProjectKey);
        }
            public void ShouldActivateAllTypesWhenModelIsLocal()
            {
                var data = new ExtensionDataModel(this.service, this.vshelper, null, null)
                {
                    AnalysisMode = false,
                    AnalysisType = true
                };

                Assert.AreEqual(data.AnalysisTypeText, "Analysis");
                data.AnalysisType = true;
                Assert.AreEqual(data.AnalysisTypeText, "Preview");
                data.AnalysisType = true;
                Assert.AreEqual(data.AnalysisTypeText, "Incremental");
                data.AnalysisType = true;
                Assert.AreEqual(data.AnalysisTypeText, "File");
                data.AnalysisType = true;
                Assert.AreEqual(data.AnalysisTypeText, "Analysis");
                data.AnalysisType = false;
                Assert.AreEqual(data.AnalysisTypeText, "Preview");
                data.AnalysisType = false;
                Assert.AreEqual(data.AnalysisTypeText, "Incremental");
                data.AnalysisType = false;
                Assert.AreEqual(data.AnalysisTypeText, "File");
                data.AnalysisType = false;
                Assert.AreEqual(data.AnalysisTypeText, "Analysis");
            }
        public void VerifyOpenAndReopenStatusTest()
        {
            var data = new ExtensionDataModel(this.service, this.vshelper, null, null)
            {
                SelectedIssuesInView =
                    new List <Issue>
                {
                    new Issue {
                        Status = IssueStatus.OPEN
                    },
                    new Issue {
                        Status = IssueStatus.REOPENED
                    }
                }
            };

            Assert.AreEqual(Visibility.Hidden, data.IsReopenVisible);
            Assert.AreEqual(Visibility.Visible, data.IsResolveVisible);
            Assert.AreEqual(Visibility.Visible, data.IsFalsePositiveVisible);
            Assert.AreEqual(Visibility.Visible, data.IsCommentingVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsConfirmVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsUnconfirmVisible);
            Assert.AreEqual(Visibility.Hidden, data.IsAssignVisible);
            Assert.AreEqual(Visibility.Visible, data.IsOpenExternallyVisible);
        }
예제 #8
0
            public void CoverageInEditorSetAndGetTest()
            {
                var data           = new ExtensionDataModel(this.service, this.vshelper, null, null);
                var sourceCoverage = new Dictionary <int, CoverageElement>();

                Assert.AreEqual(sourceCoverage, data.GetCoverageInEditor(string.Empty));
            }
예제 #9
0
        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 DisableCoverageInEditor()
 {
     var data = new ExtensionDataModel(this.service, this.vshelper, null, null);
     var sourceCoverage = new SourceCoverage();
     data.CoverageInEditorEnabled = false;
     Assert.IsFalse(data.CoverageInEditorEnabled);
     Assert.AreNotEqual(sourceCoverage, data.GetCoverageInEditor(string.Empty));
 }
예제 #12
0
            public void DisableCoverageInEditor()
            {
                var data           = new ExtensionDataModel(this.service, this.vshelper, null, null);
                var sourceCoverage = new SourceCoverage();

                data.CoverageInEditorEnabled = false;
                Assert.IsFalse(data.CoverageInEditorEnabled);
                Assert.AreNotEqual(sourceCoverage, data.GetCoverageInEditor(string.Empty));
            }
        public void TestUpdateModelUpdateData()
        {
            var model = new ExtensionDataModel();

            model.ExtensionDataModelUpdate(this.service, this.vshelper, new Resource(), null, null);
            Assert.AreEqual(0, model.Issues.Count);
            Assert.AreEqual(this.service, model.RestService);
            Assert.AreEqual(this.vshelper, model.Vsenvironmenthelper);
        }
            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 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 TestSetUserList()
        {
            var model = new ExtensionDataModel(this.service, this.vshelper, null, null)
            {
                UsersList = new System.Collections.Generic.List <User>
                {
                    new User()
                }
            };

            Assert.AreEqual(1, model.UsersList.Count);
        }
            public void TypeShouldBeFileWhenModeIsServer()
            {
                var data = new ExtensionDataModel(this.service, this.vshelper, null, null)
                {
                    AnalysisMode = true,
                    AnalysisType = true
                };

                Assert.AreEqual(data.AnalysisTypeText, "File");
                data.AnalysisType = false;
                Assert.AreEqual(data.AnalysisTypeText, "File");
            }
        public void TestSelectIssueFromListUsingId()
        {
            var issueWithId = new Issue {
                Id = 20, Component = "asdaskjd:sdaskjd:aksjdkas/asdkasj.cs"
            };

            var model = new ExtensionDataModel(this.service, this.vshelper, null, null);

            model.ReplaceAllIssuesInCache(new List <Issue> {
                issueWithId
            });
            model.SelectAIssueFromList(20);
            Assert.AreEqual(issueWithId, model.SelectedIssue);
        }
            public void TestOnOffAnalyses()
            {
                var data = new ExtensionDataModel(this.service, this.vshelper, null, null)
                {
                    AnalysisMode = true
                };

                Assert.AreEqual(data.AnalysisModeText, "Server");
                data.AnalysisMode = false;
                Assert.AreEqual(data.AnalysisModeText, "Local");
                data.AnalysisMode = false;
                Assert.AreEqual(data.AnalysisModeText, "Local");
                data.AnalysisMode = true;
                Assert.AreEqual(data.AnalysisModeText, "Server");
            }
            public void FrequencyAndTriggerOnDemandExecuteWhenTypeIsNotFile()
            {
                var data = new ExtensionDataModel(this.service, this.vshelper, null, null)
                {
                    AnalysisMode = false,
                    AnalysisType = true
                };

                Assert.AreEqual(data.AnalysisModeText, "Local");
                Assert.AreEqual(data.AnalysisTypeText, "Analysis");
                data.AnalysisType = false;
                Assert.AreEqual(data.AnalysisTypeText, "Preview");
                data.AnalysisType = false;
                Assert.AreEqual(data.AnalysisTypeText, "Incremental");
                data.AnalysisType = false;
                Assert.AreEqual(data.AnalysisTypeText, "File");
            }
        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 TestSetIssuesListWithCommentsWithRefreshView()
        {
            var issueWithId = new Issue {
                Id = 20, Component = "asdaskjd:sdaskjd:aksjdkas/asdkasj.cs", Key = new Guid()
            };

            issueWithId.Comments.Add(new Comment());
            var list = new List <Issue> {
                issueWithId
            };
            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(list);


            model.SelectedIssuesInView = list;
            Assert.AreEqual(1, model.Issues.Count);
            Assert.AreEqual(1, model.Comments.Count);
            Assert.AreEqual("Number of Issues: 1 ", model.StatsLabel);
        }
        public void TestDefaultConstructor()
        {
            var model = new ExtensionDataModel();

            Assert.AreEqual(0, model.Issues.Count);
        }
 public void CoverageInEditorSetAndGetTest()
 {
     var data = new ExtensionDataModel(this.service, this.vshelper, null, null);
     var sourceCoverage = new Dictionary<int, CoverageElement>();
     Assert.AreEqual(sourceCoverage, data.GetCoverageInEditor(string.Empty));
 }