public TestRunsMigrationContext(MigrationEngine me, TestRunsMigrationConfig config) : base(me, config)
 {
     sourceWitStore  = new WorkItemStoreContext(me.Source, WorkItemStoreFlags.None);
     sourceTestStore = new TestManagementContext(me.Source);
     targetWitStore  = new WorkItemStoreContext(me.Target, WorkItemStoreFlags.BypassRules);
     targetTestStore = new TestManagementContext(me.Target);
 }
Beispiel #2
0
 public TestPlansAndSuitsMigrationContext(MigrationEngine me, TestPlansAndSuitsMigrationConfig config) : base(me, config)
 {
     this.engine       = me;
     sourceWitStore    = new WorkItemStoreContext(me.Source, WorkItemStoreFlags.None);
     sourceTestStore   = new TestManagementContext(me.Source);
     targetWitStore    = new WorkItemStoreContext(me.Target, WorkItemStoreFlags.BypassRules);
     targetTestStore   = new TestManagementContext(me.Target);
     targetTestConfigs = targetTestStore.Project.TestConfigurations.Query("Select * From TestConfiguration");
     this.config       = config;
 }
 public TestPlandsAndSuitesMigrationContext(MigrationEngine me, TestPlansAndSuitesMigrationConfig config) : base(me, config)
 {
     this.engine       = me;
     sourceWitStore    = new WorkItemStoreContext(me.Source, WorkItemStoreFlags.None);
     sourceTestStore   = new TestManagementContext(me.Source, config.TestPlanQueryBit);
     targetWitStore    = new WorkItemStoreContext(me.Target, WorkItemStoreFlags.BypassRules);
     targetTestStore   = new TestManagementContext(me.Target);
     sourceTestConfigs = sourceTestStore.Project.TestConfigurations.Query("Select * From TestConfiguration");
     targetTestConfigs = targetTestStore.Project.TestConfigurations.Query("Select * From TestConfiguration");
     sourceIdentityManagementService = me.Source.Collection.GetService <IIdentityManagementService>();
     targetIdentityManagementService = me.Target.Collection.GetService <IIdentityManagementService>();
     this.config = config;
 }
Beispiel #4
0
        // http://blogs.microsoft.co.il/shair/2015/02/02/tfs-api-part-56-test-configurations/
        protected override void InternalExecute()
        {
            TestManagementContext SourceTmc  = new TestManagementContext(Engine.Source);
            TestManagementContext targetTmc  = new TestManagementContext(Engine.Target);
            List <ITestVariable>  sourceVars = SourceTmc.Project.TestVariables.Query().ToList();

            Log.LogInformation("Plan to copy {0} Veriables?", sourceVars.Count);

            foreach (var sourceVar in sourceVars)
            {
                Log.LogInformation("Copy: {0}", sourceVar.Name);
                ITestVariable targetVar = GetVar(targetTmc.Project.TestVariables, sourceVar.Name);
                bool          isDirty   = false;
                if (targetVar == null)
                {
                    Log.LogInformation("    Need to create: {0}", sourceVar.Name);
                    targetVar      = targetTmc.Project.TestVariables.Create();
                    targetVar.Name = sourceVar.Name;
                    isDirty        = true;
                }
                else
                {
                    Log.LogInformation("    Exists: {0}", sourceVar.Name);
                }
                // match values
                foreach (var sourceVal in sourceVar.AllowedValues)
                {
                    Log.LogInformation("    Seeking: {0}", sourceVal.Value);
                    ITestVariableValue targetVal = GetVal(targetVar, sourceVal.Value);
                    if (targetVal == null)
                    {
                        Log.LogInformation("    Need to create: {0}", sourceVal.Value);
                        targetVal = targetTmc.Project.TestVariables.CreateVariableValue(sourceVal.Value);
                        targetVar.AllowedValues.Add(targetVal);
                        isDirty = true;
                    }
                    else
                    {
                        Log.LogInformation("    Exists: {0}", targetVal.Value);
                    }
                }
                if (isDirty)
                {
                    targetVar.Save();
                }
            }
        }
 private void ValidateAndFixTestSuiteQuery(ITestSuiteBase source, IDynamicTestSuite targetSuiteChild,
                                           TestManagementContext targetTestStore)
 {
     try
     {
         // Verifying that the query is valid
         targetSuiteChild.Query.Execute();
     }
     catch (Exception e)
     {
         FixIterationNotFound(e, source, targetSuiteChild, targetTestStore);
     }
     finally
     {
         targetSuiteChild.Repopulate();
     }
 }
