Exemplo n.º 1
0
        public static MigrationTestEnvironment CreateMigrationTestEnvironment(string testName)
        {
            MigrationTestEnvironment env = null;

            string fileName = Environment.GetEnvironmentVariable(cTestEnvironment);

            if (String.IsNullOrEmpty(fileName))
            {
                fileName = cTestEnvironmentFile;
            }

            try
            {
                Trace.TraceInformation("Deserializing {0}", Path.GetFullPath(fileName));
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(MigrationTestEnvironment));
                    env = serializer.Deserialize(fs) as MigrationTestEnvironment;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Failed to load {0}", fileName);
                throw ex;
            }

            if (env != null)
            {
                env.TestName = testName;
            }

            return(env);
        }
Exemplo n.º 2
0
        public static MigrationTestEnvironment CreateMigrationTestEnvironment(string testName, string configFileName)
        {
            MigrationTestEnvironment env = null;

            try
            {
                using (FileStream fs = new FileStream(configFileName, FileMode.Open, FileAccess.Read))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(MigrationTestEnvironment));
                    env = serializer.Deserialize(fs) as MigrationTestEnvironment;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Failed to load {0}", configFileName);
                throw ex;
            }

            if (env != null)
            {
                env.TestName = testName;
            }

            return(env);
        }
Exemplo n.º 3
0
        public static MigrationTestEnvironment Load(string testName, string fileName)
        {
            MigrationTestEnvironment env = null;

            if (String.IsNullOrEmpty(fileName))
            {
                fileName = DefaultEnvironmentFileName;
            }

            try
            {
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(MigrationTestEnvironment));
                    env = serializer.Deserialize(fs) as MigrationTestEnvironment;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Failed to load {0}", fileName);
                throw ex;
            }

            if (env != null)
            {
                env.TestName = testName;
            }

            return(env);
        }
