diff --git a/Sources/Directory.Build.props b/Sources/Directory.Build.props index 1008e2c..f9f53e0 100644 --- a/Sources/Directory.Build.props +++ b/Sources/Directory.Build.props @@ -14,7 +14,7 @@ https://github.com/kysect/Kysect.CommonLib https://github.com/kysect/Kysect.CommonLib - 0.1.20 + 0.1.21 diff --git a/Sources/Kysect.CommonLib.Testing/TestTemporaryDirectory.cs b/Sources/Kysect.CommonLib.Testing/TestTemporaryDirectory.cs index 04ce132..45a28e9 100644 --- a/Sources/Kysect.CommonLib.Testing/TestTemporaryDirectory.cs +++ b/Sources/Kysect.CommonLib.Testing/TestTemporaryDirectory.cs @@ -14,7 +14,7 @@ public TestTemporaryDirectory(System.IO.Abstractions.FileSystem fileSystem, stri _fileSystem = fileSystem.ThrowIfNull(); rootPath.ThrowIfNull(); - string path = _fileSystem.Path.Combine(rootPath, "TempDirectory", Guid.NewGuid().ToString()); + string path = _fileSystem.Path.Combine(rootPath, "Temp", GetRandomDirectoryName()); if (_fileSystem.Directory.Exists(path)) { @@ -28,7 +28,7 @@ public TestTemporaryDirectory(System.IO.Abstractions.FileSystem fileSystem, stri public string GetTemporaryDirectory() { - return _fileSystem.Path.Combine(_directoryInfo.FullName, Guid.NewGuid().ToString()); + return _fileSystem.Path.Combine(_directoryInfo.FullName, GetRandomDirectoryName()); } public void Dispose() @@ -64,4 +64,9 @@ public static void DeleteRecursive(IDirectoryInfo target) target.Delete(); } + + private string GetRandomDirectoryName() + { + return Guid.NewGuid().ToString().Substring(0, 8); + } } \ No newline at end of file diff --git a/Sources/Kysect.CommonLib.Tests/Kysect.CommonLib.Tests.csproj b/Sources/Kysect.CommonLib.Tests/Kysect.CommonLib.Tests.csproj index fa1f0c3..92ce03c 100644 --- a/Sources/Kysect.CommonLib.Tests/Kysect.CommonLib.Tests.csproj +++ b/Sources/Kysect.CommonLib.Tests/Kysect.CommonLib.Tests.csproj @@ -24,6 +24,7 @@ + \ No newline at end of file diff --git a/Sources/Kysect.CommonLib.Tests/Testing/TestTemporaryDirectoryTests.cs b/Sources/Kysect.CommonLib.Tests/Testing/TestTemporaryDirectoryTests.cs new file mode 100644 index 0000000..7ffdca0 --- /dev/null +++ b/Sources/Kysect.CommonLib.Tests/Testing/TestTemporaryDirectoryTests.cs @@ -0,0 +1,24 @@ +using FluentAssertions; +using Kysect.CommonLib.Testing; + +namespace Kysect.CommonLib.Tests.Testing; + +public class TestTemporaryDirectoryTests +{ + /// + /// We use this method during testing of git clone and get VERY LONG path. GitHub may fail with + /// LibGit2Sharp.LibGit2SharpException : path too long: 'D:/a/GithubUtils/GithubUtils/Sources/artifacts/bin/Kysect.GithubUtils.Tests/release/TempDirectory/0d339f96-3146-42ff-84ee-d2534af2c84b/80ec70c9-6afa-413b-b3af-ac6ecc10aa8f/Sources/Kysect.GithubUtils/Contributions/ActivityProviders/GithubActivityProviderExtensions.cs + /// + [Fact] + public void GetTemporaryDirectory_ReturnStringDoNotLong() + { + var fileSystem = new System.IO.Abstractions.FileSystem(); + string baseDirectoryPath = fileSystem.Path.GetFullPath("."); + using var temporaryDirectory = new TestTemporaryDirectory(fileSystem); + + string directoryPath = temporaryDirectory.GetTemporaryDirectory(); + int additionalLength = directoryPath.Length - baseDirectoryPath.Length; + + additionalLength.Should().BeLessThan(25); + } +} \ No newline at end of file