public void Rename_RenamesConfigAndFile() { const string newLabel = "NewLabel"; var selectedConfig = _configurations[0]; selectedConfig.FilePath = null; // SUT Assert.True(_controller.RenameConfiguration(new ListViewItem { Tag = selectedConfig }, new LabelEditEventArgs(0, newLabel)), "Renaming a config to a unique name should complete successfully"); Assert.AreEqual(newLabel, selectedConfig.Label, "The configuration should have been renamed"); Assert.AreEqual(DictionaryConfigurationManagerController.FormatFilePath(_controller._projectConfigDir, newLabel), selectedConfig.FilePath, "The FilePath should have been generated"); Assert.True(_controller.IsDirty, "Made changes; should be dirty"); }
public void FormatFilePath() { var formattedFilePath = DictionaryConfigurationManagerController.FormatFilePath(_controller._projectConfigDir, "\nFile\\Name/With\"Chars<?>"); // SUT StringAssert.StartsWith(_projectConfigPath, formattedFilePath); StringAssert.EndsWith(DictionaryConfigurationModel.FileExtension, formattedFilePath); StringAssert.DoesNotContain("\n", formattedFilePath); StringAssert.DoesNotContain("\\", Path.GetFileName(formattedFilePath)); StringAssert.DoesNotContain("/", Path.GetFileName(formattedFilePath)); StringAssert.DoesNotContain("\"", formattedFilePath); StringAssert.DoesNotContain("<", formattedFilePath); StringAssert.DoesNotContain("?", formattedFilePath); StringAssert.DoesNotContain(">", formattedFilePath); StringAssert.Contains("File", formattedFilePath); StringAssert.Contains("Name", formattedFilePath); StringAssert.Contains("With", formattedFilePath); StringAssert.Contains("Chars", formattedFilePath); }
public void GenerateFilePath() { List <DictionaryConfigurationModel> conflictingConfigs; var configToRename = GenerateFilePath_Helper(out conflictingConfigs); // SUT DictionaryConfigurationManagerController.GenerateFilePath(_controller._projectConfigDir, _controller._configurations, configToRename); var newFilePath = configToRename.FilePath; StringAssert.StartsWith(_projectConfigPath, newFilePath); StringAssert.EndsWith(DictionaryConfigurationModel.FileExtension, newFilePath); Assert.AreEqual(DictionaryConfigurationManagerController.FormatFilePath(_controller._projectConfigDir, "configuration3_3"), configToRename.FilePath, "The file path should be based on the label"); foreach (var config in conflictingConfigs) { Assert.AreNotEqual(Path.GetFileName(newFilePath), Path.GetFileName(config.FilePath), "File name should be unique"); } }
private DictionaryConfigurationModel GenerateFilePath_Helper(out List <DictionaryConfigurationModel> conflictingConfigs) { var configToRename = new DictionaryConfigurationModel { Label = "configuration3", FilePath = null, Publications = new List <string>() }; conflictingConfigs = new List <DictionaryConfigurationModel> { new DictionaryConfigurationModel { Label = "conflicting file 3-0", FilePath = DictionaryConfigurationManagerController.FormatFilePath(_controller._projectConfigDir, "configuration3"), Publications = new List <string>() }, new DictionaryConfigurationModel { Label = "conflicting file 3-1", FilePath = DictionaryConfigurationManagerController.FormatFilePath(_controller._projectConfigDir, "configuration3_1"), Publications = new List <string>() }, new DictionaryConfigurationModel { Label = "conflicting file 3-2--in another directory to prove we can't accidentally mask unchanged default configurations", FilePath = Path.Combine(Path.Combine(_projectConfigPath, "subdir"), "configuration3_2" + DictionaryConfigurationModel.FileExtension), Publications = new List <string>() } }; _configurations.Add(configToRename); _configurations.AddRange(conflictingConfigs); return(configToRename); }