Skip to content

Commit 631a643

Browse files
committed
🐛 (TfsTestPlansAndSuitesMigrationProcessor.cs): handle duplicate test plan names
Enhance the `FindTestPlan` method to handle scenarios where multiple test plans have the same name. Previously, the code assumed that test plan names were unique, which could lead to unexpected behavior or errors if duplicates existed. The updated logic checks for multiple test plans with the same name, logs a warning with their IDs, and throws an exception to prevent further execution. This ensures that the migration process does not proceed with ambiguous test plan identification, maintaining data integrity.
1 parent 80f93c2 commit 631a643

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/MigrationTools.Clients.TfsObjectModel/Processors/TfsTestPlansAndSuitesMigrationProcessor.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,16 @@ private ITestSuiteBase FindSuiteEntry(IStaticTestSuite staticSuite, string title
607607
private ITestPlan FindTestPlan(string planName, int sourcePlanId)
608608
{
609609
Log.LogDebug("TestPlansAndSuitesMigrationContext::FindTestPlan");
610-
ITestPlan testPlan = (from p in _targetTestStore.Project.TestPlans.Query("Select * From TestPlan") where p.Name == planName select p).SingleOrDefault();
611-
610+
ITestPlan testPlan;
611+
List<ITestPlan> testPlans = (from p in _targetTestStore.Project.TestPlans.Query("Select * From TestPlan") where p.Name == planName select p).ToList();
612+
if (testPlans.Count > 1)
613+
{
614+
string result = string.Join(",", testPlans.Select(obj => obj.Id));
615+
Log.LogWarning("We found multiple test Plans with the name '{TestPlanName}'. They have ID(s) of '{result}'! We only have name at this point as a unique identifier and duplicates will break the code. Ensure that all Test Plans have unique names.", planName, result);
616+
throw new Exception(string.Format("Test plans {0} all have the same name!", result));
617+
}
618+
testPlan = testPlans[0];
619+
612620
if (testPlan != null)
613621
{
614622
Log.LogDebug("TestPlansAndSuitesMigrationContext::FindTestPlan:: FOUND Test Plan with {name}", planName);
@@ -1173,4 +1181,4 @@ private void ValidateAndFixTestSuiteQuery(ITestSuiteBase source, IDynamicTestSui
11731181
}
11741182
}
11751183
}
1176-
}
1184+
}

0 commit comments

Comments
 (0)