Browse Source

Let's make it reentrant

Piotr Czajkowski 8 hours ago
parent
commit
1b4ee304be

+ 4 - 2
ProcessFiles/ProcessFiles.cs

@@ -14,8 +14,8 @@ namespace ProcessFiles
 
     public class ProcessFiles
     {
-        private readonly List<string> errors = [];
-        private  readonly  List<char> invalidCharactersForExtension = ['?', '*'];
+        private List<string> errors = [];
+        private readonly List<char> invalidCharactersForExtension = ['?', '*'];
 
         private Result WhatIsIt(string path)
         {
@@ -137,6 +137,8 @@ namespace ProcessFiles
             var invalidExtensions = GetInvalidExtensions(fileExtensions);
             if (invalidExtensions.Count > 0) throw new ArgumentException($"Following extensions contain invalid characters ({string.Join(", ", invalidCharactersForExtension)}):\n{string.Join(Environment.NewLine, invalidExtensions)}");
             
+            errors = [];
+            
             foreach (var argument in arguments)
             {
                 switch (WhatIsIt(argument))

+ 0 - 16
ProcessFilesTests/ProcessFilesTests.cs

@@ -160,22 +160,6 @@ 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.Equals($"{missingPath} doesn't exist!")));
-            Assert.True(errors.Exists(x => x.StartsWith($"{nestedMissingPath} doesn't exist!")));
-        }
 
         [Fact]
         public void ProcessDirectoryEnumerationFailureShouldBeReportedAsError()

+ 1 - 1
ProcessFilesTests/ProcessFilesTests.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>net10.0</TargetFramework>
-
+  <Nullable>enable</Nullable>
     <IsPackable>false</IsPackable>
 
     <OutputType>Library</OutputType>