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);
        }
        /// <summary>
        /// The filter by status.
        /// </summary>
        /// <param name="issue">
        /// The issue.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool FilterByStatus(Issue issue)
        {
            if (string.IsNullOrEmpty(issue.Status))
            {
                return false;
            }

            if (issue.Status.Equals("CLOSED"))
            {
                if (this.IsStatusClosedChecked)
                {
                    return false;
                }
            }

            if (issue.Status.Equals("OPEN"))
            {
                if (this.IsStatusOpenChecked)
                {
                    return false;
                }
            }

            if (issue.Status.Equals("CONFIRMED"))
            {
                if (this.IsStatusConfirmedChecked)
                {
                    return false;
                }
            }

            if (issue.Status.Equals("REOPENED"))
            {
                if (this.IsStatusReopenedChecked)
                {
                    return false;
                }
            }

            if (issue.Status.Equals("RESOLVED"))
            {
                if (this.IsStatusResolvedChecked)
                {
                    return false;
                }
            }

            return true;
        }
        /// <summary>
        /// The filter by severity.
        /// </summary>
        /// <param name="issue">
        /// The issue.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool FilterBySeverity(Issue issue)
        {
            if (string.IsNullOrEmpty(issue.Severity))
            {
                return false;
            }

            if (issue.Severity.EndsWith("INFO", true, CultureInfo.InvariantCulture))
            {
                if (this.IsInfoChecked)
                {
                    return false;
                }
            }

            if (issue.Severity.EndsWith("MINOR", true, CultureInfo.InvariantCulture))
            {
                if (this.IsMinorChecked)
                {
                    return false;
                }
            }

            if (issue.Severity.EndsWith("MAJOR", true, CultureInfo.InvariantCulture))
            {
                if (this.IsMajaorChecked)
                {
                    return false;
                }
            }

            if (issue.Severity.EndsWith("CRITICAL", true, CultureInfo.InvariantCulture))
            {
                if (this.IsCriticalChecked)
                {
                    return false;
                }
            }

            if (issue.Severity.EndsWith("BLOCKER", true, CultureInfo.InvariantCulture))
            {
                if (this.IsBlockerChecked)
                {
                    return false;
                }
            }

            return true;
        }
        /// <summary>
        /// The filter by resolution.
        /// </summary>
        /// <param name="issue">
        /// The issue.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool FilterByResolution(Issue issue)
        {
            if (string.IsNullOrEmpty(issue.Resolution))
            {
                return false;
            }

            if (issue.Resolution.Equals("FIXED"))
            {
                if (this.IsFixedChecked)
                {
                    return false;
                }
            }

            if (issue.Resolution.Equals("REMOVED"))
            {
                if (this.IsRemovedChecked)
                {
                    return false;
                }
            }

            return true;
        }
        /// <summary>
        /// The apply filter.
        /// </summary>
        /// <param name="issue">
        /// The issue.
        /// </param>
        /// <param name="newIssuesOnly">
        /// The new Issues Only.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool ApplyFilter(Issue issue, bool newIssuesOnly)
        {
            if (this.IsAssigneeChecked && !this.AssigneeInFilter.Login.Equals(issue.Assignee))
            {
                return true;
            }

            if (this.FilterByResolution(issue))
            {
                return true;
            }

            if (this.FilterByStatus(issue))
            {
                return true;
            }

            if (this.FilterBySeverity(issue))
            {
                return true;
            }

            if (newIssuesOnly)
            {
                if (!issue.IsNew)
                {
                    return true;
                }
            }

            return false;
        }
        /// <summary>
        /// The filter by severity.
        /// </summary>
        /// <param name="issue">
        /// The issue.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool FilterBySeverity(Issue issue)
        {
            if (string.IsNullOrEmpty(issue.Severity))
            {
                return false;
            }

            if (issue.Severity.Equals("1 : INFO"))
            {
                if (this.IsInfoChecked)
                {
                    return false;
                }
            }

            if (issue.Severity.Equals("2 : MINOR"))
            {
                if (this.IsMinorChecked)
                {
                    return false;
                }
            }

            if (issue.Severity.Equals("3 : MAJOR"))
            {
                if (this.IsMajaorChecked)
                {
                    return false;
                }
            }

            if (issue.Severity.Equals("4 : CRITICAL"))
            {
                if (this.IsCriticalChecked)
                {
                    return false;
                }
            }

            if (issue.Severity.Equals("5 : BLOCKER"))
            {
                if (this.IsBlockerChecked)
                {
                    return false;
                }
            }

            return true;
        }
 /// <summary>
 /// The is issue supported.
 /// </summary>
 /// <param name="issue">
 /// The issue.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 private bool IsIssueSupported(Issue issue)
 {
     return CxxPlugin.IsSupported(issue.Component);
 }
 public void TestSetIssuesListWithCommentsWithRefreshView()
 {
     var issueWithComment = new Issue();
     issueWithComment.Comments.Add(new Comment());
     var model = new ExtensionDataModel(this.service, this.vshelper, null)
     {
         Issues = new System.Collections.Generic.List<Issue>
                                 {
                                    issueWithComment,
                                    new Issue { Status = "REOPENED" }
                                 }
     };
     model.RefreshView();
     Assert.AreEqual(2, model.Issues.Count);
     Assert.AreEqual(1, model.Comments.Count);
     Assert.AreEqual("Number Of Issues: 2", model.StatsLabel);
 }
        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 TestSetIssuesList()
        {
            var issueWithId = new Issue { Id = 20, Component = "asdaskjd:sdaskjd:aksjdkas/asdkasj.cs", Key = new Guid() };

            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(new List<Issue> { issueWithId });

            Assert.AreEqual(1, model.Issues.Count);
            Assert.AreEqual("Number of Issues: 1 ", model.StatsLabel);
            Assert.AreEqual(string.Empty, model.ErrorMessage);
        }
        public void TestSelectIssueFromListUsingKey()
        {
            var issueWithId = new Issue { Id = 20, Component = "asdaskjd:sdaskjd:aksjdkas/asdkasj.cs", Key = new Guid() };

            var model = new ExtensionDataModel(this.service, this.vshelper, null);
            model.ReplaceAllIssuesInCache(new List<Issue> { issueWithId });

            model.SelectAIssueFromList(new Guid());
            Assert.AreEqual(issueWithId, model.SelectedIssue);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SonarTagDisplayViolationsAction"/> class.
 /// </summary>
 /// <param name="issue">
 /// The issue.
 /// </param>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <param name="enabledIn">
 /// The enabled In.
 /// </param>
 public SonarTagDisplayViolationsAction(Issue issue, ExtensionDataModel model, bool enabledIn = true)
 {
     this.model = model;
     this.issue = issue;
     this.enabled = enabledIn;
 }
Exemple #13
0
        /// <summary>
        /// The get violations.
        /// </summary>
        /// <param name="lines">
        ///     The lines.
        /// </param>
        /// <returns>
        /// The VSSonarPlugin.SonarInterface.ResponseMappings.Violations.ViolationsResponse.
        /// </returns>
        public override List<Issue> GetViolations(FSharpList<string> lines)
        {
            var violations = new List<Issue>();

            if (lines == null || lines.Length == 0)
            {
                return violations;
            }

            foreach (var line in lines)
            {
                try
                {
                    int start = 0;
                    var file = GetStringUntilFirstChar(ref start, line, '(');

                    start++;
                    var linenumber = Convert.ToInt32(GetStringUntilFirstChar(ref start, line, ')'));

                    start += 2;
                    var msg = GetStringUntilFirstChar(ref start, line, '[').Trim();

                    start++;
                    var id = GetStringUntilFirstChar(ref start, line, ']');

                    var entry = new Issue
                                    {
                                        Line = linenumber,
                                        Message = msg,
                                        Rule = this.RepositoryKey + "." + id,
                                        Component = file
                                    };

                    violations.Add(entry);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("error: " + ex.Message);
                }
            }

            return violations;
        }
Exemple #14
0
        /// <summary>
        /// The get violations.
        /// </summary>
        /// <param name="lines">
        ///     The lines.
        /// </param>
        /// <returns>
        /// The VSSonarPlugin.SonarInterface.ResponseMappings.Violations.ViolationsResponse.
        /// </returns>
        public override List<Issue> GetViolations(FSharpList<string> lines)
        {
            var violations = new List<Issue>();

            if (lines == null || lines.Length == 0)
            {
                return violations;
            }

            var xml = new XmlDeserializer();
            var output = xml.Deserialize<List<Vulnerability>>(new RestResponse { Content = string.Join("\r\n", lines) });

            foreach (var result in output)
            {
                if (string.IsNullOrEmpty(result.Type))
                {
                    foreach (var file in result.Files)
                    {
                        foreach (var line in file.LineId)
                        {
                            var entry = new Issue
                                            {
                                                Rule = this.RepositoryKey + "." + result.Type,
                                                Line = line.Value,
                                                Message = result.Message,
                                                Component = file.Name
                                            };

                            try
                            {
                                entry.Severity = (Severity)Enum.Parse(typeof(Severity), result.Severity);
                            }
                            catch (Exception ex)
                            {
                                entry.Severity  = Severity.UNDEFINED;
                            }

                            violations.Add(entry);
                        }
                    }
                }
            }

            return violations;
        }
        /// <summary>
        /// The deep copy.
        /// </summary>
        /// <returns>
        /// The <see cref="Issue"/>.
        /// </returns>
        public Issue DeepCopy()
        {
            var copyIssue = new Issue
                                {
                                    Id = this.Id,
                                    Key = this.Key,
                                    Line = this.Line,
                                    Message = this.Message,
                                    Project = this.Project,
                                    Resolution = this.Resolution,
                                    Rule = this.Rule,
                                    Severity = this.Severity,
                                    Status = this.Status,
                                    UpdateDate = this.UpdateDate,
                                    CloseDate = this.CloseDate,
                                    Component = this.Component,
                                    CreationDate = this.CreationDate,
                                    EffortToFix = this.EffortToFix,
                                    ViolationId = this.ViolationId,
                                    Assignee = this.Assignee,
                                    Comments = new List<Comment>()
                                };

            foreach (var comment in this.Comments)
            {
                var copyComment = new Comment
                                      {
                                          CreatedAt = comment.CreatedAt,
                                          HtmlText = comment.HtmlText,
                                          Id = comment.Id,
                                          Key = comment.Key,
                                          Login = comment.Login
                                      };
                copyIssue.Comments.Add(copyComment);
            }

            return copyIssue;
        }
Exemple #16
0
        /// <summary>
        /// The get violations.
        /// </summary>
        /// <param name="lines">
        ///     The lines.
        /// </param>
        /// <returns>
        /// The VSSonarPlugin.SonarInterface.ResponseMappings.Violations.ViolationsResponse.
        /// </returns>
        public override List<Issue> GetViolations(FSharpList<string> lines)
        {
            var violations = new List<Issue>();

            if (lines == null || lines.Length == 0)
            {
                return violations;
            }

            foreach (var line in lines)
            {
                try
                {
                    var elems = line.Split(':');
                    var file = elems[0] + ":" + elems[1];
                    var linenumber = Convert.ToInt32(elems[2]);
                    var data = elems[3].Split('(');
                    var id = data[1].Split(')')[0];
                    var msg = data[1].Split(')')[1];

                    var entry = new Issue
                                    {
                                        Line = linenumber,
                                        Message = msg,
                                        Rule = this.RepositoryKey + "." + id,
                                        Component = file
                                    };

                    violations.Add(entry);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("error: " + ex.Message);
                }
            }

            return violations;
        }
        public void TestSelectIssueFromListUsingKey()
        {
            var issueWithId = new Issue { Key = new Guid() };

            var model = new ExtensionDataModel(this.service, this.vshelper, null)
            {
                Issues = new System.Collections.Generic.List<Issue>
                                        {
                                           issueWithId,
                                           new Issue { Status = "REOPENED" }
                                        }
            };

            model.SelectAIssueFromList(new Guid());
            Assert.AreEqual(issueWithId, model.SelectedIssue);
        }