Browse Source

Added GetAttributes

Piotr Czajkowski 5 months ago
parent
commit
2de6d9d006

+ 4 - 1
ProcessFiles/Interfaces/IFile.cs

@@ -1,6 +1,9 @@
-namespace ProcessFiles.Interfaces
+using System.IO;
+
+namespace ProcessFiles.Interfaces
 {
     public interface IFile
     {
+        public FileAttributes GetAttributes(string path);
     }
 }

+ 1 - 1
ProcessFiles/Interfaces/IFileSystem.cs

@@ -2,6 +2,6 @@
 {
     public interface IFileSystem
     {
-        public IFile File { get; set; }
+        public IFile File { get; }
     }
 }

+ 10 - 0
ProcessFiles/Models/DefaultFile.cs

@@ -0,0 +1,10 @@
+using ProcessFiles.Interfaces;
+using System.IO;
+
+namespace ProcessFiles.Models
+{
+    public class DefaultFile : IFile
+    {
+        public FileAttributes GetAttributes(string path) => File.GetAttributes(path);
+    }
+}

+ 10 - 0
ProcessFiles/Models/DefaultFileSystem.cs

@@ -0,0 +1,10 @@
+using ProcessFiles.Interfaces;
+
+namespace ProcessFiles.Models
+{
+    public class DefaultFileSystem : IFileSystem
+    {
+        private readonly IFile file = new DefaultFile();
+        public IFile File => file;
+    }
+}

+ 2 - 2
ProcessFiles/ProcessFiles.cs

@@ -8,14 +8,14 @@ namespace ProcessFiles
 {
     public class ProcessFiles(IFileSystem? fileSystem = null)
     {
-        private readonly IFileSystem? fileSystem = fileSystem;
+        private readonly IFileSystem fileSystem = fileSystem ?? new DefaultFileSystem();
         private List<string> errors = [];
 
         private Result WhatIsIt(string path)
         {
             try
             {
-                var attr = File.GetAttributes(path);
+                var attr = fileSystem.File.GetAttributes(path);
                 if (attr.HasFlag(FileAttributes.Directory))
                     return Result.Directory;