Beispiel #1
0
        public void StartsWithMappingsTest()
        {
            MigrationItemStrings fileOutSideMapping = new MigrationItemStrings("source-integration/file.txt", null, TestEnvironment, true);
            MigrationItemStrings fileUnderMapping   = new MigrationItemStrings("source/file.txt", null, TestEnvironment, true);

            TestUtils.CreateRandomFile(fileOutSideMapping.LocalPath, 10);
            TestUtils.CreateRandomFile(fileUnderMapping.LocalPath, 10);

            string mergeComment = "Migration test merge";

            SourceWorkspace.PendAdd(fileOutSideMapping.LocalPath);
            SourceWorkspace.PendAdd(fileUnderMapping.LocalPath);

            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), mergeComment);

            MappingPair mapping = new MappingPair(TestEnvironment.FirstSourceServerPath + SrcPathSeparator + "source",
                                                  TestEnvironment.FirstTargetServerPath + TarPathSeparator + "source",
                                                  false);
            MappingPair mapping2 = new MappingPair(TestEnvironment.FirstSourceServerPath + SrcPathSeparator + "source-integration",
                                                   TestEnvironment.FirstTargetServerPath + TarPathSeparator + "source-integration",
                                                   false);

            TestEnvironment.Mappings.Clear();

            TestEnvironment.AddMapping(mapping);
            TestEnvironment.AddMapping(mapping2);
            RunAndValidate();
        }
Beispiel #2
0
        private bool Refresh()
        {
            //motherkeys = this.Mother.Generate(Mother.CurrentETLTools.Take(Mother.CurrentETLTools.IndexOf(this.ETLModule)), false).Take(3).GetKeys().ToList();
            //     subkeys =
            //        SubTask.Generate(
            //            SubTask.CurrentETLTools.Take(RangeStart),false)
            //            .Take(3).GetKeys().ToList();
            var dict =
                MappingPairs.Where(
                    d =>
                    string.IsNullOrEmpty(d.Target.SelectItem) == false &&
                    string.IsNullOrEmpty(d.Source.SelectItem) == false).Distinct().GroupBy(d => d.Target.SelectItem).Select(group => group.First())
                .ToDictionary(d => d.Target.SelectItem, d => d.Source.SelectItem);

            ControlExtended.UIInvoke(() =>
            {
                MappingPairs.Clear();
                foreach (var key in subkeys)
                {
                    var pair = new MappingPair(motherkeys, subkeys);
                    pair.Target.SelectItem = key;
                    string value           = key;
                    dict.TryGetValue(key, out value);
                    pair.Source.SelectItem = value;
                    MappingPairs.Add(pair);
                }
            });
            return(true);

            //var index = Mother.CurrentETLTools.IndexOf(ETLModule);
            //if (index == -1)
            //    return;
            //Mother.Generate(Mother.CurrentETLTools.Take(index), false);
        }
        public void Map(MappingPair mappingPair)
        {
            var src  = mappingPair.Src as IMappingEnumerableObject;
            var dest = mappingPair.Dest as IMappingEnumerableObject;

            while (src.Next())
            {
                dest.New();

                var currentDestMappingObjectType = MapperConfiguration.MappingObjects.Get(dest.Current);
                var currentDest = MapperConfiguration.ObjectFactory.CreateInstance(currentDestMappingObjectType) as IMappingSingleObject;
                currentDest.UnderlyingObject = dest.Current;

                var currentSrcMappingObjectType = MapperConfiguration.MappingObjects.Get(src.Current);
                var currentSrc = MapperConfiguration.ObjectFactory.CreateInstance(currentSrcMappingObjectType) as IMappingSingleObject;
                currentSrc.UnderlyingObject = src.Current;

                var pair         = new MappingPair(currentSrc, currentDest);
                var strategyType = MapperConfiguration.MappingStrategies.Get(pair);
                var strategy     = MapperConfiguration.ObjectFactory.CreateInstance(strategyType) as IMappingStrategy;
                strategy.MapperConfiguration = MapperConfiguration;
                strategy.PropsMatcher        = PropsMatcher;
                strategy.PropValueConverter  = PropValueConverter;
                strategy.Map(pair);
            }
        }
Beispiel #4
0
        public static bool CanMap(MappingPair mappingPair)
        {
            var dataTable = mappingPair.Src.UnderlyingObject as DataTable;

            if (dataTable != null)
            {
                if (dataTable.Namespace.Contains("http://schemas.microsoft.com/office/project/server"))
                {
                    return(true);
                }

                return(false);
            }

            var dataRow = mappingPair.Src.UnderlyingObject as DataRow;

            if (dataRow != null)
            {
                if (dataRow.Table.Namespace.Contains("http://schemas.microsoft.com/office/project/server"))
                {
                    return(true);
                }

                return(false);
            }

            return(false);
        }
