public void Should_perform_full_stack_of_transforms_correctly() { var service = new RenameService(); service.SetTransformActive <DateTimeAppenderTransform>(true); service.SetTransformActive <PrefixAddingTransform>(true); service.SetTransformActive <SuffixAddingTransform>(true); service.SetTransformActive <UniqueFilenameTransform>(true); service.GetTransform <PrefixAddingTransform>().Prefix = "prefix_"; service.GetTransform <SuffixAddingTransform>().Suffix = "_suffix"; service.GetTransform <DateTimeAppenderTransform>().DateTimeFormat = "_yyyy-MM-dd"; var expectedDateTime = DateTime.Now.ToString("_yyyy-MM-dd"); var previewResults = service.PreviewTransformedFilenames(_filenames); Assert.AreEqual(6, previewResults.Count); Assert.AreEqual(1, previewResults.Count(x => x.FilenameWithoutExtension == "prefix_UnitTestFile_0" + expectedDateTime + "_suffix")); Assert.AreEqual(1, previewResults.Count(x => x.FilenameWithoutExtension == "prefix_UnitTestFile_1" + expectedDateTime + "_suffix")); Assert.AreEqual(1, previewResults.Count(x => x.FilenameWithoutExtension == "prefix_UnitTestFile_2" + expectedDateTime + "_suffix")); Assert.AreEqual(1, previewResults.Count(x => x.FilenameWithoutExtension == "prefix_UnitTestFile_3" + expectedDateTime + "_suffix")); Assert.AreEqual(1, previewResults.Count(x => x.FilenameWithoutExtension == "prefix_UnitTestFile_0" + expectedDateTime + "_suffix_2")); Assert.AreEqual(1, previewResults.Count(x => x.FilenameWithoutExtension == "prefix_UnitTestFile_1" + expectedDateTime + "_suffix_2")); }
public MainWindowViewModel() { // Set unity container UnityContainer unityContainer = (UnityContainer)System.Windows.Application.Current.Resources["UContainer"]; unityContainer.RegisterType <OptionsModel>(new ContainerControlledLifetimeManager()); unityContainer.RegisterType <RenameService>(new ContainerControlledLifetimeManager()); // Instantiate objects now _option = unityContainer.Resolve <OptionsModel>(); _statServ = unityContainer.Resolve <StatusService>(); _renServ = unityContainer.Resolve <RenameService>(); _renServ.SetOptions(_option); // only pass this as a copy not a reference; // Set actions for the view and just use lambda expression to return true regardless BrowseFolder = new DelegateCommand(BrowseExecute, () => true); RenameNow = new DelegateCommand(RenExecute, () => true); // Call initialize(ON_INIT) for initialization just incase it was called from context menu // this call for everything status display, call to get folder etc. ProcessCode pc = ProcessCode.ON_INIT; InitializeAll(ref pc); _busy = false; }
public ActionResult RemoveSubFolderList(string folder, string toFolder, int limit) { var model = RenameService.RemoveSubFolder(sourceFolder: folder, descFolder: toFolder, fileSizeLimit: limit); model = model.OrderBy(x => x.DescFile).ToList(); return(View(model)); }
public FileTypesModel(RenameService rs) { if (rs != null) { // Add the method when RenameNowEvent is triggered so to update the filefilterstring rs.renameNowEvent += OnUpdateSetTypes; } }
public void Constructor_NullRenameType() { var configuration = CreateInMemoryConfiguration(null); var renameService = new RenameService(logger, configuration); var expectedRenameType = RenameType.Copy; Assert.Equal(expectedRenameType, renameService.RenameType); }
public void Constructor_UnsupportedRenameTypeString() { var invalidRtString = "bob-the-builder"; var configuration = CreateInMemoryConfiguration(invalidRtString); var renameService = new RenameService(logger, configuration); var expectedRenameType = RenameType.Copy; Assert.Equal(expectedRenameType, renameService.RenameType); }
public void RenameFile_ArgumentNullException_SourcePathNull() { var renameString = "copy"; var configuration = CreateInMemoryConfiguration(renameString); // Setup RenameService var renameService = new RenameService(logger, configuration); // "Copy" source to target var destPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); renameService.RenameFile(null, destPath); Assert.False(File.Exists(destPath)); }
public void PrefixAddingTransform_Should_rename_files_to_start_with_prefix() { var service = new RenameService(); service.SetTransformActive <PrefixAddingTransform>(true); service.GetTransform <PrefixAddingTransform>().Prefix = "prefix_"; var previewResults = service.PreviewTransformedFilenames(_filenames); Assert.AreEqual(6, previewResults.Count); Assert.AreEqual(2, previewResults.Count(x => x.FilenameWithoutExtension == "prefix_UnitTestFile_0")); Assert.AreEqual(2, previewResults.Count(x => x.FilenameWithoutExtension == "prefix_UnitTestFile_1")); Assert.AreEqual(1, previewResults.Count(x => x.FilenameWithoutExtension == "prefix_UnitTestFile_2")); Assert.AreEqual(1, previewResults.Count(x => x.FilenameWithoutExtension == "prefix_UnitTestFile_3")); }
public void SuffixAddingTransform_Should_rename_files_to_end_with_suffix() { var service = new RenameService(); service.SetTransformActive <SuffixAddingTransform>(true); service.GetTransform <SuffixAddingTransform>().Suffix = "_suffix"; var previewResults = service.PreviewTransformedFilenames(_filenames); Assert.AreEqual(6, previewResults.Count); Assert.AreEqual(2, previewResults.Count(x => x.FilenameWithoutExtension == "UnitTestFile_0_suffix")); Assert.AreEqual(2, previewResults.Count(x => x.FilenameWithoutExtension == "UnitTestFile_1_suffix")); Assert.AreEqual(1, previewResults.Count(x => x.FilenameWithoutExtension == "UnitTestFile_2_suffix")); Assert.AreEqual(1, previewResults.Count(x => x.FilenameWithoutExtension == "UnitTestFile_3_suffix")); }
public void Constructor_SupportedRenameTypeString() { var renameTypeList = new List <string> { "copy", "move", "none", "CoPy", "noNE" }; foreach (var rt in renameTypeList) { var configuration = CreateInMemoryConfiguration(rt); var renameService = new RenameService(logger, configuration); var expectedRenameType = Enum.Parse(typeof(RenameType), rt, true); Assert.Equal(expectedRenameType, renameService.RenameType); } }
// Initialize all options here public OptionsModel(RenameService rs) { // Set defaults _fileTypes = new FileTypesModel(rs); // set defaults for file types _fileTypes.Add("*.*"); _prefix = ""; _suffix = ""; _removeFilename = _renameSelectedFiles = _busy = false; _removePrefixFirst = _removeSuffixFirst = true; _progressWindowButtonLabel = "CANCEL"; _filesSelected = new List <string>(); _folderPath = GetFolderPathInit(); }
public void UniqueFilenameTransform_Should_rename_files_to_be_unique() { var service = new RenameService(); service.SetTransformActive <UniqueFilenameTransform>(true); var previewResults = service.PreviewTransformedFilenames(_filenames); Assert.AreEqual(6, previewResults.Count); Assert.IsNotNull(previewResults.FirstOrDefault(x => x.FilenameWithoutExtension == "UnitTestFile_0")); Assert.IsNotNull(previewResults.FirstOrDefault(x => x.FilenameWithoutExtension == "UnitTestFile_0_2")); Assert.IsNotNull(previewResults.FirstOrDefault(x => x.FilenameWithoutExtension == "UnitTestFile_1")); Assert.IsNotNull(previewResults.FirstOrDefault(x => x.FilenameWithoutExtension == "UnitTestFile_1_2")); Assert.IsNotNull(previewResults.FirstOrDefault(x => x.FilenameWithoutExtension == "UnitTestFile_2")); Assert.IsNotNull(previewResults.FirstOrDefault(x => x.FilenameWithoutExtension == "UnitTestFile_3")); }
public void DateTimeAppenderTransform_Should_rename_files_to_end_with_year() { var service = new RenameService(); service.SetTransformActive <DateTimeAppenderTransform>(true); service.GetTransform <DateTimeAppenderTransform>().DateTimeFormat = "yyyy"; var previewResults = service.PreviewTransformedFilenames(_filenames); var year = DateTime.Now.Year; Assert.AreEqual(6, previewResults.Count); Assert.AreEqual(2, previewResults.Count(x => x.FilenameWithoutExtension == "UnitTestFile_0" + year)); Assert.AreEqual(2, previewResults.Count(x => x.FilenameWithoutExtension == "UnitTestFile_1" + year)); Assert.AreEqual(1, previewResults.Count(x => x.FilenameWithoutExtension == "UnitTestFile_2" + year)); Assert.AreEqual(1, previewResults.Count(x => x.FilenameWithoutExtension == "UnitTestFile_3" + year)); }
public void FindPhotoDateTime_ValidDateTimeString_InvalidFormat() { var renameString = "copy"; var configuration = CreateInMemoryConfiguration(renameString); // Setup RenameService and Photo var renameService = new RenameService(logger, configuration); var photo = new Photo(""); // Test that FindPhotoDateTime finds datetime with correct format var dateTimeToday = DateTime.Today; var format = "h"; photo.DateTimeOriginal = dateTimeToday; Assert.Throws <FormatException>(() => renameService.FindPhotoDateTime(photo, format)); }
public void FindPhotoDateTime_InvalidDateTime() { var renameString = "copy"; var configuration = CreateInMemoryConfiguration(renameString); // Setup RenameService and Photo var renameService = new RenameService(logger, configuration); var photo = new Photo(""); // Test that FindPhotoDateTime finds datetime with correct format var format = "yyyyMMdd_HHmmss"; photo.DateTimeOriginal = null; var actualDateTimeString = renameService.FindPhotoDateTime(photo, format); Assert.Empty(actualDateTimeString); }
public void RenameFile_ArgumentException_EmptySourceName_NoFilesExist() { var renameString = "copy"; var configuration = CreateInMemoryConfiguration(renameString); // Setup RenameService var renameService = new RenameService(logger, configuration); // Create source path, but no file var sourcePath = string.Empty; // "Copy" source to target var destPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); renameService.RenameFile(sourcePath, destPath); Assert.False(File.Exists(sourcePath)); Assert.False(File.Exists(destPath)); }
public void FindPhotoDateTime_ValidDateTime_And_Format() { var renameString = "copy"; var configuration = CreateInMemoryConfiguration(renameString); // Setup RenameService and Photo var renameService = new RenameService(logger, configuration); var photo = new Photo(""); // Test that FindPhotoDateTime finds datetime with correct format var dateTimeToday = DateTime.Today; var format = "yyyyMMdd_HHmmss"; photo.DateTimeOriginal = dateTimeToday; var expectedDateTimeString = dateTimeToday.ToString(format); var actualDateTimeString = renameService.FindPhotoDateTime(photo, format); Assert.Equal(expectedDateTimeString, actualDateTimeString); }
public void RenameFile_IOException_ProcessHoldingFileAccess_SourceExists() { var renameString = "copy"; var configuration = CreateInMemoryConfiguration(renameString); // Setup RenameService var renameService = new RenameService(logger, configuration); // Create source path and file, keep file open var sourcePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); File.Create(sourcePath); // "Copy" source to target var destPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); renameService.RenameFile(sourcePath, destPath); Assert.True(File.Exists(sourcePath)); Assert.False(File.Exists(destPath)); }
public void RenameFile_None_ExistingSource() { var renameString = "none"; var configuration = CreateInMemoryConfiguration(renameString); // Setup RenameService var renameService = new RenameService(logger, configuration); // Create source file var sourcePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); File.Create(sourcePath) .Close(); // Do nothing ¯\_(ツ)_/¯ var destPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); renameService.RenameFile(sourcePath, destPath); Assert.True(File.Exists(sourcePath)); Assert.False(File.Exists(destPath)); }
public void RenameFile_Copy_ExistingSource() { var renameString = "copy"; var configuration = CreateInMemoryConfiguration(renameString); // Setup RenameService var renameService = new RenameService(logger, configuration); // Create source file var sourcePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); File.Create(sourcePath) .Close(); // Copy source to target var destPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); renameService.RenameFile(sourcePath, destPath); Assert.True(File.Exists(sourcePath)); Assert.True(File.Exists(destPath)); }
public void Should_execute_full_stack_transform_rename_correctly_and_write_a_log() { var service = new RenameService(); service.SetTransformActive <DateTimeAppenderTransform>(true); service.SetTransformActive <PrefixAddingTransform>(true); service.SetTransformActive <SuffixAddingTransform>(true); service.SetTransformActive <UniqueFilenameTransform>(true); service.GetTransform <PrefixAddingTransform>().Prefix = "prefix_"; service.GetTransform <SuffixAddingTransform>().Suffix = "_suffix"; service.GetTransform <DateTimeAppenderTransform>().DateTimeFormat = "_yyyy-MM-dd"; var expectedDateTime = DateTime.Now.ToString("_yyyy-MM-dd"); var executionResults = service.ExecuteRenames(_filenames.Select(x => (x, true)).ToList(), _logFilename); Assert.AreEqual(true, executionResults.Success); Assert.IsTrue(executionResults.ExecutionLog.Length > 0); Assert.AreEqual(6, executionResults.FileRenameResults.Count); Assert.AreEqual(1, executionResults.FileRenameResults.Count(x => x.Key.FilenameWithoutExtension == "prefix_UnitTestFile_0" + expectedDateTime + "_suffix")); Assert.AreEqual(1, executionResults.FileRenameResults.Count(x => x.Key.FilenameWithoutExtension == "prefix_UnitTestFile_1" + expectedDateTime + "_suffix")); Assert.AreEqual(1, executionResults.FileRenameResults.Count(x => x.Key.FilenameWithoutExtension == "prefix_UnitTestFile_2" + expectedDateTime + "_suffix")); Assert.AreEqual(1, executionResults.FileRenameResults.Count(x => x.Key.FilenameWithoutExtension == "prefix_UnitTestFile_3" + expectedDateTime + "_suffix")); Assert.AreEqual(1, executionResults.FileRenameResults.Count(x => x.Key.FilenameWithoutExtension == "prefix_UnitTestFile_0" + expectedDateTime + "_suffix_2")); Assert.AreEqual(1, executionResults.FileRenameResults.Count(x => x.Key.FilenameWithoutExtension == "prefix_UnitTestFile_1" + expectedDateTime + "_suffix_2")); Assert.IsTrue(File.Exists(executionResults.FileRenameResults.ElementAt(0).Key.FileInfo.FullName)); Assert.IsTrue(File.Exists(executionResults.FileRenameResults.ElementAt(1).Key.FileInfo.FullName)); Assert.IsTrue(File.Exists(executionResults.FileRenameResults.ElementAt(2).Key.FileInfo.FullName)); Assert.IsTrue(File.Exists(executionResults.FileRenameResults.ElementAt(3).Key.FileInfo.FullName)); Assert.IsTrue(File.Exists(executionResults.FileRenameResults.ElementAt(4).Key.FileInfo.FullName)); Assert.IsTrue(File.Exists(executionResults.FileRenameResults.ElementAt(5).Key.FileInfo.FullName)); Assert.IsTrue(File.Exists(_logFilename)); }
private async Task<RenameResponse> SendRequest(OmnisharpWorkspace workspace, string renameTo, string filename, string fileContent, bool wantsTextChanges = false, bool applyTextChanges = true) { var lineColumn = TestHelpers.GetLineAndColumnFromDollar(fileContent); var controller = new RenameService(workspace); var request = new RenameRequest { Line = lineColumn.Line, Column = lineColumn.Column, RenameTo = renameTo, FileName = filename, Buffer = fileContent.Replace("$", ""), WantsTextChanges = wantsTextChanges, ApplyTextChanges = applyTextChanges }; await workspace.BufferManager.UpdateBuffer(request); return await controller.Handle(request); }
private async Task <RenameResponse> SendRequest(OmnisharpWorkspace workspace, string renameTo, string filename, string fileContent, bool wantsTextChanges = false, bool applyTextChanges = true) { var lineColumn = TestHelpers.GetLineAndColumnFromDollar(fileContent); var controller = new RenameService(workspace); var request = new RenameRequest { Line = lineColumn.Line, Column = lineColumn.Column, RenameTo = renameTo, FileName = filename, Buffer = fileContent.Replace("$", ""), WantsTextChanges = wantsTextChanges, ApplyTextChanges = applyTextChanges }; await workspace.BufferManager.UpdateBuffer(request); return(await controller.Handle(request)); }
public FRMMain() { InitializeComponent(); _renameService = new RenameService(); }
public static void TestRemoveFolder(string sourceFolder, string descFolder, int fileSizeLimit) { descFolder = (sourceFolder.EndsWith("\\") || sourceFolder.EndsWith("/")) ? sourceFolder + "movefiles\\" : sourceFolder + "\\movefiles\\"; var ret = RenameService.RemoveSubFolder(sourceFolder: sourceFolder, descFolder: descFolder, fileSizeLimit: fileSizeLimit); }
public static void TestRename(string sourceFolder, int fileSizeLimit) { var descFolder = (sourceFolder.EndsWith("\\") || sourceFolder.EndsWith("/")) ? sourceFolder + "tempFile\\" : sourceFolder + "\\tempFin\\"; var ret = RenameService.PrepareRename(sourceFolder, descFolder, fileSizeLimit); }
public ActionResult BatchRenameList(string folder, string toFolder, int limit) { var model = RenameService.PrepareRename(folder, toFolder, limit); return(View(model)); }