public void RenameObjects_Spritesheet_Renames() { // Arrange var spriteSheetConfig = new SpriteSheetGenerationConfig(2, "Texture.png"); spriteSheetConfig.NamePrefix = "Texture_Sprite"; var textureWithSprites = this.SetupSpriteSheet(spriteSheetConfig); var replaceNameOp = new ReplaceNameOperation(); replaceNameOp.NewName = "NewSprite"; var enumerateOp = new EnumerateOperation(); enumerateOp.StartingCount = 1; var renameSequence = new RenameOperationSequence <IRenameOperation>(); renameSequence.Add(replaceNameOp); renameSequence.Add(enumerateOp); var path = AssetDatabase.GetAssetPath(textureWithSprites); var allAssetsAtPath = AssetDatabase.LoadAllAssetsAtPath(path); var allSprites = new List <Object>(); foreach (var asset in allAssetsAtPath) { if (asset is Sprite) { allSprites.Add(asset); } } var bulkRenamer = new BulkRenamer(renameSequence); bulkRenamer.RenameObjects(allSprites, true); var expectedNames = new List <string> { "NewSprite1", "NewSprite2", "NewSprite3", "NewSprite4" }; var resultingNames = new List <string>(); foreach (var sprite in allSprites) { resultingNames.Add(sprite.name); } Assert.AreEqual(expectedNames, resultingNames); }
public void Rename_DeleteTargetNameIsEmpty_IsUnchanged() { // Arrange var name = string.Empty; var replaceNameOp = new ReplaceNameOperation(); var expected = RenameResult.Empty; // Act var result = replaceNameOp.Rename(name, 0); // Assert Assert.AreEqual(expected, result); }
public void Rename_DeleteTargetNameIsNull_Renames() { // Arrange string name = null; var replaceNameOp = new ReplaceNameOperation(); var expected = RenameResult.Empty; // Act var result = replaceNameOp.Rename(name, 0); // Assert Assert.AreEqual(expected, result); }
public void Rename_DeleteTargetNameIsNotEmpty_IsDeleted() { // Arrange var name = "Char_Hero"; var replaceNameOp = new ReplaceNameOperation(); var expected = new RenameResult() { new Diff(name, DiffOperation.Deletion) }; // Act var result = replaceNameOp.Rename(name, 0); // Assert Assert.AreEqual(expected, result); }
public void Rename_ReplaceName_IsReplaced() { // Arrange var name = "Char_Hero"; var replaceNameOp = new ReplaceNameOperation(); replaceNameOp.NewName = "Blah"; var expected = new RenameResult() { new Diff(name, DiffOperation.Deletion), new Diff("Blah", DiffOperation.Insertion) }; // Act var result = replaceNameOp.Rename(name, 0); // Assert Assert.AreEqual(expected, result); }
public void RenameObjects_SingleAsset_Renames() { var gameObjectAsset = this.CreatePrefabFromGameObject( new GameObject("Original"), string.Concat(TestFixturesDirectory, "Original.prefab")); var singleAsset = new List <Object>() { gameObjectAsset }; var replaceNameOp = new ReplaceNameOperation(); replaceNameOp.NewName = "NewName"; var renameSequence = new RenameOperationSequence <IRenameOperation>(); renameSequence.Add(replaceNameOp); var bulkRenamer = new BulkRenamer(renameSequence); bulkRenamer.RenameObjects(singleAsset, true); Assert.AreEqual("NewName", singleAsset[0].name); }
/// <summary> /// Initializes a new instance of the <see cref="ReplaceNameOperation"/> class. /// This is a clone constructor, copying the values from one to another. /// </summary> /// <param name="operationToCopy">Operation to copy.</param> public ReplaceNameOperation(ReplaceNameOperation operationToCopy) { this.NewName = operationToCopy.NewName; }
/// <summary> /// Clone this instance. /// </summary> /// <returns>A clone of this instance</returns> public override RenameOperation Clone() { var clone = new ReplaceNameOperation(this); return(clone); }