-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
61 additions
and
26 deletions.
There are no files selected for viewing
10 changes: 4 additions & 6 deletions
10
tests/Workleap.DotNet.CodingStandards.Tests/Helpers/PathHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/Workleap.DotNet.CodingStandards.Tests/Helpers/TemporaryDirectory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace Workleap.DotNet.CodingStandards.Tests.Helpers; | ||
|
||
internal sealed class TemporaryDirectory : IDisposable | ||
{ | ||
private TemporaryDirectory(string fullPath) => FullPath = fullPath; | ||
|
||
public string FullPath { get; } | ||
|
||
public static TemporaryDirectory Create() | ||
{ | ||
var path = Path.GetFullPath(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"))); | ||
Directory.CreateDirectory(path); | ||
return new TemporaryDirectory(path); | ||
} | ||
|
||
public string GetPath(string relativePath) | ||
{ | ||
return Path.Combine(FullPath, relativePath); | ||
} | ||
|
||
public void CreateTextFile(string relativePath, string content) | ||
{ | ||
var path = GetPath(relativePath); | ||
Directory.CreateDirectory(Path.GetDirectoryName(path)); | ||
File.WriteAllText(path, content); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
try | ||
{ | ||
Directory.Delete(FullPath, recursive: true); | ||
} | ||
catch | ||
{ | ||
// We use this code in tests, so it's not important if a folder cannot be deleted | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters