Skip to content

Commit a99311b

Browse files
committed
Version bump to 1.4 - added CreateDiretory and DeleteDirectory to IFileIO
1 parent 68b4381 commit a99311b

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ To use this helper - register `IFileIO` is your `DI` with `FileIO` as the implme
4343
- ReadAllText (path)
4444
- FileExists(path)
4545
- WriteAllLines(path, lines)
46-
- DeleteFile(path)
46+
- DeleteFile(path)
47+
- CreateDirectory (path)
48+
- DeleteDirectory (path)
4749

4850
# Extension Methods
4951

@@ -82,5 +84,6 @@ Merges to `main` publish to nuget as a major release.
8284
# Change Log
8385
- 1.1.0 - added IList.AddRange extension method
8486
- 1.2.0 - never published - only preview
85-
- 1.3.0 - added IFileIO - an interface + implementation for making common filesystem opperations easier to test
86-
- 1.3.1 - suppressed some test warnings and updated the GH workflows
87+
- 1.3.0 - added `IFileIO` - an interface + implementation for making common filesystem opperations easier to test
88+
- 1.3.1 - suppressed some test warnings and updated the GH workflows
89+
- 1.4.0 - added `CreatedDiretory` and `DeleteDirectory` to `IFileIO`

src/ExtensionTests/FileIOTests.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ public void FilesExists_DoesNotExist()
6868
result.Should().BeFalse();
6969
}
7070

71-
72-
//Need WriteAllLines
73-
//Need DeleteFile
74-
7571
[Fact]
7672
public void WriteAllLines_withDeleteFile()
7773
{
@@ -114,4 +110,33 @@ public void WriteAllLines_withDeleteFile()
114110
var confirmDelete = _files.FileExists(target);
115111
confirmDelete.Should().BeFalse();
116112
}
113+
114+
[Fact]
115+
public void DirectoryTests()
116+
{
117+
var basePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create);
118+
var TestDir = "TestIODir";
119+
var dirPath = Path.Combine(basePath, TestDir);
120+
121+
var exists = _files.DirectoryExists(dirPath);
122+
if(exists)
123+
{
124+
_files.DeleteDirectory(dirPath);
125+
exists = _files.DirectoryExists(dirPath);
126+
}
127+
// Comnfirm Starting State
128+
exists.Should().BeFalse();
129+
130+
// Create
131+
_files.CreateDirectory(dirPath);
132+
exists = _files.DirectoryExists(dirPath);
133+
134+
// Confim Creation
135+
exists.Should().BeTrue();
136+
137+
// CleanUp and Confim Delete
138+
_files.DeleteDirectory(dirPath);
139+
exists = _files.DirectoryExists(dirPath);
140+
exists.Should().BeFalse();
141+
}
117142
}

src/Extensions/Extensions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Configurations>Debug;Release;NET7</Configurations>
1111
<RootNamespace>Calebs.Extensions</RootNamespace>
1212
<AssemblyName>Calebs.Extensions</AssemblyName>
13-
<Version>1.3.1</Version>
13+
<Version>1.4.0</Version>
1414
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1515
<Authors>Caleb Jenkins</Authors>
1616
<Company>Caleb Jenkins</Company>

src/Extensions/SystemIO/IFileIO.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ namespace Calebs.Extensions.SystemIO;
1010
/// </summary>
1111
public interface IFileIO
1212
{
13+
bool FileExists(string path) => File.Exists(path);
14+
void DeleteFile(string path) => File.Delete(path);
15+
string ReadAllText (string path) => File.ReadAllText(path);
16+
void WriteAllLines(string path, IEnumerable<string> lines) => File.WriteAllLines(path, lines);
1317
string[] GetFiles(string path, string filter = "") => Directory.GetFiles(path, filter);
1418
bool DirectoryExists(string path) => Directory.Exists(path);
1519
string GetDirectoryName(string path) => Path.GetDirectoryName(path);
16-
string ReadAllText (string path) => File.ReadAllText(path);
17-
bool FileExists(string path) => File.Exists(path);
18-
void WriteAllLines(string path, IEnumerable<string> lines) => File.WriteAllLines(path, lines);
19-
void DeleteFile(string path) => File.Delete(path);
20+
void CreateDirectory(string path) => Directory.CreateDirectory(path);
21+
void DeleteDirectory (string path) => Directory.Delete(path);
2022
}

0 commit comments

Comments
 (0)