Ejemplo n.º 1
0
        public void CreateRandomIssues()
        {
            List<Project> ps = Project.GetAllProjects();
            if (ps.Count > 0) {

                Project p = ps[0];

                int StartIssueCount = Issue.GetIssuesByProjectId(p.Id).Count;

                RandomProjectData prand = new RandomProjectData(p);

                for (int i = 0; i < CNST_NumIssues; i++)
                {
                    // Get Random yet valid data for the current project
                    Category c = prand.GetCategory();
                    Milestone ms = prand.GetMilestone();
                    Status st = prand.GetStatus();
                    Priority pr = prand.GetPriority();
                    IssueType isst = prand.GetIssueType();
                    Resolution res = prand.GetResolution();

                    string assigned = prand.GetUsername();
                    // creator is also the owner
                    string createdby = prand.GetUsername();

                    Issue iss = new Issue(0, p.Id, RandomStrings.RandomString(30), RandomStrings.RandomString(250), c.Id, pr.Id, st.Id, isst.Id,
                        ms.Id, ms.Id, res.Id,createdby , assigned, createdby, 0, 1, DateTime.MinValue);
                    iss.Save();
                }

                int EndIssueCount = Issue.GetIssuesByProjectId(p.Id).Count;

                // Did we create only CNST_SmallIssues issues?
                Assert.IsTrue(EndIssueCount == StartIssueCount + CNST_NumIssues);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns an Issue object, pre-populated with defaults settings.
        /// </summary>
        /// <param name="projectId">The project id.</param> 
        /// <param name="AssignedName">The Assigned To username.</param> 
        /// <param name="OwnerName">The owner and reporter username.</param> 
        /// <returns></returns>
        public static Issue GetDefaultIssueByProjectId(int projectId, string Title, string Description, string AssignedName, string OwnerName)
        {
            if (projectId < DefaultValues.GetProjectIdMinValue())
                throw new ArgumentOutOfRangeException(string.Format("ProjectID must be {0} or larger.", DefaultValues.GetProjectIdMinValue()));

            Project CurProject = Project.GetProjectById(projectId);

            if (CurProject == null)
                throw new ArgumentException("Project not found for ProjectID.");

            List<Category> Cats = Category.GetCategoriesByProjectId(projectId);
            Category defCat = null;
            List<Status> Statuses = Status.GetStatusByProjectId(projectId);
            Status defStatus = null;
            List<Priority> Priorities = Priority.GetPrioritiesByProjectId(projectId);
            Priority defPriority = null;
            List<IssueType> IssueTypes = IssueType.GetIssueTypesByProjectId(projectId);
            IssueType defIssueType = null;
            List<Resolution> Resolutions = Resolution.GetResolutionsByProjectId(projectId);
            Resolution defResolution = null;
            List<Milestone> AffectedMilestones = Milestone.GetMilestoneByProjectId(projectId);
            Milestone defAffectedMilestone = null;
            List<Milestone> Milestones = Milestone.GetMilestoneByProjectId(projectId);
            Milestone defMilestone = null;

            // Select the first one in the list, not really the default intended.
            defCat = Cats[0];
            defStatus = Statuses[0];
            defPriority = Priorities[0];
            defIssueType = IssueTypes[0];
            defResolution = Resolutions[0];
            defAffectedMilestone = AffectedMilestones[0];
            defMilestone = Milestones[0];

            // Now create an issue
            Issue iss = new Issue(0, projectId, Title, Description, defCat.Id, defPriority.Id, defStatus.Id,
                defIssueType.Id, defMilestone.Id, defAffectedMilestone.Id, defResolution.Id,
                OwnerName, AssignedName, OwnerName, 0, 0, DateTime.MinValue);

            return iss;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves the bug.
        /// </summary>
        /// <returns></returns>
        private bool SaveIssue()
        {
            decimal estimation;
            decimal.TryParse(txtEstimation.Text.Trim(), out estimation);
            DateTime dueDate = DueDate.Text.Length > 0 ? DateTime.Parse(DueDate.Text) : DateTime.MinValue;

            bool NewIssue = (IssueId <= 0);

            // WARNING: DO NOT ENCODE THE HTMLEDITOR TEXT.
            // It expects raw input. So pass through a raw string.
            // This is a potential XSS vector as the Issue Class should
            // handle sanitizing the input and checking that its input is HtmlEncoded
            // (ie no < or > characters), not the IssueDetail.aspx.cs

            Issue newIssue = new Issue(IssueId, ProjectId, string.Empty, string.Empty, Server.HtmlEncode(TitleTextBox.Text), DescriptionHtmlEditor.Text.Trim(),
                DropCategory.SelectedValue, DropCategory.SelectedText, DropPriority.SelectedValue, DropPriority.SelectedText,
                string.Empty, DropStatus.SelectedValue, DropStatus.SelectedText, string.Empty, DropIssueType.SelectedValue,
                DropIssueType.SelectedText, string.Empty, DropResolution.SelectedValue, DropResolution.SelectedText, string.Empty,
                DropAssignedTo.SelectedText, DropAssignedTo.SelectedValue, Guid.Empty, Security.GetDisplayName(),
                Security.GetUserName(), Guid.Empty, DropOwned.SelectedText, DropOwned.SelectedValue, Guid.Empty, dueDate,
                DropMilestone.SelectedValue, DropMilestone.SelectedText, string.Empty, null, DropAffectedMilestone.SelectedValue, DropAffectedMilestone.SelectedText,
                string.Empty, chkPrivate.Checked == true ? 1 : 0,
                0, estimation, DateTime.MinValue, DateTime.MinValue, Security.GetUserName(), Security.GetDisplayName(),
                Convert.ToInt32(ProgressSlider.Text), false, 0);

            if (!newIssue.Save())
            {
                Message1.ShowErrorMessage("Could not save issue");
                return false;
            }

            IssueId = newIssue.Id;

            if (!CustomField.SaveCustomFieldValues(IssueId, ctlCustomFields.Values))
            {
                Message1.ShowErrorMessage("Could not save issue custom fields");
                return false;
            }

            //if new issue check if notify owner and assigned is checked.
            if (NewIssue)
            {
                //add attachment if present.
                // get the current file
                HttpPostedFile uploadFile = this.AspUploadFile.PostedFile;
                HttpContext context = HttpContext.Current;
                if (uploadFile.ContentLength > 0)
                {
                    IssueAttachment.UploadFile(IssueId, uploadFile, context, AttachmentDescription.Text.Trim());
                }

                //create a vote for the new issue
                IssueVote vote = new IssueVote(IssueId, Security.GetUserName());
                if (!vote.Save())
                    Message1.ShowErrorMessage("Could not save issue vote.");

                if (chkNotifyOwner.Checked)
                {
                    System.Web.Security.MembershipUser oUser = ITUser.GetUser(newIssue.OwnerUserName);
                    if (oUser != null)
                    {
                        IssueNotification notify = new IssueNotification(IssueId, oUser.UserName);
                        notify.Save();
                    }
                }
                if (chkNotifyAssignedTo.Checked && !string.IsNullOrEmpty(newIssue.AssignedUserName))
                {
                    System.Web.Security.MembershipUser oUser = ITUser.GetUser(newIssue.AssignedUserName);
                    if (oUser != null)
                    {
                        IssueNotification notify = new IssueNotification(IssueId, oUser.UserName);
                        notify.Save();
                    }
                }
                IssueNotification.SendIssueAddNotifications(IssueId);
            }

            return true;
        }
Ejemplo n.º 4
0
        public void TestCreation1()
        {
            TestIssue = new Issue(Id, ProjectId, ProjectName, Code, Title, Description,
                CategoryId, CategoryName, PriorityId, PriorityName,PriorityImageUrl, StatusId, StatusName,StatusImageUrl, IssueTypeId, IssueTypeName,IssueTypeImageUrl,
                ResolutionId, ResolutionName,ResolutionImageUrl, AssignedDisplayName, AssignedUsername, AssignedUserId,
                CreatorDisplayName, CreatorUsername, CreatorUserId, OwnerDisplayName, OwnerUsername, OwnerUserId, DueDate, MilestoneId,
                MilestoneName,MilestoneImageUrl, MilestoneDueDate,AffectedMilestoneId,AffectedMilestoneName,AffectedMilestoneImageUrl, Visibility, TimeLogged, Estimation, DateCreated, LastUpdate, LastUpdateUsername, LastUpdateDisplayName,Progress,Disabled, Votes);

            Assert.AreEqual(Code, TestIssue.ProjectCode);
            Assert.AreEqual(Id, TestIssue.Id);
            Assert.AreEqual(ProjectId, TestIssue.ProjectId);
            Assert.AreEqual(ProjectName, TestIssue.ProjectName);
            Assert.AreEqual(Title, TestIssue.Title);
            Assert.AreEqual(Description, TestIssue.Description);
            Assert.AreEqual(CategoryId, TestIssue.CategoryId);
            Assert.AreEqual(CategoryName, TestIssue.CategoryName);
            Assert.AreEqual(MilestoneId, TestIssue.MilestoneId);
            Assert.AreEqual(MilestoneName, TestIssue.MilestoneName);
            Assert.AreEqual(AffectedMilestoneId, TestIssue.AffectedMilestoneId);
            Assert.AreEqual(MilestoneName, TestIssue.MilestoneName);
            Assert.AreEqual(PriorityId, TestIssue.PriorityId);
            Assert.AreEqual(PriorityName, TestIssue.PriorityName);
            Assert.AreEqual(StatusId, TestIssue.StatusId);
            Assert.AreEqual(StatusName, TestIssue.StatusName);
            Assert.AreEqual(IssueTypeId, TestIssue.IssueTypeId);
            Assert.AreEqual(IssueTypeName, TestIssue.IssueTypeName);
            Assert.AreEqual(ResolutionId, TestIssue.ResolutionId);
            Assert.AreEqual(ResolutionName, TestIssue.ResolutionName);
            Assert.AreEqual(AssignedDisplayName, TestIssue.AssignedDisplayName);
            Assert.AreEqual(AssignedUserId, TestIssue.AssignedUserId);
            Assert.AreEqual(CreatorDisplayName, TestIssue.CreatorDisplayName);
            Assert.AreEqual(CreatorUserId, TestIssue.CreatorUserId);
            Assert.AreEqual(CreatorUsername, TestIssue.CreatorUserName);
            Assert.AreEqual(DateCreated, TestIssue.DateCreated);
            Assert.AreEqual(LastUpdateUsername, TestIssue.LastUpdateUserName);
            Assert.AreEqual(LastUpdate, TestIssue.LastUpdate);
            Assert.AreEqual(LastUpdateDisplayName, TestIssue.LastUpdateDisplayName);
            Assert.AreEqual(Estimation, TestIssue.Estimation);
        }
Ejemplo n.º 5
0
 public void TestCreation()
 {
     TestIssue = new Issue();
     Assert.IsNotNull(TestIssue);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Handles the Click event of the SaveIssues control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void SaveIssues_Click(object sender, EventArgs e)
        {
            //TODO: Ajax progress bar when this is running;
            string ids = GetSelectedIssueIds();
            if (ids.Length > 0)
            {

                //prune out all values that must not change
                var customFieldValues = ctlCustomFields.Values;
                for (int i = customFieldValues.Count - 1; i >= 0; i--)
                {
                    var value = customFieldValues[i];
                    if (string.IsNullOrEmpty(value.Value))
                    {
                        customFieldValues.RemoveAt(i);
                    }
                }

                foreach (string s in ids.Split(new char[] { ',' }))
                {
                    Issue issue = Issue.GetIssueById(Convert.ToInt32(s));
                    if (issue != null)
                    {
                        DateTime dueDate = DueDate.Text.Length > 0 ? DateTime.Parse(DueDate.Text) : DateTime.MinValue;

                        Issue newIssue = new Issue(issue.Id, issue.ProjectId, string.Empty, string.Empty,issue.Title, issue.Description,
                            dropCategory.SelectedValue != 0 ? dropCategory.SelectedValue : issue.CategoryId, dropCategory.SelectedValue != 0 ? dropCategory.SelectedText : issue.CategoryName,
                            dropPriority.SelectedValue != 0 ? dropPriority.SelectedValue : issue.PriorityId, dropPriority.SelectedValue != 0 ? dropPriority.SelectedText : issue.PriorityName,
                            string.Empty,
                            dropStatus.SelectedValue != 0 ? dropStatus.SelectedValue : issue.StatusId,
                            dropStatus.SelectedValue != 0 ? dropStatus.SelectedText : issue.StatusName, string.Empty,
                            dropType.SelectedValue != 0 ? dropType.SelectedValue : issue.IssueTypeId,
                            dropType.SelectedValue != 0 ? dropType.SelectedText : issue.IssueTypeName, string.Empty,
                            dropResolution.SelectedValue != 0 ? dropResolution.SelectedValue : issue.ResolutionId,
                            dropResolution.SelectedValue != 0 ? dropResolution.SelectedText : issue.ResolutionName, string.Empty,
                            dropAssigned.SelectedValue != string.Empty ? dropAssigned.SelectedText : issue.AssignedDisplayName,
                            dropAssigned.SelectedValue != string.Empty ? dropAssigned.SelectedValue : issue.AssignedUserName,
                            Guid.Empty, Security.GetDisplayName(),Security.GetUserName(), Guid.Empty,
                            dropOwner.SelectedValue !=string.Empty ? dropOwner.SelectedText : issue.OwnerDisplayName,
                            dropOwner.SelectedValue != string.Empty ? dropOwner.SelectedValue : issue.OwnerUserName, Guid.Empty, dueDate != DateTime.MinValue ? dueDate : issue.DueDate,
                            dropMilestone.SelectedValue != 0 ? dropMilestone.SelectedValue : issue.MilestoneId, dropMilestone.SelectedValue != 0 ? dropMilestone.SelectedText : issue.MilestoneName, string.Empty, null,
                            dropAffectedMilestone.SelectedValue != 0 ? dropAffectedMilestone.SelectedValue : issue.AffectedMilestoneId, dropAffectedMilestone.SelectedValue != 0 ? dropAffectedMilestone.SelectedText : issue.AffectedMilestoneName,
                            string.Empty, issue.Visibility,0, issue.Estimation, DateTime.MinValue, DateTime.MinValue, Security.GetUserName(), Security.GetDisplayName(),
                            issue.Progress, false, 0);

                        newIssue.Save();

                        CustomField.SaveCustomFieldValues(issue.Id, customFieldValues);

                    }

                }
            }
            OnRebindCommand(EventArgs.Empty);
        }