PathExtensionsTests.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using Emby.Server.Implementations.Library;
  3. using Xunit;
  4. namespace Jellyfin.Server.Implementations.Tests.Library
  5. {
  6. public class PathExtensionsTests
  7. {
  8. [Theory]
  9. [InlineData("Superman: Red Son [imdbid=tt10985510]", "imdbid", "tt10985510")]
  10. [InlineData("Superman: Red Son - tt10985510", "imdbid", "tt10985510")]
  11. [InlineData("Superman: Red Son", "imdbid", null)]
  12. [InlineData("Superman: Red Son", "something", null)]
  13. public void GetAttributeValue_ValidArgs_Correct(string input, string attribute, string? expectedResult)
  14. {
  15. Assert.Equal(expectedResult, PathExtensions.GetAttributeValue(input, attribute));
  16. }
  17. [Theory]
  18. [InlineData("", "")]
  19. [InlineData("Superman: Red Son [imdbid=tt10985510]", "")]
  20. [InlineData("", "imdbid")]
  21. public void GetAttributeValue_EmptyString_ThrowsArgumentException(string input, string attribute)
  22. {
  23. Assert.Throws<ArgumentException>(() => PathExtensions.GetAttributeValue(input, attribute));
  24. }
  25. [Theory]
  26. [InlineData("C:/Users/jeff/myfile.mkv", "C:/Users/jeff", "/home/jeff", "/home/jeff/myfile.mkv")]
  27. [InlineData("C:/Users/jeff/myfile.mkv", "C:/Users/jeff/", "/home/jeff", "/home/jeff/myfile.mkv")]
  28. [InlineData("/home/jeff/music/jeff's band/consistently inconsistent.mp3", "/home/jeff/music/jeff's band", "/home/not jeff", "/home/not jeff/consistently inconsistent.mp3")]
  29. [InlineData("C:\\Users\\jeff\\myfile.mkv", "C:\\Users/jeff", "/home/jeff", "/home/jeff/myfile.mkv")]
  30. [InlineData("C:\\Users\\jeff\\myfile.mkv", "C:\\Users/jeff", "/home/jeff/", "/home/jeff/myfile.mkv")]
  31. [InlineData("C:\\Users\\jeff\\myfile.mkv", "C:\\Users/jeff/", "/home/jeff/", "/home/jeff/myfile.mkv")]
  32. [InlineData("C:\\Users\\jeff\\myfile.mkv", "C:\\Users/jeff/", "/", "/myfile.mkv")]
  33. [InlineData("/o", "/o", "/s", "/s")] // regression test for #5977
  34. public void TryReplaceSubPath_ValidArgs_Correct(string path, string subPath, string newSubPath, string? expectedResult)
  35. {
  36. Assert.True(PathExtensions.TryReplaceSubPath(path, subPath, newSubPath, out var result));
  37. Assert.Equal(expectedResult, result);
  38. }
  39. [Theory]
  40. [InlineData(null, null, null)]
  41. [InlineData(null, "/my/path", "/another/path")]
  42. [InlineData("/my/path", null, "/another/path")]
  43. [InlineData("/my/path", "/another/path", null)]
  44. [InlineData("", "", "")]
  45. [InlineData("/my/path", "", "")]
  46. [InlineData("", "/another/path", "")]
  47. [InlineData("", "", "/new/subpath")]
  48. [InlineData("/home/jeff/music/jeff's band/consistently inconsistent.mp3", "/home/jeff/music/not jeff's band", "/home/not jeff")]
  49. public void TryReplaceSubPath_InvalidInput_ReturnsFalseAndNull(string? path, string? subPath, string? newSubPath)
  50. {
  51. Assert.False(PathExtensions.TryReplaceSubPath(path, subPath, newSubPath, out var result));
  52. Assert.Null(result);
  53. }
  54. }
  55. }