/// <summary>
/// Cuts 2 files with the same name, pastes them to a folder, and makes
/// sure we get prompted to overwrite. Answers no to overwriting, both
/// files should still be in the project.
/// </summary>
/// <param name="mover"></param>
private void MoveDuplicateFileNameDontOverwrite(MoveDelegate mover) {
foreach (var projectType in ProjectTypes) {
var project = new ProjectDefinition(
"DragDropCopyCutPaste",
projectType,
ItemGroup(
Folder("A"),
Folder("B"),
Content("quox.txt", "top-level"),
Content("A\\quox.txt", "A")
)
);
using (var solution = project.Generate().ToVs()) {
mover(
solution.WaitForItem("DragDropCopyCutPaste", "B"),
solution.WaitForItem("DragDropCopyCutPaste", "A", "quox.txt"),
solution.WaitForItem("DragDropCopyCutPaste", "quox.txt")
);
using (var dialog = OverwriteFileDialog.Wait(solution.App)) {
AssertUtil.Contains(dialog.Text, "A file with the same name 'quox.txt' already exists.");
dialog.No();
}
solution.AssertFileExists("DragDropCopyCutPaste", "B", "quox.txt");
// one of the fils should still exist...
try {
solution.AssertFileExists("DragDropCopyCutPaste", "quox.txt");
} catch (AssertFailedException) {
solution.AssertFileExists("DragDropCopyCutPaste", "A", "quox.txt");
}
Assert.AreEqual(1, solution.Project.ProjectItems.Item("B").ProjectItems.Count);
}
}
}
/// <summary>
/// Adds a new folder which fits exactly w/ no space left in the path name
/// </summary>
private void CutFileToFolderTooLong(MoveDelegate mover) {
foreach (var projectType in ProjectTypes) {
var testDef = new ProjectDefinition("LFN",
projectType,
ItemGroup(
Compile("server")
)
);
using (var solution = SolutionFile.Generate("LongFileNames", 29, testDef).ToVs()) {
// find server, send copy & paste, verify copy of file is there
var projectNode = solution.WaitForItem("LFN");
AutomationWrapper.Select(projectNode);
solution.PressAndRelease(Key.F10, Key.LeftCtrl, Key.LeftShift);
solution.PressAndRelease(Key.D);
solution.PressAndRelease(Key.Right);
solution.PressAndRelease(Key.D);
solution.Type("01234567891");
solution.PressAndRelease(Key.Enter);
var folderNode = solution.WaitForItem("LFN", "01234567891");
Assert.IsNotNull(folderNode);
var serverNode = solution.FindItem("LFN", "server" + projectType.CodeExtension);
AutomationWrapper.Select(serverNode);
solution.ControlC();
solution.ControlV();
var serverCopy = solution.WaitForItem("LFN", "server - Copy" + projectType.CodeExtension);
Assert.IsNotNull(serverCopy);
mover(solution, folderNode, serverCopy);
// Depending on VS version/update, the message may be:
// "The filename is too long."
// "The filename or extension is too long."
solution.CheckMessageBox(" filename ", " is too long.");
}
}
}
/// <summary>
/// Move item to a folder that has a symbolic link. Verify we cannot move
/// ourselves to ourselves and that moves are reflected in both the folder and its symbolic link.
/// NOTE: Because of symbolic link creation, this test must be run as administrator.
/// </summary>
private void MoveFileFromFolderToLinkedFolder(MoveDelegate mover) {
foreach (var projectType in ProjectTypes) {
var projectDefs = new[] {
new ProjectDefinition("MoveLinkedFolder",
projectType,
ItemGroup(
Content("textfile.txt", "text file contents"),
Folder("Folder"),
Content("Folder\\FileInFolder.txt", "File inside of linked folder..."),
SymbolicLink("FolderLink", "Folder")
)
)
};
using (var solution = SolutionFile.Generate("MoveLinkedFolder", projectDefs).ToVs()) {
mover(
solution,
solution.FindItem("MoveLinkedFolder", "FolderLink"),
solution.FindItem("MoveLinkedFolder", "Folder", "FileInFolder.txt")
);
// Say okay to the error that pops up since we can't move to ourselves.
solution.WaitForDialog();
Keyboard.Type(Key.Enter);
solution.WaitForDialogDismissed();
// Verify that after the dialog our files are still present.
solution.AssertFileExists("MoveLinkedFolder", "FolderLink", "FileInFolder.txt");
solution.AssertFileExists("MoveLinkedFolder", "Folder", "FileInFolder.txt");
// Now move the text file in the root. Expect it to move and be in both.
mover(
solution,
solution.FindItem("MoveLinkedFolder", "FolderLink"),
solution.FindItem("MoveLinkedFolder", "textfile.txt")
);
solution.AssertFileExists("MoveLinkedFolder", "FolderLink", "textfile.txt");
solution.AssertFileExists("MoveLinkedFolder", "Folder", "textfile.txt");
}
}
}
/// <summary>
/// Copy item from folder to a symbolic link of that folder. Expect a copy to be made.
/// NOTE: Because of symbolic link creation, this test must be run as administrator.
/// </summary>
private void CopyFileFromFolderToLinkedFolder(MoveDelegate copier) {
foreach (var projectType in ProjectTypes) {
var projectDefs = new[] {
new ProjectDefinition("MoveLinkedFolder",
projectType,
ItemGroup(
Folder("Folder"),
Content("Folder\\FileInFolder.txt", "File inside of linked folder..."),
SymbolicLink("FolderLink", "Folder")
)
)
};
using (var solution = SolutionFile.Generate("MoveLinkedFolder", projectDefs).ToVs()) {
copier(
solution,
solution.FindItem("MoveLinkedFolder", "FolderLink"),
solution.FindItem("MoveLinkedFolder", "Folder", "FileInFolder.txt"));
// Verify that after the dialog our files are still present.
solution.AssertFileExists("MoveLinkedFolder", "FolderLink", "FileInFolder.txt");
solution.AssertFileExists("MoveLinkedFolder", "Folder", "FileInFolder.txt");
// Verify the copies were made.
solution.AssertFileExists("MoveLinkedFolder", "FolderLink", "FileInFolder - Copy.txt");
solution.AssertFileExists("MoveLinkedFolder", "Folder", "FileInFolder - Copy.txt");
}
}
}
/// <summary>
/// Drag file from another hierarchy into folder in our hierarchy, item should be added
/// Cannot move the folder 'DuplicateFolderName'. A folder with that name already exists in the destination directory.
/// </summary>
private void MoveDuplicateFolderName(MoveDelegate mover) {
foreach (var projectType in ProjectTypes) {
var testDef = new ProjectDefinition("DragDropCopyCutPaste",
projectType,
ItemGroup(
Folder("DuplicateFolderName"),
Folder("DuplicateFolderNameTarget"),
Folder("DuplicateFolderNameTarget\\DuplicateFolderName")
)
);
using (var solution = testDef.Generate().ToVs()) {
mover(
solution,
solution.WaitForItem("DragDropCopyCutPaste", "DuplicateFolderNameTarget"),
solution.WaitForItem("DragDropCopyCutPaste", "DuplicateFolderName")
);
solution.CheckMessageBox("Cannot move the folder 'DuplicateFolderName'. A folder with that name already exists in the destination directory.");
}
}
}
请发表评论