public void GetNewName_ValidOperations_AreAppliedInOrder()
        {
            // Arrange
            var name = "Char_Hero_Idle";

            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.SearchString      = "ar_He";
            replaceStringOp.ReplacementString = "baboon";

            var trimCharactersOp = new TrimCharactersOperation();

            trimCharactersOp.NumFrontDeleteChars = 4;

            var operationSequence = new RenameOperationSequence <IRenameOperation>();

            operationSequence.Add(replaceStringOp);
            operationSequence.Add(trimCharactersOp);

            var operationSequenceReversed = new RenameOperationSequence <IRenameOperation>();

            operationSequenceReversed.Add(trimCharactersOp);
            operationSequenceReversed.Add(replaceStringOp);

            var expected         = "boonro_Idle";
            var expectedReversed = "_Hero_Idle";

            // Act
            string result         = operationSequence.GetResultingName(name, 0);
            string resultReversed = operationSequenceReversed.GetResultingName(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
            Assert.AreEqual(expectedReversed, resultReversed);
        }
Пример #2
0
        /// <summary>
        /// Renames the specified Objects according to a supplied RenameOperationSequence.
        /// </summary>
        /// <param name="objectsToRename">Objects to rename.</param>
        /// <param name="sequence">Sequence to use to generate new names.</param>
        /// <param name="ignoreUndo">If set to <c>true</c> ignore undo.</param>
        public void RenameObjects(List <UnityEngine.Object> objectsToRename, RenameOperationSequence <RenameOperation> sequence, bool ignoreUndo = false)
        {
            var objs = new List <ObjectNameDelta>();

            for (int i = 0; i < objectsToRename.Count; ++i)
            {
                var newName      = sequence.GetResultingName(objectsToRename[i].name, i);
                var originalName = objectsToRename[i].name;

                // Don't request a rename if the name isn't going to change.
                if (originalName.Equals(newName))
                {
                    continue;
                }

                objs.Add(new ObjectNameDelta(objectsToRename[i], newName));
            }

            this.RenameObjects(objs, ignoreUndo);
        }
        public void GetNewName_AllOperations_RenamesCorrectly()
        {
            // Arrange
            var name = "Char_Hero_Idle";

            var trimCharactersOp = new TrimCharactersOperation();

            trimCharactersOp.NumFrontDeleteChars = 1;
            trimCharactersOp.NumBackDeleteChars  = 5;

            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.SearchString      = "r_H";
            replaceStringOp.ReplacementString = "t_Z";

            var addStringOp = new AddStringOperation();

            addStringOp.Prefix = "a_";
            addStringOp.Suffix = "AA";

            var enumerateOp = new EnumerateOperation();

            enumerateOp.SetCountFormat("D4");
            enumerateOp.StartingCount = 100;

            var operationSequence = new RenameOperationSequence <IRenameOperation>();

            operationSequence.Add(trimCharactersOp);
            operationSequence.Add(replaceStringOp);
            operationSequence.Add(addStringOp);
            operationSequence.Add(enumerateOp);

            var expected = "a_hat_ZeroAA0100";

            // Act
            string result = operationSequence.GetResultingName(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }