diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-06-08 23:07:56 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-08 23:07:56 -0500 |
| commit | 2a41aae31033a52515cd8fab0b1c40e55c6e0bd3 (patch) | |
| tree | d5f25c2f87025ed6c4791ac8bb54ad806d1fe0b7 /tests | |
| parent | 83391ed8a632aa362db837dd41ea7b945e829741 (diff) | |
| parent | b6740dc7368170205722caf45802ec17dcc3c902 (diff) | |
| download | slskd-2a41aae31033a52515cd8fab0b1c40e55c6e0bd3.tar.gz | |
Merge pull request #504 from slskd/bugfix
Fix bug downloading files from the root of a share
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/slskd.Tests.Unit/Common/Extensions/ToLocalRelativeFilenameTests.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/slskd.Tests.Unit/Common/Extensions/ToLocalRelativeFilenameTests.cs b/tests/slskd.Tests.Unit/Common/Extensions/ToLocalRelativeFilenameTests.cs new file mode 100644 index 00000000..c3eb5696 --- /dev/null +++ b/tests/slskd.Tests.Unit/Common/Extensions/ToLocalRelativeFilenameTests.cs @@ -0,0 +1,53 @@ +namespace slskd.Tests.Unit.Common.Extensions +{ + using System; + using Xunit; + + public class ToLocalRelativeFilenameTests + { + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData("\t")] + public void Throws_ArgumentException_Given_Bad_Remote_Filename(string filename) + { + var ex = Record.Exception(() => filename.ToLocalRelativeFilename()); + + Assert.NotNull(ex); + Assert.IsType<ArgumentException>(ex); + } + + [Fact] + public void Returns_Localized_Filename_And_Parent_Directory() + { + if (Environment.OSVersion.Platform == PlatformID.Win32NT) + { + Assert.Equal(@"path\file.ext", "deeply/nested/path/file.ext".ToLocalRelativeFilename()); + } + else + { + Assert.Equal(@"path/file.ext", @"C:\deeply\nested\path\file.ext".ToLocalRelativeFilename()); + } + + } + + [Fact] + public void Returns_Just_File_If_Only_File_Given() + { + Assert.Equal("file.ext", "file.ext".ToLocalRelativeFilename()); + } + + [Fact] + public void Removes_Invalid_Characters_From_Path_And_Filename() + { + if (Environment.OSVersion.Platform == PlatformID.Win32NT) + { + Assert.Equal(@"p_a_t_h\fi_le.ext", @"p?a|t<h/fi>le.ext".ToLocalRelativeFilename()); + } + else + { + Assert.Equal(@"_", $"{'\0'}".ToLocalRelativeFilename()); + } + } + } +} |