Beispiel #5
0
        public void RenameWithSourceNotMappedTest()
        {
            MigrationItemStrings folder = new MigrationItemStrings("rename-from", "rename-to", TestEnvironment, true);
            MigrationItemStrings file   = new MigrationItemStrings("rename-from/fld/file.txt", "rename-to/fld/file.txt", TestEnvironment, true);

            // Add the child item
            SourceAdapter.AddFile(file.LocalPath);

            MappingPair mapping = new MappingPair(TestEnvironment.FirstSourceServerPath + SrcPathSeparator + "rename-from",
                                                  TestEnvironment.FirstTargetServerPath + TarPathSeparator + "rename-from",
                                                  true); // cloaked

            TestEnvironment.AddMapping(mapping);

            SourceWorkspace.Get(VersionSpec.Latest, GetOptions.Overwrite);
            SourceWorkspace.PendRename(folder.ServerPath, folder.NewServerPath);

            SourceAdapter.EditFile(file.NewLocalPath);

            Run();
            VerifyHistory(3, 0);

            // Resolve "Branch source path not found conflict" using "$/" scope.
            ConflictResolver  conflictManager = new ConflictResolver(Configuration);
            List <RTConflict> conflicts       = conflictManager.GetConflicts();

            Assert.AreEqual(1, conflicts.Count, "There should be only 1 conflict");
            conflictManager.TryResolveConflict(conflicts[0], new VCChangeToAddOnBranchSourceNotMappedAction(), "$/"); // Add on branch source not found

            RunAndValidate(true, true);
        }
        public static bool CanMap(MappingPair mappingPair)
        {
            if (!mappingPair.Dest.CanContainWhitespacesInProperties)
            {
                return(true);
            }

            return(false);
        }
Beispiel #7
0
        public void PathSnapshotTest()
        {
            MigrationItemStrings branch = new MigrationItemStrings("source/", "target/", TestEnvironment, true);

            MigrationItemStrings[] addFiles = new MigrationItemStrings[20];

            // Add files
            // Create a tree structure so that we can test path compression logic.
            int sessionSnapshotChangesetId = 0;

            for (int i = 0; i < 20; i++)
            {
                addFiles[i] = new MigrationItemStrings(string.Format("source/path1/addFile{0}.txt", i), null, TestEnvironment, true);
                if (i == 15)
                {
                    sessionSnapshotChangesetId = SourceAdapter.AddFile(addFiles[i].LocalPath);
                }
                else
                {
                    SourceAdapter.AddFile(addFiles[i].LocalPath);
                }
            }

            int path2SnapshotChangesetId = 0;

            for (int i = 0; i < 20; i++)
            {
                addFiles[i] = new MigrationItemStrings(string.Format("source/path2/addFile{0}.txt", i), null, TestEnvironment, true);
                if (i == 15)
                {
                    path2SnapshotChangesetId = SourceAdapter.AddFile(addFiles[i].LocalPath);
                }
                else
                {
                    SourceAdapter.AddFile(addFiles[i].LocalPath);
                }
            }
            TestEnvironment.SnapshotStartPoints = new Dictionary <string, string>();
            TestEnvironment.SnapshotStartPoints.Add(TestEnvironment.SourceTeamProject, sessionSnapshotChangesetId.ToString());
            TestEnvironment.SnapshotBatchSize = 3;

            // We need to map to the sub item level
            MappingPair rootMapping = TestEnvironment.Mappings[0];

            TestEnvironment.Mappings.Clear();
            TestEnvironment.Mappings.Add(new MappingPair(rootMapping.SourcePath + "/source/path1", rootMapping.TargetPath + "/source/path1", false));
            TestEnvironment.Mappings.Add(new MappingPair(rootMapping.SourcePath + "/source/path2", rootMapping.TargetPath + "/source/path2", false, path2SnapshotChangesetId.ToString(), null));

            Run();

            // ToDo, ideally, we should compare content at snapshot changeset and compare history after snapshot changeset.
            Assert.IsTrue(VerifyContents());
        }
Beispiel #8
0
        public void BasicCloakTest()
        {
            MigrationItemStrings cloakedFile = new MigrationItemStrings("cloak" + SourceAdapter.PathSeparator + "file.txt", null, TestEnvironment, true);

            SourceAdapter.AddFile(cloakedFile.LocalPath);

            MappingPair mapping = new MappingPair(TestEnvironment.FirstSourceServerPath + SrcPathSeparator + "cloak",
                                                  TestEnvironment.FirstTargetServerPath + TarPathSeparator + "cloak",
                                                  true); // cloaked

            TestEnvironment.AddMapping(mapping);

            SourceAdapter.EditFile(m_extraFile.LocalPath);
            SourceAdapter.EditFile(cloakedFile.LocalPath);

            RunAndValidate();
        }
Beispiel #9
0
        public void MigrateCloakedFolderItselfTest()
        {
            MigrationItemStrings cloakedFile = new MigrationItemStrings("cloak", "cloak", TestEnvironment, true);

            SourceAdapter.AddFolder(cloakedFile.LocalPath);

            MappingPair mapping = new MappingPair(TestEnvironment.FirstSourceServerPath + SrcPathSeparator + "cloak",
                                                  TestEnvironment.FirstTargetServerPath + TarPathSeparator + "cloak",
                                                  true); // cloaked

            TestEnvironment.AddMapping(mapping);

            SourceAdapter.EditFile(m_extraFile.LocalPath);

            Run();
            VerifyHistory(0, 0);
        }
