/// <summary>
        /// Initializes a new instance of the <see cref="IssuesGridSettingsDialog"/> class.
        /// </summary>
        /// <param name="dataModelIn">
        /// The data model in.
        /// </param>
        public IssuesGridSettingsDialog(ExtensionDataModel dataModelIn)
        {
            this.InitializeComponent();

            this.DataContext = null;
            this.DataContext = dataModelIn;
        }
 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);
     var sourceCoverage = new SourceCoverage();
     data.CoverageInEditorEnabled = false;
     Assert.IsFalse(data.CoverageInEditorEnabled);
     Assert.AreNotEqual(sourceCoverage, data.GetCoverageInEditor(string.Empty));
 }
        /// <summary>
        /// The update data context.
        /// </summary>
        /// <param name="dataModelIn">
        /// The data model in.
        /// </param>
        public void UpdateDataContext(ExtensionDataModel dataModelIn)
        {
            // bind data with view model
            this.dataModel = dataModelIn;
            this.DataContext = null;
            this.DataContext = dataModelIn;

            this.BindCommandsInWindow(dataModelIn);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="IssueWindow"/> class.
        /// </summary>
        /// <param name="dataModelIn">
        /// The data Model In.
        /// </param>
        public IssueWindow(ExtensionDataModel dataModelIn)
        {
            this.InitializeComponent();

            // bind data with view model
            this.dataModel = dataModelIn;
            this.DataContext = null;
            this.DataContext = dataModelIn;

            this.BindCommandsInWindow(dataModelIn);
        }
 public void FrequencyAndTriggerOnDemandExecuteWhenTypeIsNotFile()
 {
     var data = new ExtensionDataModel(this.service, this.vshelper, 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 TestSetUserList()
 {
     var model = new ExtensionDataModel(this.service, this.vshelper, null)
     {
         UsersList = new System.Collections.Generic.List<User>
                                 {
                                    new User()
                                 }
     };
     Assert.AreEqual(1, model.UsersList.Count);
 }
 /// <summary>
 /// The update model.
 /// </summary>
 /// <param name="myModel">
 /// The my model.
 /// </param>
 public void UpdateModel(ExtensionDataModel myModel)
 {
     this.windowToUse.UpdateDataContext(myModel);
 }
 public void TestUpdateModelUpdateData()
 {
     var model = new ExtensionDataModel();
     model.ExtensionDataModelUpdate(this.service, this.vshelper, new Resource());
     Assert.AreEqual(0, model.Issues.Count);
     Assert.AreEqual(this.service, model.RestService);
     Assert.AreEqual(this.vshelper, model.Vsenvironmenthelper);
 }
        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 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<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Anything))
                .Return(new List<Resource> { newResource });

            this.service.Expect(
                mp => mp.GetSourceForFileResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Anything))
                .Return(new Source { Lines = new[] { "line1", "line2", "line3", "line4" } })
                .Repeat.Once();

            this.service.Expect(
                mp => mp.GetIssuesInResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Anything))
                .Return(new List<Issue>())
                .Repeat.Once();

            this.service.Expect(
                mp => mp.GetCoverageInResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Anything))
                .Return(source1)
                .Repeat.Once();

            this.plugin.Expect(
                mp => mp.GetResourceKey(Arg<VsProjectItem>.Is.Anything, Arg<string>.Is.Anything))
                .Return("resource");

            var data = new ExtensionDataModel(this.service, this.vshelper, null);
            data.AssociatedProject = new Resource { Key = "sonar.com:common" };
            data.CoverageInEditorEnabled = true;

            data.RefreshDataForResource("resource");
            var data1 = data.GetCoverageInEditor("ghfggfgf\r\nghfggfgf\r\nghfggfgf\r\nghfggfgf\r\n");
            Assert.IsNotNull(data1);
        }
        public void VerifyResetVisibilitiesWhenStatusIsNotDefined()
        {
            var data = new ExtensionDataModel(this.service, this.vshelper, null)
            {
                SelectedIssuesInView =
                    new List<Issue>
                                       {
                                           new Issue { Status = null }
                                       }
            };

            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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetIssuesCommand"/> class.
 /// </summary>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <param name="service">
 /// The service.
 /// </param>
 public GetIssuesCommand(ExtensionDataModel model, ISonarRestService service)
 {
     this.model = model;
     this.service = service;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ViewSwitchCommand"/> class.
 /// </summary>
 /// <param name="model">
 /// The model.
 /// </param>
 public ViewSwitchCommand(ExtensionDataModel model)
 {
     this.model = model;
 }
 public void CoverageInEditorSetAndGetTest()
 {
     var data = new ExtensionDataModel(this.service, this.vshelper, null);
     var sourceCoverage = new Dictionary<int, CoverageElement>();
     Assert.AreEqual(sourceCoverage, data.GetCoverageInEditor(string.Empty));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AssociateCommand"/> class.
 /// </summary>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <param name="vsenvironmenthelper">
 /// The vsenvironmenthelper.
 /// </param>
 public AssociateCommand(ExtensionDataModel model, IVsEnvironmentHelper vsenvironmenthelper)
 {
     this.model = model;
     this.vsenvironmenthelper = vsenvironmenthelper;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UnConfirmIssueCommand"/> class.
 /// </summary>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <param name="service">
 /// The service.
 /// </param>
 public UnConfirmIssueCommand(ExtensionDataModel model, ISonarRestService service)
 {
     this.model = model;
     this.service = service;
 }
        /// <summary>
        /// The update model in tool window.
        /// </summary>
        /// <param name="modelToUse">
        /// The model to use.
        /// </param>
        private void UpdateModelInToolWindow(ExtensionDataModel modelToUse)
        {
            // init basic model without project association
            ToolWindowPane window = this.FindToolWindow(typeof(IssuesToolWindow), 0, true) as IssuesToolWindow;

            if (null == window || modelToUse == null)
            {
                return;
            }

            var win = window as IssuesToolWindow;
            modelToUse.ExtensionDataModelUpdate(new SonarRestService(new JsonSonarConnector()), new VsPropertiesHelper(this.dte2), null);
            win.UpdateModel(modelToUse);
        }
            public void DoServerAnalysisUpdateBufferFileNotFound()
            {
                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<ConnectionConfiguration>.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<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Anything))
                    .Return(new List<Resource> { element })
                    .Repeat.Twice();

                this.plugin.Expect(mp => mp.IsSupported(Arg<ConnectionConfiguration>.Is.Anything, Arg<Resource>.Is.Anything)).Return(true).Repeat.Once();
                this.plugin.Expect(
                    mp =>
                    mp.GetResourceKey(
                        Arg<VsProjectItem>.Is.Anything,
                        Arg<string>.Is.Anything)).Return("key").Repeat.Once();

                var data = new ExtensionDataModel(this.service, this.vshelper, null);
                data.AssociatedProject = new Resource { Key = "KEY"};
                data.RefreshDataForResource("c:\\src\\file.cpp");
                Assert.AreEqual("Extension Not Ready", data.ErrorMessage);
                Assert.AreEqual(0, data.GetIssuesInEditor("file").Count);
            }
 public void ShouldReturnWhenContstrainsAreNotMet()
 {
     var data = new ExtensionDataModel(this.service, this.vshelper, 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);
 }
 /// <summary>
 /// The bind commands in window.
 /// </summary>
 /// <param name="dataModelIn">
 /// The data model in.
 /// </param>
 private void BindCommandsInWindow(ExtensionDataModel dataModelIn)
 {
     // bind commands
     this.ConfPluginsOptions.DataContext = new ExtensionMenuCommand(dataModelIn);
 }
        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);
            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 VerifyMultiSelectionTest()
        {
            var data = new ExtensionDataModel(this.service, this.vshelper, null)
            {
                SelectedIssuesInView =
                    new List<Issue>
                                       {
                                           new Issue { Status = "OPEN" },
                                           new Issue { Status = "REOPENED" },
                                           new Issue { Status = "RESOLVED" }
                                       }
            };

            Assert.AreEqual(Visibility.Visible, 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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtensionMenuCommand"/> class.
 /// </summary>
 /// <param name="model">
 /// The model.
 /// </param>
 public ExtensionMenuCommand(ExtensionDataModel model)
 {
     this.model = model;
 }
        public void VerifyResolvedTest()
        {
            var data = new ExtensionDataModel(this.service, this.vshelper, null)
            {
                SelectedIssuesInView =
                    new List<Issue>
                                       {
                                           new Issue { Status = "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);
            var issues = service.GetIssuesInResource(config, "resource");
            var associatedProject = new Resource { Key = "core:Common" };

            this.model = new ExtensionDataModel(service, mockVsHelpers, associatedProject);
            var t = new Thread(this.Threadprc);
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FalsePositiveOnIssueCommand"/> class.
 /// </summary>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <param name="service">
 /// The service.
 /// </param>
 public FalsePositiveOnIssueCommand(ExtensionDataModel model, ISonarRestService service)
 {
     this.model = model;
     this.service = service;
 }
        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)
            {
                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 VerifyConfirmStatus()
        {
            var data = new ExtensionDataModel(this.service, this.vshelper, null, null)
            {
                SelectedIssuesInView =
                    new List<Issue>
                                       {
                                           new Issue { Status = IssueStatus.CONFIRMED }
                                       }
            };

            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.Visible, data.IsUnconfirmVisible);
            Assert.AreEqual(Visibility.Visible, data.IsAssignVisible);
            Assert.AreEqual(Visibility.Visible, data.IsOpenExternallyVisible);
        }
            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);
            }