Exemplo n.º 4
0
        public virtual void Initialize()
        {
            Configuration = null;
            TestStartTime = DateTime.Now;

            if (String.IsNullOrEmpty(TestName))
            {
                // this is a MSTest test
                TestName = TestContext.TestName;
                Microsoft.TeamFoundation.Migration.Toolkit.Constants.PluginsFolderName = ".";
            }

            TestEnvironment = MigrationTestEnvironment.Load(TestName);
            TestEnvironment.Initialize(TestProjectName);

            DirectoryInfo[] directories = new DirectoryInfo[]
            {
                new DirectoryInfo(Microsoft.TeamFoundation.Migration.Toolkit.Constants.PluginsFolderName),
                new DirectoryInfo("."),
            };

            m_adapterManager = new AdapterManager(directories);

            TestEnvironment.LeftEndPoint.TestName  = TestName;
            TestEnvironment.RightEndPoint.TestName = TestName;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Encapsulates all the paths for one item (file or folder) in a migration
 /// </summary>
 /// <param name="itemName">The Desired itemName</param>
 /// <param name="newItemName">Item name after a namespace change (rename, branch)</param>
 /// <param name="env">MigrationTestEnvironment object</param>
 /// <param name="useSource">Determines if the paths should be based on the source of the mapping(tfs2tfs) or the target(wss2tfs)</param>
 public MigrationItemStrings(string itemName, string newItemName, MigrationTestEnvironment env, bool useSource)
 {
     if (useSource)
     {
         setStrings(itemName, newItemName, env.TestName, env.FirstSourceServerPath, env.SourceWorkspaceLocalPath);
     }
     else
     {
         setStrings(itemName, newItemName, env.TestName, env.FirstTargetServerPath, env.TargetWorkspaceLocalPath);
     }
 }
Exemplo n.º 6
0
        public static void CustomActions_DisableBypassRulesOnTarget(MigrationTestEnvironment env, Configuration config)
        {
            var enableBypassRule = new CustomSetting();

            enableBypassRule.SettingKey   = "EnableBypassRuleDataSubmission";
            enableBypassRule.SettingValue = "false";

            MigrationSource target = env.GetTargetMigrationSource(config);

            target.CustomSettings.CustomSetting.Add(enableBypassRule);
        }
Exemplo n.º 7
0
        public static void CustomActions_DisableCSSNodeCreationOnTarget(MigrationTestEnvironment env, Configuration config)
        {
            var disableAreaPathCreation = new CustomSetting();

            disableAreaPathCreation.SettingKey = "DisableAreaPathAutoCreation";
            //disableAreaPathCreation.SettingValue = string.Empty;

            var disableIterationPathCreation = new CustomSetting();

            disableIterationPathCreation.SettingKey = "DisableIterationPathAutoCreation";
            //disableIterationPathCreation.SettingValue = string.Empty;

            MigrationSource target = env.GetTargetMigrationSource(config);

            target.CustomSettings.CustomSetting.Add(disableAreaPathCreation);
            target.CustomSettings.CustomSetting.Add(disableIterationPathCreation);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Encapsulates all the paths for one item (file or folder) in a (WSS2TFS) migration
 /// </summary>
 /// <param name="itemName">The Desired itemName</param>
 /// <param name="newItemName">Item name after a namespace change (rename, branch)</param>
 /// <param name="env">MigrationTestEnvironment object</param>
 /// <param name="useSource">Determines if the paths should be based on the source of the mapping(tfs2tfs) or that target(wss2tfs)</param>
 public MigrationItemStrings(string itemName, string newItemName, MigrationTestEnvironment env)
     : this(itemName, newItemName, env, false)
 {
 }
Exemplo n.º 9
0
        public static Configuration CreateConfiguration(string defaultConfigFile, MigrationTestEnvironment env)
        {
            string configFile = env.ConfigurationFile;

            if (String.IsNullOrEmpty(configFile))
            {
                configFile = defaultConfigFile;
            }

            Configuration config = CreateConfiguration(configFile);

            if (config == null)
            {
                return(null);
            }

            // Configuration Attributes
            config.UniqueId = Guid.NewGuid().ToString();
            if (env.TestName.Length > 35)
            {
                // note: in DB, SessionGroupConfig.FriendlyName is only 40-char long
                config.FriendlyName = env.TestName.Substring(0, 35);
            }
            else
            {
                config.FriendlyName = env.TestName;
            }
            config.SessionGroup.WorkFlowType = env.WorkFlowType;

            // TODO:
            // for now handle first two migration sources for now.
            // for now handle first two sessions and filter items
            Debug.Assert(config.SessionGroup.Sessions.Session.Count == 1);

            // MigrationSources
            var sources = config.SessionGroup.MigrationSources.MigrationSource;

            sources[0].ServerUrl             = env.LeftEndPoint.ServerUrl;
            sources[0].FriendlyName          = env.LeftEndPoint.FriendlyName;
            sources[0].ServerIdentifier      = env.LeftEndPoint.FriendlyName;
            sources[0].SourceIdentifier      = env.LeftEndPoint.TeamProject;
            sources[0].ProviderReferenceName = env.LeftEndPoint.AdapterID.ToString();
            sources[0].InternalUniqueId      = env.LeftEndPoint.InternalUniqueID.ToString();

            Trace.TraceInformation("Left Custom Setting has {0} entries", env.LeftEndPoint.CustomSettingsList.Count);
            foreach (Setting s in env.LeftEndPoint.CustomSettingsList)
            {
                CustomSetting customSetting = new CustomSetting()
                {
                    SettingKey   = s.Key,
                    SettingValue = s.Value,
                };

                sources[0].CustomSettings.CustomSetting.Add(customSetting);
                Trace.TraceInformation("Added Left Test CustomSetting Key={0} Value={1}", customSetting.SettingKey, customSetting.SettingValue);
            }

            sources[1].ServerUrl             = env.RightEndPoint.ServerUrl;
            sources[1].FriendlyName          = env.RightEndPoint.FriendlyName;
            sources[1].ServerIdentifier      = env.RightEndPoint.FriendlyName;
            sources[1].SourceIdentifier      = env.RightEndPoint.TeamProject;
            sources[1].ProviderReferenceName = env.RightEndPoint.AdapterID.ToString();
            sources[1].InternalUniqueId      = env.RightEndPoint.InternalUniqueID.ToString();

            Trace.TraceInformation("Right Custom Setting has {0} entries", env.RightEndPoint.CustomSettingsList.Count);
            foreach (Setting s in env.RightEndPoint.CustomSettingsList)
            {
                CustomSetting customSetting = new CustomSetting()
                {
                    SettingKey   = s.Key,
                    SettingValue = s.Value,
                };

                sources[1].CustomSettings.CustomSetting.Add(customSetting);
                Trace.TraceInformation("Added Right Test CustomSetting Key={0} Value={1}", customSetting.SettingKey, customSetting.SettingValue);
            }

            // Generate unique Guids for sessions
            config.SessionGroup.SessionGroupGUID = Guid.NewGuid().ToString();
            SessionsElement sessions = config.SessionGroup.Sessions;

            foreach (var session in sessions.Session)
            {
                session.SessionUniqueId              = Guid.NewGuid().ToString();
                session.LeftMigrationSourceUniqueId  = sources[0].InternalUniqueId;
                session.RightMigrationSourceUniqueId = sources[1].InternalUniqueId;
            }

            // Build mappings at run time based on env.Mappings
            Debug.Assert(sessions.Session[0].Filters.FilterPair.Count == 0,
                         "MigrationTestEnvironment template should not contain filter items. These will be ignored");

            // Ignore any existing mappings in the template file
            sessions.Session[0].Filters.FilterPair.Clear();
            foreach (MappingPair pair in env.Mappings)
            {
                FilterItem source = new FilterItem();
                FilterItem target = new FilterItem();
                source.FilterString = pair.SourcePath;
                target.FilterString = pair.TargetPath;
                if (!string.IsNullOrEmpty(pair.SourceSnapshotStartPoint))
                {
                    source.SnapshotStartPoint = pair.SourceSnapshotStartPoint;
                }
                if (!string.IsNullOrEmpty(pair.TargetSnapshotStartPoint))
                {
                    target.SnapshotStartPoint = pair.TargetSnapshotStartPoint;
                }
                if (!string.IsNullOrEmpty(pair.SourcePeerSnapshotStartPoint))
                {
                    source.PeerSnapshotStartPoint = pair.SourcePeerSnapshotStartPoint;
                }
                if (!string.IsNullOrEmpty(pair.TargetPeerSnapshotStartPoint))
                {
                    target.PeerSnapshotStartPoint = pair.TargetPeerSnapshotStartPoint;
                }
                if (!string.IsNullOrEmpty(pair.SourceMergeScope))
                {
                    source.MergeScope = pair.SourceMergeScope;
                }
                if (!string.IsNullOrEmpty(pair.TargetMergeScope))
                {
                    target.MergeScope = pair.TargetMergeScope;
                }

                if (env.MigrationTestType == MigrationTestType.TwoWayRight)
                {
                    source.MigrationSourceUniqueId = sources[1].InternalUniqueId;
                    target.MigrationSourceUniqueId = sources[0].InternalUniqueId;
                }
                else
                {
                    source.MigrationSourceUniqueId = sources[0].InternalUniqueId;
                    target.MigrationSourceUniqueId = sources[1].InternalUniqueId;
                }

                FilterPair mapping = new FilterPair();
                mapping.Neglect = pair.Cloak;
                mapping.FilterItem.Add(source);
                mapping.FilterItem.Add(target);

                Trace.TraceInformation("Adding Filter Pair {0} {1} -> {2}", mapping.Neglect, source, target);
                sessions.Session[0].Filters.FilterPair.Add(mapping);
            }

            // Snapshot configuration
            foreach (KeyValuePair <string, string> snapshotStartPoint in env.SnapshotStartPoints)
            {
                XmlDocument ownerDocument = sessions.Session[0].CustomSettings.SettingXml.Any[0].OwnerDocument;

                // Set the batch size
                if (env.SnapshotBatchSize != 0)
                {
                    XmlNode      snapshotBatchSizeNode = ownerDocument.CreateNode(XmlNodeType.Element, "Setting", "");
                    XmlAttribute snapshotBatchSizeName = ownerDocument.CreateAttribute("SettingKey");
                    snapshotBatchSizeName.Value = "SnapshotBatchSize";
                    XmlAttribute snapshotBatchSizeValue = ownerDocument.CreateAttribute("SettingValue");
                    snapshotBatchSizeValue.Value = env.SnapshotBatchSize.ToString();
                    snapshotBatchSizeNode.Attributes.Append(snapshotBatchSizeName);
                    snapshotBatchSizeNode.Attributes.Append(snapshotBatchSizeValue);
                    sessions.Session[0].CustomSettings.SettingXml.Any[0].ChildNodes[0].AppendChild(snapshotBatchSizeNode);
                }

                XmlNode      snapshotSettingNode = ownerDocument.CreateNode(XmlNodeType.Element, "Setting", "");
                XmlAttribute snapshotName        = ownerDocument.CreateAttribute("SettingKey");
                snapshotName.Value = "SnapshotStartPoint";
                XmlAttribute snapshotValue = ownerDocument.CreateAttribute("SettingValue");

                if (string.Equals(snapshotStartPoint.Key, sources[0].SourceIdentifier))
                {
                    snapshotValue.Value = sources[0].InternalUniqueId.ToString() + ';' + snapshotStartPoint.Value;
                    snapshotSettingNode.Attributes.Append(snapshotName);
                    snapshotSettingNode.Attributes.Append(snapshotValue);
                    sessions.Session[0].CustomSettings.SettingXml.Any[0].ChildNodes[0].AppendChild(snapshotSettingNode);
                }
                else if (string.Equals(snapshotStartPoint.Key, sources[1].SourceIdentifier))
                {
                    snapshotValue.Value = sources[1].InternalUniqueId.ToString() + ';' + snapshotStartPoint.Value;
                    snapshotSettingNode.Attributes.Append(snapshotName);
                    snapshotSettingNode.Attributes.Append(snapshotValue);
                    sessions.Session[0].CustomSettings.SettingXml.Any[0].ChildNodes[0].AppendChild(snapshotSettingNode);
                }
            }

            // additional configuration customization
            env.CustomizeConfiguration(config);

            Trace.TraceInformation("WorkFlow: {0}, {1}, {2}",
                                   config.SessionGroup.WorkFlowType.DirectionOfFlow,
                                   config.SessionGroup.WorkFlowType.Frequency,
                                   config.SessionGroup.WorkFlowType.SyncContext);

            return(config);
        }
Exemplo n.º 10
0
 public static void CustomActions_DisableContextSync(MigrationTestEnvironment env, Configuration config)
 {
     config.SessionGroup.WorkFlowType.SyncContext = SyncContext.Disabled;
 }
Exemplo n.º 11
0
 public static MigrationTestEnvironment Load(string testName)
 {
     return(MigrationTestEnvironment.Load(testName, Environment.GetEnvironmentVariable(DefaultTestEnvironmentVariableName)));
 }