Browse Source

Checking for directory as well

Piotr Czajkowski 22 hours ago
parent
commit
d7186bd0c0
2 changed files with 18 additions and 3 deletions
  1. 1 1
      ProcessFiles/ProcessFiles.cs
  2. 17 2
      ProcessFilesTests/ProcessFilesTests.cs

+ 1 - 1
ProcessFiles/ProcessFiles.cs

@@ -19,7 +19,7 @@ namespace ProcessFiles
 
         private Result WhatIsIt(string path)
         {
-            if (!File.Exists(path))
+            if (!File.Exists(path) && !Directory.Exists(path))
             {
                 errors.Add($"{path} doesn't exist!");
                 return Result.Failure;

+ 17 - 2
ProcessFilesTests/ProcessFilesTests.cs

@@ -115,6 +115,21 @@ namespace ProcessFilesTests
             Assert.NotEmpty(errors);
             Assert.Empty(result);
         }
+        
+        [Fact]
+        public void ProcessDirectoryNotExistTest()
+        {
+            var result = string.Empty;
+            void TestAction(string value)
+            {
+                result = value;
+            }
+
+            var test = new ProcessFiles.ProcessFiles();
+            var errors = test.Process(["./nonExistent"], "txt", TestAction);
+            Assert.NotEmpty(errors);
+            Assert.Empty(result);
+        }
 
         [Fact]
         public void ProcessFileNotMatchExtensionTest()
@@ -158,8 +173,8 @@ namespace ProcessFilesTests
                 "txt",
                 _ => test.Process([nestedMissingPath], "txt", _ => { })).ToList();
 
-            Assert.True(errors.Exists(x => x.StartsWith($"Problem getting attributes of {missingPath}")));
-            Assert.True(errors.Exists(x => x.StartsWith($"Problem getting attributes of {nestedMissingPath}")));
+            Assert.True(errors.Exists(x => x.Equals($"{missingPath} doesn't exist!")));
+            Assert.True(errors.Exists(x => x.StartsWith($"{nestedMissingPath} doesn't exist!")));
         }
 
         [Fact]