// 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(); } } }
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)); } } } }