Browse Source

The more tests the better

Piotr Czajkowski 4 days ago
parent
commit
8950d8701b
1 changed files with 31 additions and 0 deletions
  1. 31 0
      ProcessFilesTests/ProcessFilesTests.cs

+ 31 - 0
ProcessFilesTests/ProcessFilesTests.cs

@@ -1,5 +1,6 @@
 using System.Collections.Generic;
 using System.IO;
+using System.Linq;
 using Xunit;
 
 namespace ProcessFilesTests
@@ -143,5 +144,35 @@ namespace ProcessFilesTests
             Assert.Empty(errors);
             Assert.True(CheckResult(result, expectedInSubFolderMultipleExtensions));
         }
+        
+        [Fact]
+        public void ProcessWhenActionInvokesProcessShouldPreserveOuterErrors()
+        {
+            var missingPath = Path.Combine(testFolder, "missing.txt");
+            var nestedMissingPath = Path.Combine(testFolder, "nested-missing.txt");
+
+            var test = new ProcessFiles.ProcessFiles();
+            var errors = test.Process(
+                [missingPath, testFile],
+                "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}")));
+        }
+
+        [Fact]
+        public void ProcessDirectoryEnumerationFailureShouldBeReportedAsError()
+        {
+            var test = new ProcessFiles.ProcessFiles();
+            var errors = test.Process(
+                [testFolder],
+                ["txt["], // invalid search pattern forces Directory.GetFiles to throw
+                _ => { }).ToList();
+
+            Assert.Single(errors);
+            Assert.Contains(testFolder, errors[0]);
+            Assert.Contains("txt[", errors[0]);
+        }
     }
 }