Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version bump to 1.4 #22

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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`
33 changes: 29 additions & 4 deletions src/ExtensionTests/FileIOTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ public void FilesExists_DoesNotExist()
result.Should().BeFalse();
}


//Need WriteAllLines
//Need DeleteFile

[Fact]
public void WriteAllLines_withDeleteFile()
{
Expand Down Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion src/Extensions/Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Configurations>Debug;Release;NET7</Configurations>
<RootNamespace>Calebs.Extensions</RootNamespace>
<AssemblyName>Calebs.Extensions</AssemblyName>
<Version>1.3.1</Version>
<Version>1.4.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Caleb Jenkins</Authors>
<Company>Caleb Jenkins</Company>
Expand Down
10 changes: 6 additions & 4 deletions src/Extensions/SystemIO/IFileIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ namespace Calebs.Extensions.SystemIO;
/// </summary>
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<string> 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<string> 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);
}