Пример #1
0
        private void AssignTesters(ITestSuiteBase sourceSuite, ITestSuiteBase targetSuite)
        {
            if (targetSuite == null)
            {
                Trace.TraceError($"Target Suite is NULL");
            }

            List <ITestPointAssignment> assignmentsToAdd = new List <ITestPointAssignment>();

            //loop over all source test case entries
            foreach (ITestSuiteEntry sourceTce in sourceSuite.TestCases)
            {
                // find target testcase id for this source tce
                WorkItem targetTc = targetWitStore.FindReflectedWorkItem(sourceTce.TestCase.WorkItem, false);

                if (targetTc == null)
                {
                    Trace.TraceError($"Target Reflected Work Item Not found for source WorkItem ID: {sourceTce.TestCase.WorkItem.Id}");
                }

                //figure out test point assignments for each source tce
                foreach (ITestPointAssignment tpa in sourceTce.PointAssignments)
                {
                    int sourceConfigurationId = tpa.ConfigurationId;

                    TeamFoundationIdentity targetIdentity = null;

                    if (tpa.AssignedTo != null)
                    {
                        targetIdentity = GetTargetIdentity(tpa.AssignedTo.Descriptor);
                        if (targetIdentity == null)
                        {
                            sourceIdentityManagementService.RefreshIdentity(tpa.AssignedTo.Descriptor);
                        }

                        targetIdentity = GetTargetIdentity(tpa.AssignedTo.Descriptor);
                    }

                    // translate source configuration id to target configuration id and name
                    //// Get source configuration name
                    string sourceConfigName = (from tc in sourceTestConfigs
                                               where tc.Id == sourceConfigurationId
                                               select tc.Name).FirstOrDefault();

                    //// Find source configuration name in target and get the id for it
                    int targetConfigId = (from tc in targetTestConfigs
                                          where tc.Name == sourceConfigName
                                          select tc.Id).FirstOrDefault();

                    if (targetConfigId != 0)
                    {
                        IdAndName targetConfiguration = new IdAndName(targetConfigId, sourceConfigName);

                        var targetUserId = Guid.Empty;
                        if (targetIdentity != null)
                        {
                            targetUserId = targetIdentity.TeamFoundationId;
                        }

                        // Create a test point assignment with target test case id, target configuration (id and name) and target identity
                        var newAssignment = targetSuite.CreateTestPointAssignment(
                            targetTc.Id,
                            targetConfiguration,
                            targetUserId);

                        // add the test point assignment to the list
                        assignmentsToAdd.Add(newAssignment);
                    }
                    else
                    {
                        Trace.Write($"Cannot find configuration with name [{sourceConfigName}] in target. Cannot assign tester to it.", "TestPlansAndSuites");
                    }
                }
            }

            // assign the list to the suite
            targetSuite.AssignTestPoints(assignmentsToAdd);
        }