public void OrganizeShouldFireEventsWhenSearchingForFilesRecursively() { string subdirectoryName = Path.GetRandomFileName(); string subdirectoryPath = Path.Combine(sourceDirectoryPath, subdirectoryName); Directory.CreateDirectory(subdirectoryPath); string jpgFilePath = Path.Combine(subdirectoryPath, Path.GetRandomFileName() + ".jpg"); string txtFilePath = Path.Combine(subdirectoryPath, Path.GetRandomFileName() + ".txt"); using (Image image = new Bitmap(1, 1)) using (var streamWriter = new StreamWriter(txtFilePath)) { image.Save(jpgFilePath); streamWriter.WriteLine(Path.GetRandomFileName()); } JPGFileFoundEventArgs receivedJPGFileFoundEventArgs = null; UnsupportedFileFoundEventArgs receivedUnsupportedFileFoundEventArgs = null; organizer.JPGFileFoundEvent += (object sender, JPGFileFoundEventArgs e) => receivedJPGFileFoundEventArgs = e; organizer.UnsupportedFileFoundEvent += (object sender, UnsupportedFileFoundEventArgs e) => receivedUnsupportedFileFoundEventArgs = e; organizer.Organize(); Assert.IsTrue(receivedJPGFileFoundEventArgs.FilePath == jpgFilePath); Assert.IsTrue(receivedJPGFileFoundEventArgs.DestinationDirectoryPath == destinationDirectoryPath); Assert.IsTrue(receivedUnsupportedFileFoundEventArgs.FilePath == txtFilePath); Assert.IsTrue(receivedUnsupportedFileFoundEventArgs.DestinationDirectoryPath == destinationDirectoryPath); }
public void HandleJPGFileFoundEventShouldSucceedWhenRenamingImageAndAFileWithThatFileNameAlreadyExists() { handler = new JPGFileHandler(organizer, JPGFileHandler.Naming.EXIFDateTime); exposedHandler = new PrivateObject(handler); List <string> subdirectories = new List <string> { Path.GetRandomFileName(), Path.GetRandomFileName(), Path.GetRandomFileName() }; string fileName = Path.GetRandomFileName() + ".jpg"; string dateTimeOriginal = "2015:10:17 18:18:11"; foreach (string subdirectory in subdirectories) { Directory.CreateDirectory(Path.Combine(sourceDirectoryPath, subdirectory)); string sourceFilePath = Path.Combine(sourceDirectoryPath, subdirectory, fileName); Image image = CreateImage(dateTimeOriginal); image.Save(sourceFilePath, ImageFormat.Jpeg); image.Dispose(); JPGFileFoundEventArgs args = new JPGFileFoundEventArgs(sourceFilePath, destinationDirectoryPath); exposedHandler.Invoke("HandleJPGFileFoundEvent", organizer, args); } List <string> newFileNames = new List <string> { "2015-10-17 18.18.11.jpg", "2015-10-17 18.18.11 1.jpg", "2015-10-17 18.18.11 2.jpg" }; string date = "2015-10-17"; foreach (string newFileName in newFileNames) { string destinationFilePath = Path.Combine(destinationDirectoryPath, date, newFileName); Assert.IsTrue(File.Exists(destinationFilePath)); } }
public void HandleJPGFileFoundEventShouldSucceedWhenImageHasEXIFDateTimeOriginalData() { string fileName = Path.GetRandomFileName(); string date = "2015-10-17"; string dateTimeOriginal = "2015:10:17 18:18:11"; string sourceFilePath = Path.Combine(sourceDirectoryPath, fileName); string destinationFilePath = Path.Combine(destinationDirectoryPath, date, fileName); Image image = CreateImage(dateTimeOriginal); image.Save(sourceFilePath, ImageFormat.Jpeg); JPGFileFoundEventArgs args = new JPGFileFoundEventArgs(sourceFilePath, destinationDirectoryPath); exposedHandler.Invoke("HandleJPGFileFoundEvent", organizer, args); Assert.IsTrue(File.Exists(destinationFilePath)); }
public void HandleJPGFileFoundEventShouldSucceedWhenRenamingImageWithEXIFDataTimeOriginalData() { handler = new JPGFileHandler(organizer, JPGFileHandler.Naming.EXIFDateTime); exposedHandler = new PrivateObject(handler); string fileName = Path.GetRandomFileName() + ".jpg"; string dateTimeOriginal = "2015:10:18 18:18:11"; string date = "2015-10-18"; string newFileName = "2015-10-18 18.18.11.jpg"; string sourceFilePath = Path.Combine(sourceDirectoryPath, fileName); string destinationFilePath = Path.Combine(destinationDirectoryPath, date, newFileName); Image image = CreateImage(dateTimeOriginal); image.Save(sourceFilePath, ImageFormat.Jpeg); JPGFileFoundEventArgs args = new JPGFileFoundEventArgs(sourceFilePath, destinationDirectoryPath); exposedHandler.Invoke("HandleJPGFileFoundEvent", organizer, args); Assert.IsTrue(File.Exists(destinationFilePath)); }