public void SearchWithSameNames_InEmptyDir_NoResults()
 {
     // Arrange
     var filesFinder = new FilesFinder();
     // Act
     var result = filesFinder.SearchWithSameNames(Path.Combine(RootTestDir, "Empty"));
     // Assert
     Assert.AreEqual(0, result.Count, "No files expected in empty directory");
 }
 public void SearchWithSameNames_InDirWithDistinctFiles_NoResults()
 {
     // Arrange
     var filesFinder = new FilesFinder();
     // Act
     var result = filesFinder.SearchWithSameNames(Path.Combine(RootTestDir, "NoFilesWithSameName"));
     // Assert
     Assert.AreEqual(0, result.Count, "No files expected");
 }
 public void SearchWithSameNames_InDirWith2SameFiles_1Result()
 {
     // Arrange
     var filesFinder = new FilesFinder();
     // Act
     var result = filesFinder.SearchWithSameNames(Path.Combine(RootTestDir, "HasFilesWithSameName"));
     // Assert
     Assert.AreEqual(1, result.Count);
     Assert.AreEqual("a.txt", result[0].FileName);
     Assert.AreEqual(2, result[0].Count);
 }
 public void UnauthorizedAccessExceptionThrown_ErrorRegistered()
 {
     // Arrange
     var dirServiceStub = new Moq.Mock<IDirService>();
     dirServiceStub.Setup(s => s.DirectoryExists(Moq.It.IsAny<string>())).Returns(true);
     dirServiceStub.Setup(s => s.GetDirectories("a")).Throws<UnauthorizedAccessException>();
     var filesFinder = new FilesFinder(dirServiceStub.Object);
     // Act
     filesFinder.SearchWithSameNames("a");
     // Assert
     Assert.AreEqual(1, filesFinder.GetLastErrors().Count);
 }
 public void PassingNull_ThrowsArgumentNullException()
 {
     var filesFinder = new FilesFinder(new DirServiceStub());
     Assert.Throws<ArgumentNullException>(() => filesFinder.SearchWithSameNames(null));
 }
 public void PassingNonExistingDirectory_RegistersError__MoqStub()
 {
     // Arrange
     var dirServiceStub = new Moq.Mock<IDirService>();
     dirServiceStub.Setup(s => s.DirectoryExists("NonExisting")).Returns(false);
     var filesFinder = new FilesFinder(dirServiceStub.Object);
     // Act
     filesFinder.SearchWithSameNames("NonExisting");
     // Assert
     Assert.AreEqual(1, filesFinder.GetLastErrors().Count, "Non existing directory error expected");
 }
 public void PassingNonExistingDirectory_RegistersError__CustomStub()
 {
     // Arrange
     var dirService = new DirServiceStub();
     dirService.DirectoryExistsResult = false;
     var filesFinder = new FilesFinder(dirService);
     // Act
     filesFinder.SearchWithSameNames("NonExisting");
     // Assert
     Assert.AreEqual(1, filesFinder.GetLastErrors().Count, "Non existing directory error expected");
 }
 public void InEmptyDir_NoResults__MoqStub()
 {
     // Arrange
     var dirServiceStub = new Moq.Mock<IDirService>();
     dirServiceStub.Setup(s => s.DirectoryExists("Empty")).Returns(true);
     var filesFinder = new FilesFinder(dirServiceStub.Object);
     // Act
     var result = filesFinder.SearchWithSameNames("Empty");
     // Assert
     Assert.AreEqual(0, result.Count, "No files expected in empty directory");
 }
 public void InEmptyDir_NoResults__CustomStub()
 {
     // Arrange
     var dirService = new DirServiceStub();
     dirService.DirectoryExistsResult = true;
     dirService.GetFilesResult = new string[0];
     dirService.GetDirectoriesResult = new string[0];
     var filesFinder = new FilesFinder(dirService);
     // Act
     var result = filesFinder.SearchWithSameNames("Empty");
     // Assert
     Assert.AreEqual(0, result.Count, "No files expected in empty directory");
 }
 public void InDirWithDistinctFiles_NoResults()
 {
     // Arrange
     var dirServiceStub = new Moq.Mock<IDirService>();
     dirServiceStub.Setup(s => s.DirectoryExists("A")).Returns(true);
     dirServiceStub.Setup(s => s.GetFiles("A")).Returns(new[] {@"A\1.txt", @"A\2.txt"});
     var filesFinder = new FilesFinder(dirServiceStub.Object);
     // Act
     var result = filesFinder.SearchWithSameNames("A");
     // Assert
     Assert.AreEqual(0, result.Count, "No files expected");
 }
 public void InDirWith2SameFiles_1Result()
 {
     // Arrange
     var dirServiceStub = new Moq.Mock<IDirService>();
     dirServiceStub.Setup(s => s.DirectoryExists("A")).Returns(true);
     dirServiceStub.Setup(s => s.GetDirectories("A")).Returns(new[] {@"A\B"});
     dirServiceStub.Setup(s => s.GetFiles("A")).Returns(new[] { @"A\1.txt", @"A\2.txt" });
     dirServiceStub.Setup(s => s.DirectoryExists(@"A\B")).Returns(true);
     dirServiceStub.Setup(s => s.GetFiles(@"A\B")).Returns(new[] { @"A\B\1.txt" });
     var filesFinder = new FilesFinder(dirServiceStub.Object);
     // Act
     var result = filesFinder.SearchWithSameNames("A");
     // Assert
     Assert.AreEqual(1, result.Count);
     Assert.AreEqual("1.txt", result[0].FileName);
     Assert.AreEqual(2, result[0].Count);
 }
 public void InDirWith2SameFilesButDifferentCase_1Result()
 {
     // Arrange
     var dirService = new DirServiceSmartStub(@"
     A\x.txt
     A\y.txt
     A\B\X.txt
     ");
     var filesFinder = new FilesFinder(dirService);
     // Act
     var result = filesFinder.SearchWithSameNames("A");
     // Assert
     Assert.AreEqual(1, result.Count);
     Assert.AreEqual("x.txt", result[0].FileName);
     Assert.AreEqual(2, result[0].Count);
 }
        public void InDirWith2Plus2SameFiles_2Results()
        {
            // Arrange
            var dirService = new DirServiceSmartStub(@"
            a\1.txt
            a\2.txt
            a\b\1.txt
            a\b\2.txt
            a\b\c\2.txt
            ");
            var filesFinder = new FilesFinder(dirService);
            // Act
            var result = filesFinder.SearchWithSameNames("a");
            // Assert
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual("1.txt", result[0].FileName);
            Assert.AreEqual(2, result[0].Count);

            Assert.AreEqual("2.txt", result[1].FileName);
            Assert.AreEqual(3, result[1].Count);
        }
 public void SearchWithSameNames_PassingNonExistingDirectory_RegistersError()
 {
     // Arrange
     var filesFinder = new FilesFinder();
     // Act
     string nonExistingDir = Path.Combine(RootTestDir, "NonExisting");
     filesFinder.SearchWithSameNames(nonExistingDir);
     // Assert
     Assert.AreEqual(1, filesFinder.GetLastErrors().Count, "Non existing directory error expected");
 }