Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FindTestPlan to actually check the right things #1773

Merged
merged 5 commits into from
Dec 6, 2023
Merged

Conversation

MrHinsh
Copy link
Member

@MrHinsh MrHinsh commented Dec 5, 2023

Thank you for responding so quickly.

I still believe the behavior is incorrect.

This line finds the target test Plan and sets it to the variable of testPlan

ITestPlan testPlan = (from p in tmc.Project.TestPlans.Query("Select * From TestPlan") where p.Name == name select p).SingleOrDefault();

This line uses the ID of the target work item to find an item in source, thereby returning the wrong work item.

 var sourceWI = Engine.Source.WorkItems.GetWorkItem(testPlan.Id.ToString());

Observe how in my case the id of 12422 finds a Test Plan in the target, but a Bug work item in the source

image

Originally posted by @sonofhammer in #1770 (comment)

The fix is to pass in the sourceWorkItemId and use both the Source and Target work items to get the expected and actual RefectedWorkItemID:

   private ITestPlan FindTestPlan(string planName, int sourcePlanId)
   {
       Log.LogDebug("TestPlansAndSuitesMigrationContext::FindTestPlan");
       ITestPlan testPlan = (from p in _targetTestStore.Project.TestPlans.Query("Select * From TestPlan") where p.Name == planName select p).SingleOrDefault();
 
       if (testPlan != null)
       {
           Log.LogDebug("TestPlansAndSuitesMigrationContext::FindTestPlan:: FOUND Test Plan with {name}", planName);
           //Check test plan is in fact the right one
           var sourceWI = Engine.Source.WorkItems.GetWorkItem(sourcePlanId);
           string expectedReflectedId = Engine.Source.WorkItems.CreateReflectedWorkItemId(sourceWI).ToString();
           var targetWI = Engine.Source.WorkItems.GetWorkItem(testPlan.Id.ToString());
           string workItemReflectedId = (string)targetWI.Fields[Engine.Target.Config.AsTeamProjectConfig().ReflectedWorkItemIDFieldName].Value;
           if (workItemReflectedId != expectedReflectedId)
           {
               Log.LogDebug("TestPlansAndSuitesMigrationContext::FindTestPlan:: Found test plan with name {name} does not match {workItemReflectedId} ", planName, workItemReflectedId);
               testPlan = null;
           }
       }
       else
       {
           Log.LogDebug("TestPlansAndSuitesMigrationContext::FindTestPlan:: NOT FOUND Test Plan with {name}", planName);
       }
       return testPlan;
   }

@MrHinsh MrHinsh temporarily deployed to nakedalmweb-githubSDK December 5, 2023 16:24 — with GitHub Actions Inactive
@MrHinsh MrHinsh self-assigned this Dec 5, 2023
@MrHinsh MrHinsh linked an issue Dec 5, 2023 that may be closed by this pull request
@MrHinsh MrHinsh changed the title This should fix #1772 with a new find method. Update FindTestPlan to actually check the right things Dec 5, 2023
@MrHinsh
Copy link
Member Author

MrHinsh commented Dec 5, 2023

Can you check this @sonofhammer

@MrHinsh MrHinsh temporarily deployed to nakedalmweb-githubSDK December 5, 2023 18:15 — with GitHub Actions Inactive
@MrHinsh MrHinsh temporarily deployed to nakedalmweb-githubSDK December 6, 2023 10:12 — with GitHub Actions Inactive
@MrHinsh
Copy link
Member Author

MrHinsh commented Dec 6, 2023

You have been very helpful here @sonofhammer

@MrHinsh MrHinsh merged commit 191a859 into master Dec 6, 2023
6 checks passed
@MrHinsh MrHinsh deleted the issue/1772 branch December 6, 2023 11:45
@sonofhammer
Copy link

Happy to help. My help is but a drop compared to how helpful this tool has been for me on my job. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TestPlan migrator uses TARGET work item ID to locate SOURCE Work Item
2 participants