Beispiel #10
0
        public void MergeCrudOutOfScopeTest()
        {
            MigrationItemStrings branch       = new MigrationItemStrings("source/", "target/", TestEnvironment, true);
            MigrationItemStrings addedFile    = new MigrationItemStrings("source/Addedfile.txt", null, TestEnvironment, true);
            MigrationItemStrings editFile     = new MigrationItemStrings("source/Editedfile.txt", null, TestEnvironment, true);
            MigrationItemStrings deleteFile   = new MigrationItemStrings("source/DeletedFile.txt", null, TestEnvironment, true);
            MigrationItemStrings undeleteFile = new MigrationItemStrings("source/UndeletedFile.txt", null, TestEnvironment, true);
            MigrationItemStrings branchedFile = new MigrationItemStrings("source/folder/branchedFile.txt", "source/folder2/branchFile.txt", TestEnvironment, true);
            MigrationItemStrings mergeFile    = new MigrationItemStrings("source/folder/mergeFile.txt", "source/folder2/mergeFile.txt", TestEnvironment, true);

            #region Setup before the branch
            //All the files except for the Added file should exist before the branch
            SourceAdapter.AddFile(editFile.LocalPath);
            SourceAdapter.AddFile(deleteFile.LocalPath);
            SourceAdapter.AddFile(undeleteFile.LocalPath);
            SourceAdapter.AddFile(branchedFile.LocalPath);
            SourceAdapter.AddFile(mergeFile.LocalPath);

            int deletetionChangeset = SourceAdapter.DeleteItem(undeleteFile.ServerPath);
            int mergeFileChangeset  = SourceAdapter.BranchItem(mergeFile.ServerPath, mergeFile.NewServerPath);
            SourceAdapter.EditFile(mergeFile.LocalPath);
            #endregion

            int branchChangeset = SourceAdapter.BranchItem(branch.ServerPath, branch.NewServerPath);

            #region Setup after Branch operation
            SourceAdapter.AddFile(addedFile.LocalPath);
            SourceAdapter.EditFile(editFile.LocalPath);
            SourceAdapter.DeleteItem(deleteFile.ServerPath);
            SourceAdapter.UndeleteFile(undeleteFile.ServerPath, deletetionChangeset);
            SourceAdapter.BranchItem(branchedFile.ServerPath, branchedFile.NewServerPath);
            SourceAdapter.MergeItem(mergeFile, mergeFileChangeset);
            #endregion Setup after Branch operation

            //The big merge
            SourceAdapter.MergeItem(branch, branchChangeset);

            // Add the mapping scope
            MappingPair rootMapping = TestEnvironment.Mappings[0];
            TestEnvironment.Mappings.Clear();
            TestEnvironment.Mappings.Add(new MappingPair(rootMapping.SourcePath, rootMapping.TargetPath, false, null, null,
                                                         rootMapping.SourcePath + '/' + "target/", rootMapping.TargetPath + '/' + "target/"));

            RunAndValidate(true, true);
        }