Beispiel #6
0
        internal override void InternalExecute()
        {
            WorkItemStoreContext  sourceWisc = new WorkItemStoreContext(me.Source, WorkItemStoreFlags.None);
            TestManagementContext SourceTmc  = new TestManagementContext(me.Source);

            WorkItemStoreContext  targetWisc = new WorkItemStoreContext(me.Target, WorkItemStoreFlags.BypassRules);
            TestManagementContext targetTmc  = new TestManagementContext(me.Target);

            List <ITestVariable> sourceVars = SourceTmc.Project.TestVariables.Query().ToList();

            Trace.WriteLine(string.Format("Plan to copy {0} Veriables?", sourceVars.Count));

            foreach (var sourceVar in sourceVars)
            {
                Trace.WriteLine(string.Format("Copy: {0}", sourceVar.Name));
                ITestVariable targetVar = GetVar(targetTmc.Project.TestVariables, sourceVar.Name);
                if (targetVar == null)
                {
                    Trace.WriteLine(string.Format("    Need to create: {0}", sourceVar.Name));
                    targetVar      = targetTmc.Project.TestVariables.Create();
                    targetVar.Name = sourceVar.Name;
                    targetVar.Save();
                }
                else
                {
                    Trace.WriteLine(string.Format("    Exists: {0}", sourceVar.Name));
                }
                // match values
                foreach (var sourceVal in sourceVar.AllowedValues)
                {
                    Trace.WriteLine(string.Format("    Seeking: {0}", sourceVal.Value));
                    ITestVariableValue targetVal = GetVal(targetVar, sourceVal.Value);
                    if (targetVal == null)
                    {
                        Trace.WriteLine(string.Format("    Need to create: {0}", sourceVal.Value));
                        targetVal = targetTmc.Project.TestVariables.CreateVariableValue(sourceVal.Value);
                        targetVar.AllowedValues.Add(targetVal);
                        targetVar.Save();
                    }
                    else
                    {
                        Trace.WriteLine(string.Format("    Exists: {0}", targetVal.Value));
                    }
                }
            }
        }
Beispiel #7
0
        internal override void InternalExecute()
        {
            WorkItemStoreContext  sourceWisc = new WorkItemStoreContext(me.Source, WorkItemStoreFlags.None);
            TestManagementContext SourceTmc  = new TestManagementContext(me.Source);

            WorkItemStoreContext  targetWisc = new WorkItemStoreContext(me.Target, WorkItemStoreFlags.BypassRules);
            TestManagementContext targetTmc  = new TestManagementContext(me.Target);


            ITestConfigurationCollection tc = SourceTmc.Project.TestConfigurations.Query("Select * From TestConfiguration");

            Trace.WriteLine(string.Format("Plan to copy {0} Configurations?", tc.Count));

            foreach (var sourceTestConf in tc)
            {
                Trace.WriteLine("Copy Configuration {0} - ", sourceTestConf.Name);
                ITestConfiguration targetTc = GetCon(targetTmc.Project.TestConfigurations, sourceTestConf.Name);
                if (targetTc != null)
                {
                    Trace.WriteLine("    Found {0} - ", sourceTestConf.Name);
                    // Move on
                }
                else
                {
                    Trace.WriteLine("    Create new {0} - ", sourceTestConf.Name);
                    targetTc             = targetTmc.Project.TestConfigurations.Create();
                    targetTc.AreaPath    = sourceTestConf.AreaPath.Replace(me.Source.Name, me.Target.Name);
                    targetTc.Description = sourceTestConf.Description;
                    targetTc.IsDefault   = sourceTestConf.IsDefault;
                    targetTc.Name        = sourceTestConf.Name;
                    foreach (var val in targetTc.Values)
                    {
                        if (!targetTc.Values.ContainsKey(val.Key))
                        {
                            targetTc.Values.Add(val);
                        }
                    }
                    targetTc.State = sourceTestConf.State;
                    targetTc.Save();
                    Trace.WriteLine(string.Format("    Saved {0} - ", targetTc.Name));
                }
            }
        }
