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)); }
private IFileSystemWrapper GetMockedFileSystemWrapperWithNoDuplicates(string directory) { var mock = new Mock<IFileSystemWrapper>(); string file1 = "file1"; string file2 = "file2"; mock.Setup(fs => fs.GetDirectories(directory)).Returns(new string[0]); mock.Setup(fs => fs.GetFiles(directory, "*")).Returns(new string[] { file1, 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(file2)); return mock.Object; }
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); }