Beispiel #11
0
        public SubTaskModel(SmartETLTool mother, SmartETLTool subTask, ETLBase etlmodule, string[] mother_keys = null, string[] sub_keys = null)
        {
            MappingPairs =
                new ObservableCollection <MappingPair>();
            Mother  = mother;
            SubTask = subTask;
            var start = 0;
            var end   = 0;

            ETLBase.GetRange(etlmodule.ETLRange, subTask.AllETLMount, out start, out end);
            if (mother_keys != null)
            {
                motherkeys.AddRange(mother_keys);
            }
            if (sub_keys != null)
            {
                subkeys.AddRange(sub_keys);
            }
            RangeStart = start;
            RangeEnd   = end;
            ETLModule  = etlmodule;
            if (!string.IsNullOrEmpty(etlmodule.MappingSet))
            {
                foreach (var item in etlmodule.MappingSet.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var    kv    = item.Split(':');
                    string key   = "";
                    string value = "";
                    if (kv.Length == 1)
                    {
                        key = value = kv[1];
                    }
                    if (kv.Length > 1)
                    {
                        key   = kv[0];
                        value = kv[1];
                    }
                    var pair = new MappingPair(motherkeys, subkeys);
                    pair.Source._SelectItem = key;
                    pair.Target._SelectItem = value;
                    MappingPairs.Add(pair);
                }
            }
            // Refresh();
        }
        public static bool CanMap(MappingPair mappingPair)
        {
            var src = mappingPair.Src as IMappingEnumerableObject;

            if (src == null)
            {
                return(false);
            }

            var dest = mappingPair.Dest as IMappingEnumerableObject;

            if (dest == null)
            {
                return(false);
            }

            return(true);
        }
        public static bool CanMap(MappingPair mappingObjects)
        {
            var src = mappingObjects.Src as IMappingSingleObject;

            if (src == null)
            {
                return(false);
            }

            var dest = mappingObjects.Dest as IMappingSingleObject;

            if (dest == null)
            {
                return(false);
            }

            return(true);
        }
        public void Map(MappingPair mappingPair)
        {
            var src  = mappingPair.Src as IMappingSingleObject;
            var dest = mappingPair.Dest as IMappingSingleObject;

            var props = PropsMatcher.GetPropertiesMap(src.Properties, dest.Properties);

            foreach (var prop in props)
            {
                var propInfo = src.Properties.FirstOrDefault(p => p.Name == prop.Key);
                if (propInfo == null)
                {
                    continue;
                }

                var srcVal = PropValueConverter.GetConvertedValue(propInfo, null, src[prop.Key]);
                dest[prop.Value] = srcVal;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pairsToSearch"></param>
        /// <param name="extensions"></param>
        /// <returns>A dictionary that maps hashes to mapping pairs</returns>
        public static Dictionary <string, MappingPair> FilterExtensions(MappingPair[] pairsToSearch, string[] extensions)
        {
            var result = new Dictionary <string, MappingPair>();

            for (int i = 0; i < pairsToSearch.Length; i++)
            {
                MappingPair mappingPair = pairsToSearch[i];

                bool hasExtension = extensions.Any((x) => mappingPair.file.ToLower().EndsWith(x));

                if (hasExtension)
                {
                    if (!result.ContainsKey(mappingPair.hash))
                    {
                        result.Add(mappingPair.hash, mappingPair);
                    }
                }
            }

            return(result);
        }
Beispiel #16
0
        /// <summary>
        /// Given a MappingPair list, returns a AssetPath list filtered by file extensions
        /// </summary>
        /// <param name="pairsToSearch">The MappingPair list to be filtered and converted</param>
        /// <param name="extensions">An array detailing the extensions to filter them</param>
        /// <returns>A dictionary that maps hashes to mapping pairs</returns>
        public static List <AssetPath> GetPathsFromPairs(string basePath, MappingPair[] pairsToSearch, string[] extensions)
        {
            var tmpResult = new Dictionary <(string, string), AssetPath>();

            for (int i = 0; i < pairsToSearch.Length; i++)
            {
                MappingPair mappingPair = pairsToSearch[i];

                bool hasExtension = extensions.Any((x) => mappingPair.file.ToLower().EndsWith(x));

                if (hasExtension)
                {
                    if (!tmpResult.ContainsKey((mappingPair.hash, mappingPair.file)))
                    {
                        tmpResult.Add((mappingPair.hash, mappingPair.file), new AssetPath(basePath, mappingPair));
                    }
                }
            }

            return(tmpResult.Values.ToList());
        }
Beispiel #17
0
        public void BranchMergeDeleteWithSourceNotMappedTest()
        {
            MigrationItemStrings branch = new MigrationItemStrings("source", "target", TestEnvironment, true);
            MigrationItemStrings file   = new MigrationItemStrings("source/fld/file.txt", "target/fld/file.txt", TestEnvironment, true);

            // Add the parent folder at branch from place
            SourceAdapter.AddFolder(branch.LocalPath);

            MappingPair mapping = new MappingPair(TestEnvironment.FirstSourceServerPath + SrcPathSeparator + "source",
                                                  TestEnvironment.FirstTargetServerPath + TarPathSeparator + "source",
                                                  true); // cloaked

            TestEnvironment.AddMapping(mapping);

            // Branch the parent folder
            int branchChangeset = SourceAdapter.BranchItem(branch.ServerPath, branch.NewServerPath);

            // Add the child item
            SourceAdapter.AddFile(file.LocalPath);

            SourceWorkspace.Merge(branch.ServerPath, branch.NewServerPath,
                                  VersionSpec.ParseSingleSpec(branchChangeset.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);
            ResolveConflicts(Resolution.AcceptTheirs);
            SourceAdapter.DeleteItem(file.NewServerPath);

            Run();
            VerifyHistory(4, 0);

            // Resolve "Branch source path not found conflict" using "$/" scope.
            ConflictResolver  conflictManager = new ConflictResolver(Configuration);
            List <RTConflict> conflicts       = conflictManager.GetConflicts();

            Assert.AreEqual(1, conflicts.Count, "There should be only 1 conflict");
            conflictManager.TryResolveConflict(conflicts[0], new VCChangeToAddOnBranchSourceNotMappedAction(), "$/"); // Add on branch source not found

            Run(true, true);
            Assert.IsTrue(VerifyContents());
        }
Beispiel #18
0
        public void CloakedTargetMappingsTest()
        {
            MigrationItemStrings file = new MigrationItemStrings("source" + SourceAdapter.PathSeparator + "file.txt",
                                                                 "target" + SourceAdapter.PathSeparator + "file.txt", TestEnvironment, true);

            SourceAdapter.AddFile(file.LocalPath);

            MappingPair mapping = new MappingPair(TestEnvironment.FirstSourceServerPath + SrcPathSeparator + "target",
                                                  TestEnvironment.FirstTargetServerPath + TarPathSeparator + "target",
                                                  true); // cloaked

            TestEnvironment.AddMapping(mapping);

            int branchChangeset = SourceAdapter.BranchItem(file.ServerPath, file.NewServerPath);

            SourceAdapter.EditFile(m_extraFile.LocalPath);
            SourceAdapter.EditFile(file.LocalPath);

            int mergeChangset = SourceAdapter.MergeItem(file, branchChangeset);

            RunAndValidate();
        }
Beispiel #19
0
        public void DeleteUnmappedTest()
        {
            MigrationItemStrings cloakedFile = new MigrationItemStrings("cloak" + SourceAdapter.PathSeparator + "file.txt", null, TestEnvironment, true);

            SourceAdapter.AddFile(cloakedFile.LocalPath);

            MappingPair mapping = new MappingPair(TestEnvironment.FirstSourceServerPath + SrcPathSeparator + "cloak",
                                                  TestEnvironment.FirstTargetServerPath + TarPathSeparator + "cloak",
                                                  true); // cloaked

            TestEnvironment.AddMapping(mapping);

            SourceAdapter.EditFile(cloakedFile.LocalPath);
            SourceWorkspace.Get(VersionSpec.Latest, GetOptions.Overwrite);
            TestUtils.EditRandomFile(cloakedFile.LocalPath);
            SourceWorkspace.PendDelete(cloakedFile.LocalPath);

            // Extra file and deleted file will be checked in together.
            SourceAdapter.EditFile(m_extraFile.LocalPath);

            RunAndValidate();
        }
Beispiel #20
0
        public void CloakedSourceMappingsTest()
        {
            MigrationItemStrings branch = new MigrationItemStrings("source", "target", TestEnvironment, true);
            MigrationItemStrings file   = new MigrationItemStrings("source" + SourceAdapter.PathSeparator + "file.txt",
                                                                   "source" + SourceAdapter.PathSeparator + "renamedFile.txt", TestEnvironment, true);

            SourceAdapter.AddFile(file.LocalPath);

            MappingPair mapping = new MappingPair(TestEnvironment.FirstSourceServerPath + SrcPathSeparator + "source",
                                                  TestEnvironment.FirstTargetServerPath + TarPathSeparator + "source",
                                                  true); // cloaked

            TestEnvironment.AddMapping(mapping);

            int branchChangeset = SourceAdapter.BranchItem(branch.ServerPath, branch.NewServerPath);

            SourceAdapter.EditFile(m_extraFile.LocalPath);
            SourceAdapter.EditFile(file.LocalPath);
            SourceAdapter.RenameItem(file.ServerPath, file.NewServerPath);

            SourceWorkspace.Merge(branch.ServerPath, branch.NewServerPath,
                                  VersionSpec.ParseSingleSpec(branchChangeset.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);
            ResolveConflicts(Resolution.AcceptTheirs);
            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), MergeComment);

            Run();
            VerifyHistory(5, 0);

            // Resolve "Branch source path not found conflict" using "$/" scope.
            ConflictResolver  conflictManager = new ConflictResolver(Configuration);
            List <RTConflict> conflicts       = conflictManager.GetConflicts();

            Assert.AreEqual(1, conflicts.Count, "There should be only 1 conflict");
            conflictManager.TryResolveConflict(conflicts[0], new VCChangeToAddOnBranchSourceNotMappedAction(), "$/"); // Add on branch source not found

            RunAndValidate(true, true);
        }
Beispiel #21
0
        public void PartialCloakedChangesetTest()
        {
            MigrationItemStrings file1 = new MigrationItemStrings("folder/file1.txt", null, TestEnvironment, true);
            MigrationItemStrings file2 = new MigrationItemStrings("cloakfolder/file2.txt", null, TestEnvironment, true);

            MappingPair mapping = new MappingPair(TestEnvironment.FirstSourceServerPath + SrcPathSeparator + "cloakfolder",
                                                  TestEnvironment.FirstTargetServerPath + TarPathSeparator + "cloakfolder",
                                                  true);

            TestEnvironment.AddMapping(mapping);

            SourceAdapter.AddFile(file1.LocalPath);
            SourceAdapter.AddFile(file2.LocalPath);

            TestUtils.EditRandomFile(file1.LocalPath);
            TestUtils.EditRandomFile(file2.LocalPath);
            SourceWorkspace.PendEdit(file1.LocalPath);
            SourceWorkspace.PendEdit(file2.LocalPath);

            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), "Multiple edits.");

            RunAndValidate();
        }
        public void Map <TSrc, TDest>(TSrc src, TDest dest,
                                      IPropNamesMatcher propsMatcher             = null,
                                      IPropValueConverter propertyValueConverter = null,
                                      IMappingStrategy mappingStrategy           = null,
                                      Dictionary <string, object> externalData   = null)
        {
            if (src == null)
            {
                throw new ArgumentNullException("src", "Source can not be null, specify valid source for mapping");
            }

            propertyValueConverter = propertyValueConverter ?? new NopPropertyValueConverter();
            externalData           = externalData ?? new Dictionary <string, object>();

            var srcMappingObjectType = _mapperConfiguration.MappingObjects.Get(src);
            var srcMappingObject     = _mapperConfiguration.ObjectFactory.CreateInstance(srcMappingObjectType) as IMappingObject;

            srcMappingObject.UnderlyingObject = src;
            srcMappingObject.ExternalData     = externalData;

            var destMappingObjectType = _mapperConfiguration.MappingObjects.Get(dest);
            var destMappingObject     = _mapperConfiguration.ObjectFactory.CreateInstance(destMappingObjectType) as IMappingObject;

            destMappingObject.UnderlyingObject = dest;
            destMappingObject.ExternalData     = externalData;

            var mappingPair = new MappingPair(srcMappingObject, destMappingObject);

            var strategyType = _mapperConfiguration.MappingStrategies.Get(mappingPair);
            var strategy     = mappingStrategy ?? _mapperConfiguration.ObjectFactory.CreateInstance(strategyType) as IMappingStrategy;

            strategy.MapperConfiguration = _mapperConfiguration;
            strategy.PropValueConverter  = propertyValueConverter;
            strategy.PropsMatcher        = propsMatcher ?? _mapperConfiguration.ObjectFactory.CreateInstance(_mapperConfiguration.PropertyNameConverters.Get(mappingPair)) as IPropNamesMatcher;
            strategy.Map(mappingPair);
        }