Beispiel #8
0
        internal override void InternalExecute()
        {
            TestManagementContext SourceTmc = new TestManagementContext(me.Source);
            TestManagementContext targetTmc = new TestManagementContext(me.Target);

            ITestConfigurationCollection tc = SourceTmc.Project.TestConfigurations.Query("Select * From TestConfiguration");

            Trace.WriteLine($"Plan to copy {tc.Count} Configurations", Name);

            foreach (var sourceTestConf in tc)
            {
                Trace.WriteLine($"{sourceTestConf.Name} - Copy Configuration", Name);
                ITestConfiguration targetTc = GetCon(targetTmc.Project.TestConfigurations, sourceTestConf.Name);
                if (targetTc != null)
                {
                    Trace.WriteLine($"{sourceTestConf.Name} - Found", Name);
                    // Move on
                }
                else
                {
                    Trace.WriteLine($"{sourceTestConf.Name} - Create new", Name);
                    targetTc             = targetTmc.Project.TestConfigurations.Create();
                    targetTc.AreaPath    = sourceTestConf.AreaPath.Replace(me.Source.Config.Project, me.Target.Config.Project);
                    targetTc.Description = sourceTestConf.Description;
                    targetTc.IsDefault   = sourceTestConf.IsDefault;
                    targetTc.Name        = sourceTestConf.Name;

                    foreach (var val in sourceTestConf.Values)
                    {
                        if (!targetTc.Values.ContainsKey(val.Key))
                        {
                            targetTc.Values.Add(val);
                        }
                    }

                    targetTc.State = sourceTestConf.State;
                    targetTc.Save();
                    Trace.WriteLine($"{sourceTestConf.Name} - Saved as {targetTc.Name}", Name);
                }
            }
        }
        private void FixQueryForTeamProjectNameChange(ITestSuiteBase source, IDynamicTestSuite targetSuitChild,
                                                      TestManagementContext targetTestStore)
        {
            // Replacing old projectname in queries with new projectname
            // The target team project name is only available via target test store because the dyn. testsuite isnt saved at this point in time
            if (!source.Plan.Project.TeamProjectName.Equals(targetTestStore.Project.TeamProjectName))
            {
                Trace.WriteLine(string.Format(
                                    @"Team Project names dont match. We need to fix the query in dynamic test suite {0} - {1}.", source.Id,
                                    source.Title));
                Trace.WriteLine(string.Format(@"Replacing old project name {1} in query {0} with new team project name {2}",
                                              targetSuitChild.Query.QueryText,
                                              source.Plan.Project.TeamProjectName,
                                              targetTestStore.Project.TeamProjectName
                                              ));

                // it is possible that user has used project name in query values. we try only to change iteration + area path values
                // A child level is selected in area / iteration path
                targetSuitChild.Query = targetSuitChild.Project.CreateTestQuery(
                    targetSuitChild.Query.QueryText.Replace(
                        string.Format(@"'{0}\", source.Plan.Project.TeamProjectName),
                        string.Format(@"'{0}\", targetTestStore.Project.TeamProjectName)
                        ));

                // Only root level is selected in area / iteration path
                targetSuitChild.Query = targetSuitChild.Project.CreateTestQuery(
                    targetSuitChild.Query.QueryText.Replace(
                        string.Format(@"'{0}'", source.Plan.Project.TeamProjectName),
                        string.Format(@"'{0}'", targetTestStore.Project.TeamProjectName)
                        ));

                ValidateAndFixTestSuiteQuery(source, targetSuitChild, targetTestStore);

                targetSuitChild.Repopulate();
                Trace.WriteLine(string.Format("New query is now {0}", targetSuitChild.Query.QueryText));
            }
        }
Beispiel #10
0
 private ITestPlan FindTestPlan(TestManagementContext tmc, string name)
 {
     return((from p in tmc.Project.TestPlans.Query("Select * From TestPlan") where p.Name == name select p).SingleOrDefault());
 }
        private void FixIterationNotFound(Exception exception, ITestSuiteBase source, IDynamicTestSuite targetSuiteChild, TestManagementContext targetTestStore)
        {
            if (exception.Message.Contains("The specified iteration path does not exist."))
            {
                Regex regEx = new Regex(@"'(.*?)'");

                var missingIterationPath = regEx.Match(exception.Message).Groups[0].Value;
                missingIterationPath = missingIterationPath.Substring(missingIterationPath.IndexOf(@"\") + 1, missingIterationPath.Length - missingIterationPath.IndexOf(@"\") - 2);

                Trace.WriteLine("Found a orphaned iteration path in test suite query.");
                Trace.WriteLine(string.Format("Invalid iteration path {0}:", missingIterationPath));
                Trace.WriteLine("Replacing the orphaned iteration path from query with root iteration path. Please fix the query after the migration.");

                targetSuiteChild.Query = targetSuiteChild.Project.CreateTestQuery(
                    targetSuiteChild.Query.QueryText.Replace(
                        string.Format(@"'{0}\{1}'", source.Plan.Project.TeamProjectName, missingIterationPath),
                        string.Format(@"'{0}'", targetTestStore.Project.TeamProjectName)
                        ));

                targetSuiteChild.Query = targetSuiteChild.Project.CreateTestQuery(
                    targetSuiteChild.Query.QueryText.Replace(
                        string.Format(@"'{0}\{1}'", targetTestStore.Project.TeamProjectName, missingIterationPath),
                        string.Format(@"'{0}'", targetTestStore.Project.TeamProjectName)
                        ));
            }
        }
 private void FixQueryForTeamProjectNameChange(ITestSuiteBase source, IDynamicTestSuite targetSuiteChild, TestManagementContext targetTestStore)
 {
     // Replacing old projectname in queries with new projectname
     // The target team project name is only available via target test store because the dyn. testsuite isnt saved at this point in time
     if (!source.Plan.Project.TeamProjectName.Equals(targetTestStore.Project.TeamProjectName))
     {
         Trace.WriteLine(string.Format(@"Team Project names dont match. We need to fix the query in dynamic test suite {0} - {1}.", source.Id, source.Title));
         Trace.WriteLine(string.Format(@"Replacing old project name {1} in query {0} with new team project name {2}", targetSuiteChild.Query.QueryText, source.Plan.Project.TeamProjectName, targetTestStore.Project.TeamProjectName));
         // First need to check is prefix project nodes has been applied for the migration
         if (config.PrefixProjectToNodes)
         {
             // if prefix project nodes has been applied we need to take the original area/iteration value and prefix
             targetSuiteChild.Query =
                 targetSuiteChild.Project.CreateTestQuery(targetSuiteChild.Query.QueryText.Replace(
                                                              string.Format(@"'{0}", source.Plan.Project.TeamProjectName),
                                                              string.Format(@"'{0}\{1}", targetTestStore.Project.TeamProjectName, source.Plan.Project.TeamProjectName)));
         }
         else
         {
             // If we are not profixing project nodes then we just need to take the old value for the project and replace it with the new project value
             targetSuiteChild.Query = targetSuiteChild.Project.CreateTestQuery(targetSuiteChild.Query.QueryText.Replace(
                                                                                   string.Format(@"'{0}", source.Plan.Project.TeamProjectName),
                                                                                   string.Format(@"'{0}", targetTestStore.Project.TeamProjectName)));
         }
         Trace.WriteLine(string.Format("New query is now {0}", targetSuiteChild.Query.QueryText));
     }
 }
        private void ApplyTestSuiteQuery(ITestSuiteBase source, IDynamicTestSuite targetSuiteChild, TestManagementContext targetTestStore)
        {
            targetSuiteChild.Query = ((IDynamicTestSuite)source).Query;

            // Postprocessing common errors
            FixQueryForTeamProjectNameChange(source, targetSuiteChild, targetTestStore);
            FixWorkItemIdInQuery(targetSuiteChild);
        }