public void FindDuplicateFilesInDirectory_DuplicatesFound_DublicateFileIsMarkedAsDuplicate()
        {
            DuplicateFileFinder duplicateFileFinder = new DuplicateFileFinder(GetMockedFileSystemWrapperWithDuplicates(directory[0]));

            var result = duplicateFileFinder.FindDuplicateFilesInDirectory(directory).Last();
            Assert.IsTrue(result.IsDuplicated);
        }
        public void CompareFiles_FilesAreNotEqual_ReturnFalse()
        {
            DuplicateFileFinder duplicateFileFinder = new DuplicateFileFinder(new FileSystemWrapperStub());

            bool result = duplicateFileFinder.CompareFiles(GetCheckFile("file1"), GetCheckFile("file2"));

            Assert.IsFalse(result);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            df = new DuplicateFileFinder();
            df.RaiseCheckedFileEvent += HandleFileChecked;
            df.RaiseStartReadingFilesEvent += HandleStartReadingFiles;
            df.RaiseEndReadingFilesEvent += HandleEndReadingFiles;

            if (args.Length == 0)
            {
                Console.WriteLine("You need to provide a directory to search.");
                return;
            }

            writeResultToFile = args.Length > 1;
            if (writeResultToFile)
                resultFilePath = args[2];

            _bw = new BackgroundWorker
            {
                WorkerReportsProgress = true,
                WorkerSupportsCancellation = true
            };

            _bw.DoWork += bw_DoWork;
            _bw.ProgressChanged += bw_ProgressChanged;
            _bw.RunWorkerCompleted += bw_RunWorkerCompleted;

            _bw.RunWorkerAsync(args[0]);

            //foreach (CheckFile file in df.FindDuplicateFilesInDirectory(args[0]).OrderBy(f => f.FileId).Where(f => f.IsDuplicated))
            //{
            //    if (args.Length == 1)
            //        Console.WriteLine(string.Format("{1} : {0}", file.FilePath, file.FileId));
            //    else if (args.Length == 2)
            //        WriteFileToTextFile(string.Format("{1} : {0}", file.FilePath, file.FileId), args[1]);
            //}
            Console.Read();
        }
 public void CompareFiles_SecondFileNotFound_ThrowsFileNotFoundException()
 {
     DuplicateFileFinder duplicateFileFinder = new DuplicateFileFinder(new FileSystemWrapperStub());
     duplicateFileFinder.CompareFiles(GetCheckFile("file"), GetCheckFile("notfile"));
 }
        public void Send_In_two_different_directories_and_both_are_searched()
        {
            var mock = new Mock<IFileSystemWrapper>();
            string directory1 = "directory1";
            string directory2 = "directory2";
            string file1 = "file1";
            string file2 = "file2";
            mock.Setup(fs => fs.GetDirectories(directory1)).Returns(new string[0]);
            mock.Setup(fs => fs.GetFiles(directory1, "*")).Returns(new string[] { file1 });
            mock.Setup(fs => fs.GetDirectories(directory2)).Returns(new string[0]);
            mock.Setup(fs => fs.GetFiles(directory2, "*")).Returns(new string[] { file2 });
            mock.Setup(fs => fs.Exists(file1)).Returns(true);
            mock.Setup(fs => fs.Exists(file2)).Returns(true);
            FileSystemWrapperStub fsw = new FileSystemWrapperStub();

            mock.Setup(fs => fs.GetFileStream(file1)).Returns(() => fsw.GetFileStream(file1));
            mock.Setup(fs => fs.GetFileStream(file2)).Returns(() => fsw.GetFileStream(file1));
            DuplicateFileFinder dff = new DuplicateFileFinder(mock.Object);

            var result = dff.FindDuplicateFilesInDirectory(new string[] {directory1, directory2});
            Assert.IsTrue(result[0].IsDuplicated, string.Format("file0: {0}, file1:{1}", result[0].FilePath, result[1].FilePath));
        }
        public void Send_In_a_directory_and_subdirectory_and_subdirectory_is_only_in_once()
        {
            var mock = new Mock<IFileSystemWrapper>();
            string directory1 = @"d:\directory1";
            string directory2 = @"d:\directory1\directory2"; ;
            string file1 = "file1";
            string file2 = "file2";
            mock.Setup(fs => fs.GetDirectories(directory1)).Returns(new string[] {directory2});
            //mock.Setup(fs => fs.GetFiles(directory1, "*")).Returns(new string[] { file1 });
            mock.Setup(fs => fs.GetDirectories(directory2)).Returns(new string[0]);
            mock.Setup(fs => fs.GetFiles(directory2, "*")).Returns(new string[] { file1 });
            mock.Setup(fs => fs.Exists(file1)).Returns(true);
            mock.Setup(fs => fs.Exists(file2)).Returns(true);
            FileSystemWrapperStub fsw = new FileSystemWrapperStub();

            mock.Setup(fs => fs.GetFileStream(file1)).Returns(() => fsw.GetFileStream(file1));
            mock.Setup(fs => fs.GetFileStream(file2)).Returns(() => fsw.GetFileStream(file2));
            DuplicateFileFinder dff = new DuplicateFileFinder(mock.Object);

            var result = dff.FindDuplicateFilesInDirectory(new string[] { directory1, directory2 });
            Assert.AreEqual(1, result.Count);
        }
        public void FindDuplicateFilesInDirectory_OnlyOneFileInFolder_ResultContainsOneCheckedFile()
        {
            var mock = new Mock<IFileSystemWrapper>();

            string file1 = "file1";

            mock.Setup(fs => fs.GetDirectories(directory[0])).Returns(new string[0]);
            mock.Setup(fs => fs.GetFiles(directory[0], "*")).Returns(new string[] { file1 });
            mock.Setup(fs => fs.Exists(file1)).Returns(true);

            DuplicateFileFinder duplicateFileFinder = new DuplicateFileFinder(mock.Object);

            var result = duplicateFileFinder.FindDuplicateFilesInDirectory(directory);
            Assert.IsTrue(result.First().Checked);
        }
        public void FindDuplicateFilesInDirectory_NoDuplicatesFound_FileIsMarkedAsNoDuplicate()
        {
            string[] directory = new string[1] {"directory1"};

            DuplicateFileFinder duplicateFileFinder = new DuplicateFileFinder(GetMockedFileSystemWrapperWithNoDuplicates(directory[0]));

            var result = duplicateFileFinder.FindDuplicateFilesInDirectory(directory).First();

            Assert.IsFalse(result.IsDuplicated);
        }