Beispiel #23
0
        public void SnapshotMergeUndeleteRenameTest()
        {
            // scenario
            // branch from source to target where source is cloaked
            // item1 on source was edited, deleted
            // item1 on source was undelete, renamed (case-only rename) (snapshot start point)
            // item1 was merged to target
            // migration uses a snapshot start point which skips migrating deletion
            // hence undelete, rename becomes add, rename

            // cloak branch from path
            MappingPair mapping = new MappingPair(
                TestEnvironment.FirstSourceServerPath + SrcPathSeparator + "source",
                TestEnvironment.FirstTargetServerPath + TarPathSeparator + "source",
                true);

            TestEnvironment.AddMapping(mapping);

            MigrationItemStrings file1 = new MigrationItemStrings("source/folder/file1.txt", "source/Folder/File1.txt", TestEnvironment, true);
            MigrationItemStrings file2 = new MigrationItemStrings("source/folder/file2.txt", "source/folder/File2.txt", TestEnvironment, true);
            MigrationItemStrings file3 = new MigrationItemStrings("source/folder/file3.txt", null, TestEnvironment, true);

            // branch
            SourceAdapter.AddFile(file1.LocalPath);
            SourceAdapter.AddFile(file2.LocalPath);
            SourceAdapter.AddFile(file3.LocalPath);

            int changesetId = SourceAdapter.BranchItem(source.ServerPath, target.ServerPath);

            // merge edit
            // merge delete
            SourceAdapter.EditFile(file1.LocalPath);
            int deletionId = SourceTfsClient.GetChangeset(SourceAdapter.DeleteItem(file1.ServerPath)).Changes[0].Item.DeletionId;

            SourceWorkspace.Merge(source.LocalPath, target.LocalPath,
                                  VersionSpec.ParseSingleSpec(changesetId.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);

            changesetId = SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), "edit -> delete");

            // pend undelete
            SourceWorkspace.PendUndelete(file1.ServerPath, deletionId);

            // pend rename
            SourceWorkspace.PendRename(file1.LocalPath, file1.NewLocalPath);
            SourceWorkspace.PendRename(file2.LocalPath, file2.NewLocalPath);
            TestUtils.EditRandomFile(file3.LocalPath);
            SourceWorkspace.PendEdit(file3.LocalPath);

            changesetId = SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), "undelete rename");
            int snapshotChangesetId = changesetId;

            // merge undelete,rename skipping deletion
            // migrating merge,undelete,rename becomes add,rename
            SourceWorkspace.Merge(source.LocalPath, target.LocalPath,
                                  VersionSpec.ParseSingleSpec(changesetId.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);

            resolveConflictAcceptThiers();
            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), "merge undelete rename");

            // snapshot
            TestEnvironment.SnapshotStartPoints = new Dictionary <string, string>();
            TestEnvironment.SnapshotStartPoints.Add(TestEnvironment.SourceTeamProject, snapshotChangesetId.ToString());
            TestEnvironment.SnapshotBatchSize = 100;

            Run();

            // Resolve "Branch source path not found conflict" using "$/" scope.
            ConflictResolver  conflictManager = new ConflictResolver(Configuration);
            List <RTConflict> conflicts       = conflictManager.GetConflicts();

            Assert.AreEqual(1, conflicts.Count, "There should be only 1 conflict");
            conflictManager.TryResolveConflict(conflicts[0], new VCChangeToAddOnBranchSourceNotMappedAction(), "$/"); // Add on branch source not found

            Run();
            Assert.IsTrue(VerifyContents());
        }
