public void  DefectCoverageTest()
        {
            Test   createdTest1  = TestManualTests.CreateManualTest();
            Test   createdTest2  = TestManualTests.CreateManualTest();
            Test   createdTest3  = TestManualTests.CreateManualTest();
            Defect createdDefect = DefectTests.CreateDefect();

            //create coverage
            Defect defectForUpdate = new Defect(createdDefect.Id);

            //add tests

            EntityList <Test> testList = new EntityList <Test>();
            Test testForLink1          = new Test(createdTest1.Id);

            testForLink1.TypeName = "test";
            testList.data.Add(testForLink1);

            Test testForLink2 = new Test(createdTest3.Id);

            testForLink2.TypeName = "test";
            testList.data.Add(testForLink2);

            defectForUpdate.SetValue("test", testList);

            //define service arg, its required to add new relation instead of replace existing ones
            Dictionary <string, string> serviceArgs = new Dictionary <string, string>();

            serviceArgs.Add("reference_update_mode", "append");

            //actial update
            Defect updated = entityService.Update(workspaceContext, defectForUpdate, serviceArgs, null);


            //get test coverage
            List <QueryPhrase> queryPhrases         = new List <QueryPhrase>();
            QueryPhrase        defectIdPhrase       = new LogicalQueryPhrase(Release.ID_FIELD, createdDefect.Id);
            QueryPhrase        coveredContentPhrase = new CrossQueryPhrase("covered_content", defectIdPhrase);

            queryPhrases.Add(coveredContentPhrase);
            EntityListResult <Test> coveredTests = entityService.Get <Test>(workspaceContext, queryPhrases, null);

            Assert.AreEqual(2, coveredTests.data.Count);

            //validation
            List <EntityId> coveredTestIds = coveredTests.data.ConvertAll <EntityId>(a => a.Id);

            Assert.IsTrue(coveredTestIds.Contains(testForLink1.Id));
            Assert.IsTrue(coveredTestIds.Contains(testForLink2.Id));
        }
Beispiel #2
0
        public void SearchWorkItems()
        {
            var guid    = Guid.NewGuid();
            var story   = StoryTests.CreateStory("Story_WorkItem_CustomName_" + guid);
            var epic    = CreateEpic("Epic_WorkItem_CustomName_" + guid);
            var feature = CreateFeature(epic, "Feature_WorkItem_CustomName_" + guid);
            var defect  = DefectTests.CreateDefect("Defect_WorkItem_CustomName_" + guid);

            var expectedWorkItems = new List <WorkItem>
            {
                story, epic, feature
            };

            EntityListResult <WorkItem> searchResult = null;

            SpinWait.SpinUntil(() =>
            {
                Thread.Sleep(1000);

                searchResult = entityService.SearchAsync <WorkItem>(workspaceContext, "_WorkItem_CustomName_" + guid,
                                                                    new List <string> {
                    WorkItem.SUBTYPE_STORY, WorkItem.SUBTYPE_EPIC, WorkItem.SUBTYPE_FEATURE
                }).Result;

                return(searchResult.data.Count == 3);
            }, new TimeSpan(0, 2, 0));

            Assert.IsNotNull(searchResult, "search operation should have returned something");
            Assert.AreEqual(3, searchResult.data.Count, "Mismatched number of entities returned by the search operation");

            int actualTestsFoundCount = 0;

            foreach (var workItem in expectedWorkItems)
            {
                actualTestsFoundCount += searchResult.data.Count(t => t.Id == workItem.Id);
            }

            Assert.AreEqual(searchResult.data.Count, actualTestsFoundCount, "Search request didn't return expected results");
        }
        public void AttachToDefect()
        {
            string fileName     = "test.txt";
            string fileContents = "This is a test for attachments\r\nChecking that it's working";

            byte[] fileContentsBytes = Encoding.UTF8.GetBytes(fileContents);

            Defect     createdDefect = DefectTests.CreateDefect();
            Attachment attachment    = entityService.AttachToEntity(workspaceContext, createdDefect, fileName, fileContentsBytes, "text/plain", new string[] { "owner_work_item" });

            Assert.IsNotNull(attachment.Id);
            Assert.AreEqual(attachment.owner_work_item.TypeName, "defect");
            Assert.AreEqual(attachment.owner_work_item.Id, createdDefect.Id);

            var relativeUrl = workspaceContext.GetPath() + "/attachments/" + attachment.Id + "/" + fileName;
            var filePath    = Path.GetTempPath() + "\\" + Guid.NewGuid() + ".txt";

            entityService.DownloadAttachmentAsync(relativeUrl, filePath).Wait();

            using (var sr = new StreamReader(filePath))
            {
                Assert.AreEqual(fileContents, sr.ReadToEnd(), "Mismatched file contents");
            }
        }