Пример #1
0
        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);
        }
Пример #2
0
        public void ProcessFileShouldFireUnsupportedFileFoundEventWhenFileIsNotJPG()
        {
            string filePath = Path.Combine(sourceDirectoryPath, Path.GetRandomFileName());

            UnsupportedFileFoundEventArgs receivedEventArgs = null;

            organizer.UnsupportedFileFoundEvent += (object sender, UnsupportedFileFoundEventArgs e) => { receivedEventArgs = e; };

            exposedOrganizer.Invoke("ProcessFile", filePath);

            Assert.AreEqual(filePath, receivedEventArgs.FilePath);
            Assert.AreEqual(destinationDirectoryPath, receivedEventArgs.DestinationDirectoryPath);
        }
Пример #3
0
        public void ProcessFileShouldFireUnsupportedFileFoundEventWhenFileCausesUnsupportedJPGFileException()
        {
            string filePath = Path.Combine(sourceDirectoryPath, Path.GetRandomFileName() + ".jpg");

            UnsupportedFileFoundEventArgs receivedEventArgs = null;

            organizer.JPGFileFoundEvent         += (object organizer, JPGFileFoundEventArgs e) => { throw new UnsupportedJPGFileException(); };
            organizer.UnsupportedFileFoundEvent += (object organizer, UnsupportedFileFoundEventArgs e) => { receivedEventArgs = e; };

            exposedOrganizer.Invoke("ProcessFile", filePath);

            Assert.AreEqual(filePath, receivedEventArgs.FilePath);
            Assert.AreEqual(destinationDirectoryPath, receivedEventArgs.DestinationDirectoryPath);
        }
        public void HandleUnsupportedFileFoundEventShouldSucceedWhenEventIsFired()
        {
            string fileName       = Path.GetRandomFileName();
            string sourceFilePath = Path.Combine(sourceDirectoryPath, fileName);

            using (StreamWriter streamWriter = File.CreateText(sourceFilePath))
            {
                streamWriter.WriteLine(Path.GetRandomFileName());
            }

            UnsupportedFileFoundEventArgs args = new UnsupportedFileFoundEventArgs(sourceFilePath, destinationDirectoryPath);

            exposedHandler.Invoke("HandleUnsupportedFileFoundEvent", organizer, args);

            string fileDestinationPath = Path.Combine(destinationDirectoryPath, fileName);

            Assert.IsTrue(File.Exists(fileDestinationPath));
        }