Beispiel #24
0
        public void SnapshotMergeRenameEditTest()
        {
            // scenario
            // branch from source to target where source is cloaked
            // take the snapshot of target branch
            // item1 on source renamed,edited
            // item1 was merged to target
            // VC session converts merge,rename,edit to add,edit

            // cloak branch from path
            MappingPair mapping = new MappingPair(
                TestEnvironment.FirstSourceServerPath + SrcPathSeparator + "source",
                TestEnvironment.FirstTargetServerPath + TarPathSeparator + "source",
                true);

            TestEnvironment.AddMapping(mapping);


            MigrationItemStrings file1 = new MigrationItemStrings(
                string.Format("source{0}folder1{1}file1.txt", SrcPathSeparator, SrcPathSeparator),
                string.Format("source{0}folder2{1}file1.txt", SrcPathSeparator, SrcPathSeparator),
                TestEnvironment, true);
            MigrationItemStrings file2 = new MigrationItemStrings(
                string.Format("source{0}folder2{1}file2.txt", SrcPathSeparator, SrcPathSeparator),
                null, TestEnvironment, true);
            MigrationItemStrings file3 = new MigrationItemStrings(
                string.Format("source{0}folder1{1}file3.txt", SrcPathSeparator, SrcPathSeparator),
                string.Format("source{0}folder2{1}file3.txt", SrcPathSeparator, SrcPathSeparator),
                TestEnvironment, true);

            // branch
            SourceAdapter.AddFile(file1.LocalPath);
            SourceAdapter.AddFile(file2.LocalPath);
            SourceAdapter.AddFile(file3.LocalPath);

            int changesetId         = SourceAdapter.BranchItem(source.ServerPath, target.ServerPath);
            int snapshotChangesetId = SourceAdapter.EditFile(file2.LocalPath);

            // pend edit on file1
            SourceWorkspace.PendEdit(file1.LocalPath);
            TestUtils.EditRandomFile(file1.LocalPath);
            // pend rename (file1 is moved to a different location)
            SourceWorkspace.PendRename(file1.LocalPath, file1.NewLocalPath);
            // pend edit on file2
            SourceWorkspace.PendEdit(file2.LocalPath);
            TestUtils.EditRandomFile(file2.LocalPath);
            // pend rename (file3 is moved to a different location)
            SourceWorkspace.PendEdit(file3.LocalPath);
            SourceWorkspace.PendRename(file3.LocalPath, file3.NewLocalPath);
            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), "rename, edit");


            // merge changes from source to target
            // - merge,rename,edit on file1
            // - merge,edit on file2
            // - merge,rename on file3
            SourceWorkspace.Merge(source.LocalPath, target.LocalPath,
                                  VersionSpec.ParseSingleSpec(changesetId.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);

            resolveConflictAcceptThiers();

            changesetId = SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), "merge,rename,edit");

            // snapshot
            TestEnvironment.SnapshotStartPoints = new Dictionary <string, string>();
            TestEnvironment.SnapshotStartPoints.Add(TestEnvironment.SourceTeamProject, snapshotChangesetId.ToString());
            TestEnvironment.SnapshotBatchSize = 100;

            Run();

            // Resolve "Branch source path not found conflict" using "$/" scope.
            ConflictResolver  conflictManager = new ConflictResolver(Configuration);
            List <RTConflict> conflicts       = conflictManager.GetConflicts();

            Assert.AreEqual(1, conflicts.Count, "There should be only 1 conflict");
            conflictManager.TryResolveConflict(conflicts[0], new VCChangeToAddOnBranchSourceNotMappedAction(), "$/"); // Add on branch source not found

            Run();
            Assert.IsTrue(VerifyContents());
        }
