diff --git a/README.md b/README.md index c916215..a211f52 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,9 @@ To use this helper - register `IFileIO` is your `DI` with `FileIO` as the implme - ReadAllText (path) - FileExists(path) - WriteAllLines(path, lines) -- DeleteFile(path) +- DeleteFile(path) +- CreateDirectory (path) +- DeleteDirectory (path) # Extension Methods @@ -82,5 +84,6 @@ Merges to `main` publish to nuget as a major release. # Change Log - 1.1.0 - added IList.AddRange extension method - 1.2.0 - never published - only preview -- 1.3.0 - added IFileIO - an interface + implementation for making common filesystem opperations easier to test -- 1.3.1 - suppressed some test warnings and updated the GH workflows +- 1.3.0 - added `IFileIO` - an interface + implementation for making common filesystem opperations easier to test +- 1.3.1 - suppressed some test warnings and updated the GH workflows +- 1.4.0 - added `CreatedDiretory` and `DeleteDirectory` to `IFileIO` diff --git a/src/ExtensionTests/FileIOTests.cs b/src/ExtensionTests/FileIOTests.cs index acad5b1..2e4cf80 100644 --- a/src/ExtensionTests/FileIOTests.cs +++ b/src/ExtensionTests/FileIOTests.cs @@ -68,10 +68,6 @@ public void FilesExists_DoesNotExist() result.Should().BeFalse(); } - - //Need WriteAllLines - //Need DeleteFile - [Fact] public void WriteAllLines_withDeleteFile() { @@ -114,4 +110,33 @@ public void WriteAllLines_withDeleteFile() var confirmDelete = _files.FileExists(target); confirmDelete.Should().BeFalse(); } + + [Fact] + public void DirectoryTests() + { + var basePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create); + var TestDir = "TestIODir"; + var dirPath = Path.Combine(basePath, TestDir); + + var exists = _files.DirectoryExists(dirPath); + if(exists) + { + _files.DeleteDirectory(dirPath); + exists = _files.DirectoryExists(dirPath); + } + // Comnfirm Starting State + exists.Should().BeFalse(); + + // Create + _files.CreateDirectory(dirPath); + exists = _files.DirectoryExists(dirPath); + + // Confim Creation + exists.Should().BeTrue(); + + // CleanUp and Confim Delete + _files.DeleteDirectory(dirPath); + exists = _files.DirectoryExists(dirPath); + exists.Should().BeFalse(); + } } diff --git a/src/Extensions/Extensions.csproj b/src/Extensions/Extensions.csproj index c18fed1..5b6c251 100644 --- a/src/Extensions/Extensions.csproj +++ b/src/Extensions/Extensions.csproj @@ -10,7 +10,7 @@ Debug;Release;NET7 Calebs.Extensions Calebs.Extensions - 1.3.1 + 1.4.0 true Caleb Jenkins Caleb Jenkins diff --git a/src/Extensions/SystemIO/IFileIO.cs b/src/Extensions/SystemIO/IFileIO.cs index b7dc1d3..63383e4 100644 --- a/src/Extensions/SystemIO/IFileIO.cs +++ b/src/Extensions/SystemIO/IFileIO.cs @@ -10,11 +10,13 @@ namespace Calebs.Extensions.SystemIO; /// public interface IFileIO { + bool FileExists(string path) => File.Exists(path); + void DeleteFile(string path) => File.Delete(path); + string ReadAllText (string path) => File.ReadAllText(path); + void WriteAllLines(string path, IEnumerable lines) => File.WriteAllLines(path, lines); string[] GetFiles(string path, string filter = "") => Directory.GetFiles(path, filter); bool DirectoryExists(string path) => Directory.Exists(path); string GetDirectoryName(string path) => Path.GetDirectoryName(path); - string ReadAllText (string path) => File.ReadAllText(path); - bool FileExists(string path) => File.Exists(path); - void WriteAllLines(string path, IEnumerable lines) => File.WriteAllLines(path, lines); - void DeleteFile(string path) => File.Delete(path); + void CreateDirectory(string path) => Directory.CreateDirectory(path); + void DeleteDirectory (string path) => Directory.Delete(path); }