コード例 #1
0
        // return all not done defects
        public static GroupResult GetAllDefectWithGroupBy(string releaseId)
        {
            List <String> fields = new List <string>();

            fields.Add(WorkItem.NAME_FIELD);
            fields.Add(WorkItem.SUBTYPE_FIELD);


            List <QueryPhrase> queries      = new List <QueryPhrase>();
            LogicalQueryPhrase subtypeQuery = new LogicalQueryPhrase(WorkItem.SUBTYPE_FIELD, WorkItem.SUBTYPE_DEFECT);

            queries.Add(subtypeQuery);
            QueryPhrase releaseIdPhrase = new LogicalQueryPhrase("id", releaseId);
            QueryPhrase byReleasePhrase = new CrossQueryPhrase(WorkItem.RELEASE_FIELD, releaseIdPhrase);

            queries.Add(byReleasePhrase);
            LogicalQueryPhrase  doneMetaphasePhrase    = new LogicalQueryPhrase("logical_name", "metaphase.work_item.done");
            NegativeQueryPhrase notDoneMetaphasePhrase = new NegativeQueryPhrase(doneMetaphasePhrase);
            CrossQueryPhrase    phaseIdPhrase          = new CrossQueryPhrase("metaphase", notDoneMetaphasePhrase);
            CrossQueryPhrase    byPhasePhrase          = new CrossQueryPhrase(WorkItem.PHASE_FIELD, phaseIdPhrase);

            queries.Add(byPhasePhrase);

            GroupResult result = SettingsForm.EntityService.GetWithGroupBy <WorkItem>(workspaceContext, queries, "severity");

            return(result);
        }
コード例 #2
0
        public void GetNotDoneDefectsAssinedToReleaseTest()
        {
            Phase PHASE_CLOSED = TestHelper.GetPhaseForEntityByLogicalName(entityService, workspaceContext, WorkItem.SUBTYPE_DEFECT, "phase.defect.closed");

            Defect  defect1 = CreateDefect();
            Defect  defect2 = CreateDefect(PHASE_CLOSED);
            Defect  defect3 = CreateDefect();
            Defect  defect4 = CreateDefect();
            Release release = ReleaseTests.CreateRelease();

            //assign defect to release
            Defect defectForUpdate1 = new Defect(defect1.Id);

            defectForUpdate1.Release = release;
            Defect defectForUpdate2 = new Defect(defect2.Id);

            defectForUpdate2.Release = release;
            Defect defectForUpdate3 = new Defect(defect3.Id);

            defectForUpdate3.Release  = release;
            defectForUpdate3.Severity = getSeverityCritical();

            Defect defectForUpdate4 = new Defect(defect4.Id);

            defectForUpdate4.Release = release;


            EntityList <Defect> listForUpdate = new EntityList <Defect>();

            listForUpdate.data.AddRange(new Defect[] { defectForUpdate1, defectForUpdate2, defectForUpdate3, defectForUpdate4 });

            EntityListResult <Defect> updated = entityService.UpdateEntities <Defect>(workspaceContext, listForUpdate);

            Assert.AreEqual <int?>(4, updated.total_count);

            //Fetch all defects that assigned to release and still not done
            //Fetch defects as work-items
            List <QueryPhrase> queries      = new List <QueryPhrase>();
            LogicalQueryPhrase subtypeQuery = new LogicalQueryPhrase(WorkItem.SUBTYPE_FIELD, WorkItem.SUBTYPE_DEFECT);

            queries.Add(subtypeQuery);

            //condition of release
            QueryPhrase releaseIdPhrase = new LogicalQueryPhrase(WorkItem.ID_FIELD, release.Id);
            QueryPhrase byReleasePhrase = new CrossQueryPhrase(WorkItem.RELEASE_FIELD, releaseIdPhrase);

            queries.Add(byReleasePhrase);

            //There are several phased in "Done" metaphase - there are we are doing condition on metaphase and not on phase
            //condition by metaphase (parent of phase)
            LogicalQueryPhrase  donePhaseNamePhrase = new LogicalQueryPhrase(Metaphase.LOGICAL_NAME_FIELD, "metaphase.work_item.done");
            NegativeQueryPhrase notDonePhrase       = new NegativeQueryPhrase(donePhaseNamePhrase);
            CrossQueryPhrase    phaseIdPhrase       = new CrossQueryPhrase("metaphase", notDonePhrase);
            CrossQueryPhrase    byPhasePhrase       = new CrossQueryPhrase(WorkItem.PHASE_FIELD, phaseIdPhrase);

            queries.Add(byPhasePhrase);

            EntityListResult <WorkItem> entitiesResult = entityService.Get <WorkItem>(workspaceContext, queries, null);

            Assert.AreEqual <int>(3, entitiesResult.total_count.Value);
            Assert.IsTrue(entitiesResult.data[0].Id == defect1.Id || entitiesResult.data[0].Id == defect3.Id || entitiesResult.data[0].Id == defect4.Id);
            Assert.IsTrue(entitiesResult.data[1].Id == defect1.Id || entitiesResult.data[1].Id == defect3.Id || entitiesResult.data[1].Id == defect4.Id);
            Assert.IsTrue(entitiesResult.data[2].Id == defect1.Id || entitiesResult.data[2].Id == defect3.Id || entitiesResult.data[2].Id == defect4.Id);


            //check group by
            GroupResult groupResult = entityService.GetWithGroupBy <WorkItem>(workspaceContext, queries, "severity");

            Assert.AreEqual(2, groupResult.groupsTotalCount);
            Group group1 = groupResult.groups[0];
            Group group2 = groupResult.groups[1];

            if (group1.count == 1)
            {
                Group temp = group1;
                group1 = group2;
                group2 = temp;
            }

            Assert.AreEqual <int>(2, group1.count);
            Assert.AreEqual <String>("list_node.severity.high", group1.value.logical_name);
            Assert.AreEqual <int>(1, group2.count);
            Assert.AreEqual <String>("list_node.severity.urgent", group2.value.logical_name);
        }