Beispiel #25
0
        public void PathSnapshotBranchTest()
        {
            MigrationItemStrings branch  = new MigrationItemStrings("source/", "target/", TestEnvironment, true);
            MigrationItemStrings branch2 = new MigrationItemStrings("source/", "target2/", TestEnvironment, true);

            MigrationItemStrings[] addFiles = new MigrationItemStrings[10];

            // Add files
            // Create a tree structure so that we can test path compression logic.
            int sessionSnapshotChangesetId = 1;

            for (int i = 0; i < 10; i++)
            {
                addFiles[i] = new MigrationItemStrings(
                    string.Format("source/addFile{0}.txt", i),
                    string.Format("source/addFile{0}-rename.txt", i),
                    TestEnvironment,
                    true);

                SourceAdapter.AddFile(addFiles[i].LocalPath);
            }

            int editBeforeSnapshotChangesetId  = SourceAdapter.EditFile(addFiles[2].LocalPath);
            int editBeforeSnapshotChangesetId2 = SourceAdapter.EditFile(addFiles[2].LocalPath);


            SourceAdapter.RenameItem(addFiles[3].ServerPath, addFiles[3].NewServerPath, "Rename before snapshot");

            int deleteChangesetID = SourceAdapter.DeleteItem(addFiles[4].ServerPath);

            SourceAdapter.DeleteItem(addFiles[5].ServerPath);

            SourceAdapter.UndeleteFile(addFiles[4].ServerPath, deleteChangesetID);

            int path2SnapshotChangesetId = SourceAdapter.RenameItem(addFiles[6].ServerPath, addFiles[6].NewServerPath, "Rename before snapshot");

            int editAfterSnapshotChangesetId  = SourceAdapter.EditFile(addFiles[6].NewLocalPath);
            int editAfterSnapshotChangesetId2 = SourceAdapter.EditFile(addFiles[6].NewLocalPath);

            SourceAdapter.DeleteItem(addFiles[4].ServerPath);
            SourceAdapter.RenameItem(addFiles[3].NewServerPath, addFiles[3].ServerPath, "Rename after snapshot");

            // Branch from a version before the snapshot
            SourceWorkspace.Get(VersionSpec.Latest, GetOptions.Overwrite);
            SourceWorkspace.PendBranch(branch.ServerPath, branch.NewServerPath, new ChangesetVersionSpec(editBeforeSnapshotChangesetId));
            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), "Branch from a version before snapshot");

            SourceAdapter.BranchItem(branch2.ServerPath, branch2.NewServerPath);



            TestEnvironment.SnapshotStartPoints = new Dictionary <string, string>();
            TestEnvironment.SnapshotStartPoints.Add(TestEnvironment.SourceTeamProject, sessionSnapshotChangesetId.ToString());
            TestEnvironment.SnapshotBatchSize = 3;

            // We need to map to the sub item level
            MappingPair rootMapping = TestEnvironment.Mappings[0];

            TestEnvironment.Mappings.Clear();
            TestEnvironment.Mappings.Add(new MappingPair(rootMapping.SourcePath + "/target", rootMapping.TargetPath + "/target", false));
            TestEnvironment.Mappings.Add(new MappingPair(rootMapping.SourcePath + "/target2", rootMapping.TargetPath + "/target2", false));
            TestEnvironment.Mappings.Add(new MappingPair(rootMapping.SourcePath + "/source", rootMapping.TargetPath + "/source", false, path2SnapshotChangesetId.ToString(), null));

            Run();

            ConflictResolver  conflictManager = new ConflictResolver(Configuration);
            List <RTConflict> conflicts       = conflictManager.GetConflicts();

            Assert.AreEqual(1, conflicts.Count, "There should be only 1 conflict");
            conflictManager.TryResolveConflict(conflicts[0], ConflictConstant.TFSHistoryNotFoundSkipAction, "1-" + path2SnapshotChangesetId);
            Run(true, true);

            // ToDo, ideally, we should compare content at snapshot changeset and compare history after snapshot changeset.
            Assert.IsTrue(VerifyContents());
        }
