2
0

PathExtensionsTests.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. public void TryReplaceSubPath_ValidArgs_Correct(string path, string subPath, string newSubPath, string? expectedResult)
  34. {
  35. Assert.True(PathExtensions.TryReplaceSubPath(path, subPath, newSubPath, out var result));
  36. Assert.Equal(expectedResult, result);
  37. }
  38. [Theory]
  39. [InlineData("", "", "")]
  40. [InlineData("/my/path", "", "")]
  41. [InlineData("", "/another/path", "")]
  42. [InlineData("", "", "/new/subpath")]
  43. [InlineData("/home/jeff/music/jeff's band/consistently inconsistent.mp3", "/home/jeff/music/not jeff's band", "/home/not jeff")]
  44. public void TryReplaceSubPath_InvalidInput_ReturnsFalseAndNull(string path, string subPath, string newSubPath)
  45. {
  46. Assert.False(PathExtensions.TryReplaceSubPath(path, subPath, newSubPath, out var result));
  47. Assert.Null(result);
  48. }
  49. }
  50. }