Beispiel #26
0
        public void PathSnapshotCRUDTest()
        {
            MigrationItemStrings branch = new MigrationItemStrings("source/", "target/", TestEnvironment, true);

            MigrationItemStrings[] path1AddFiles = new MigrationItemStrings[10];
            MigrationItemStrings[] path2AddFiles = new MigrationItemStrings[10];

            // Add files
            // Create a tree structure so that we can test path compression logic.
            int sessionSnapshotChangesetId = 0;

            for (int i = 0; i < 10; i++)
            {
                path1AddFiles[i] = new MigrationItemStrings(string.Format("source/path1/addFile{0}.txt", i), null, TestEnvironment, true);
                if (i == 7)
                {
                    sessionSnapshotChangesetId = SourceAdapter.AddFile(path1AddFiles[i].LocalPath);
                }
                else
                {
                    SourceAdapter.AddFile(path1AddFiles[i].LocalPath);
                }
            }

            for (int i = 0; i < 10; i++)
            {
                path2AddFiles[i] = new MigrationItemStrings(string.Format("source/path2/file{0}.txt", i), string.Format("source/path2/file-rename{0}.txt", i), TestEnvironment, true);
                SourceAdapter.AddFile(path2AddFiles[i].LocalPath);
            }

            SourceAdapter.EditFile(path2AddFiles[2].LocalPath);

            SourceAdapter.RenameItem(path2AddFiles[3].ServerPath, path2AddFiles[3].NewServerPath, "Rename before snapshot");

            int deleteChangesetID = SourceAdapter.DeleteItem(path2AddFiles[4].ServerPath);

            SourceAdapter.DeleteItem(path2AddFiles[5].ServerPath);

            SourceAdapter.UndeleteFile(path2AddFiles[4].ServerPath, deleteChangesetID);

            int path2SnapshotChangesetId = SourceAdapter.RenameItem(path2AddFiles[6].ServerPath, path2AddFiles[6].NewServerPath, "Rename before snapshot");

            SourceAdapter.EditFile(path2AddFiles[6].NewLocalPath);
            SourceAdapter.DeleteItem(path2AddFiles[4].ServerPath);
            SourceAdapter.RenameItem(path2AddFiles[3].NewServerPath, path2AddFiles[3].ServerPath, "Rename after snapshot");


            TestEnvironment.SnapshotStartPoints = new Dictionary <string, string>();
            TestEnvironment.SnapshotStartPoints.Add(TestEnvironment.SourceTeamProject, sessionSnapshotChangesetId.ToString());
            TestEnvironment.SnapshotBatchSize = 3;

            // We need to map to the sub item level
            MappingPair rootMapping = TestEnvironment.Mappings[0];

            TestEnvironment.Mappings.Clear();
            TestEnvironment.Mappings.Add(new MappingPair(rootMapping.SourcePath + "/source/path1", rootMapping.TargetPath + "/source/path1", false));
            TestEnvironment.Mappings.Add(new MappingPair(rootMapping.SourcePath + "/source/path2", rootMapping.TargetPath + "/source/path2", false, path2SnapshotChangesetId.ToString(), null));

            Run();

            // ToDo, ideally, we should compare content at snapshot changeset and compare history after snapshot changeset.
            Assert.IsTrue(VerifyContents());
        }
Beispiel #27
0
        public void PathPeerSnapshotTest()
        {
            // Add files
            // Create a tree structure so that we can test path compression logic.
            int snapshotChangesetId1     = 0;
            int peerSnapshotChangesetId1 = 0;

            for (int i = 0; i < 4; i++)
            {
                MigrationItemStrings sourceFile = new MigrationItemStrings(string.Format("source/path1/addFile{0}.txt", i), null, TestEnvironment, true);
                MigrationItemStrings targetFile = new MigrationItemStrings(string.Format("source/path1/addFile{0}.txt", i), null, TestEnvironment, false);

                if (i < 2)
                {
                    snapshotChangesetId1 = SourceAdapter.AddFile(sourceFile.LocalPath);
                    TargetAdapter.AddFile(targetFile.LocalPath);
                    peerSnapshotChangesetId1 = TargetAdapter.EditFile(targetFile.LocalPath, sourceFile.LocalPath);
                }
                else
                {
                    SourceAdapter.AddFile(sourceFile.LocalPath);
                }
            }

            int snapshotChangesetId2     = 0;
            int peerSnapshotChangesetId2 = 0;

            for (int i = 0; i < 4; i++)
            {
                MigrationItemStrings sourceFile = new MigrationItemStrings(string.Format("source/path2/addFile{0}.txt", i), null, TestEnvironment, true);
                MigrationItemStrings targetFile = new MigrationItemStrings(string.Format("source/path2/addFile{0}.txt", i), null, TestEnvironment, false);

                if (i < 3)
                {
                    snapshotChangesetId2 = SourceAdapter.AddFile(sourceFile.LocalPath);
                    TargetAdapter.AddFile(targetFile.LocalPath);
                    peerSnapshotChangesetId2 = TargetAdapter.EditFile(targetFile.LocalPath, sourceFile.LocalPath);
                }
                else
                {
                    SourceAdapter.AddFile(sourceFile.LocalPath);
                }
            }

            // We need to map to the sub item level
            MappingPair rootMapping = TestEnvironment.Mappings[0];

            TestEnvironment.Mappings.Clear();
            TestEnvironment.Mappings.Add(
                new MappingPair(
                    rootMapping.SourcePath + "/source/path1",
                    rootMapping.TargetPath + "/source/path1",
                    false,
                    snapshotChangesetId1.ToString(),
                    peerSnapshotChangesetId1.ToString(),
                    null,
                    null,
                    peerSnapshotChangesetId1.ToString(),
                    snapshotChangesetId1.ToString()));
            TestEnvironment.Mappings.Add(
                new MappingPair(
                    rootMapping.SourcePath + "/source/path2",
                    rootMapping.TargetPath + "/source/path2",
                    false,
                    snapshotChangesetId2.ToString(),
                    peerSnapshotChangesetId2.ToString(),
                    null,
                    null,
                    peerSnapshotChangesetId2.ToString(),
                    snapshotChangesetId2.ToString()));

            Run();

            MigrationItemStrings newFile = new MigrationItemStrings("source/path1/newFile.txt", null, TestEnvironment, true);

            SourceAdapter.AddFile(newFile.LocalPath);

            Run();

            Assert.IsTrue(VerifyContents());
        }
Beispiel #28
0
 public static bool CanMap(MappingPair mappingPair)
 {
     return(PsToCamelCasePropsMatcher.CanMap(new MappingPair(mappingPair.Dest, mappingPair.Src)));
 }