DlnaManagerTests.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using Emby.Dlna;
  2. using Emby.Dlna.PlayTo;
  3. using MediaBrowser.Common.Configuration;
  4. using MediaBrowser.Controller;
  5. using MediaBrowser.Model.Dlna;
  6. using MediaBrowser.Model.IO;
  7. using MediaBrowser.Model.Serialization;
  8. using Microsoft.Extensions.Logging;
  9. using Moq;
  10. using Xunit;
  11. namespace Jellyfin.Dlna.Tests
  12. {
  13. public class DlnaManagerTests
  14. {
  15. private DlnaManager GetManager()
  16. {
  17. var xmlSerializer = new Mock<IXmlSerializer>();
  18. var fileSystem = new Mock<IFileSystem>();
  19. var appPaths = new Mock<IApplicationPaths>();
  20. var loggerFactory = new Mock<ILoggerFactory>();
  21. var appHost = new Mock<IServerApplicationHost>();
  22. return new DlnaManager(xmlSerializer.Object, fileSystem.Object, appPaths.Object, loggerFactory.Object, appHost.Object);
  23. }
  24. [Fact]
  25. public void IsMatch_GivenMatchingName_ReturnsTrue()
  26. {
  27. var device = new DeviceInfo()
  28. {
  29. Name = "My Device",
  30. Manufacturer = "LG Electronics",
  31. ManufacturerUrl = "http://www.lge.com",
  32. ModelDescription = "LG WebOSTV DMRplus",
  33. ModelName = "LG TV",
  34. ModelNumber = "1.0",
  35. };
  36. var profile = new DeviceProfile()
  37. {
  38. Name = "Test Profile",
  39. FriendlyName = "My Device",
  40. Manufacturer = "LG Electronics",
  41. ManufacturerUrl = "http://www.lge.com",
  42. ModelDescription = "LG WebOSTV DMRplus",
  43. ModelName = "LG TV",
  44. ModelNumber = "1.0",
  45. Identification = new()
  46. {
  47. FriendlyName = "My Device",
  48. Manufacturer = "LG Electronics",
  49. ManufacturerUrl = "http://www.lge.com",
  50. ModelDescription = "LG WebOSTV DMRplus",
  51. ModelName = "LG TV",
  52. ModelNumber = "1.0",
  53. }
  54. };
  55. var profile2 = new DeviceProfile()
  56. {
  57. Name = "Test Profile",
  58. FriendlyName = "My Device",
  59. Identification = new DeviceIdentification()
  60. {
  61. FriendlyName = "My Device",
  62. }
  63. };
  64. var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile2.Identification);
  65. var deviceMatch2 = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification);
  66. Assert.True(deviceMatch);
  67. Assert.True(deviceMatch2);
  68. }
  69. [Fact]
  70. public void IsMatch_GivenNamesAndManufacturersDoNotMatch_ReturnsFalse()
  71. {
  72. var device = new DeviceInfo()
  73. {
  74. Name = "My Device",
  75. Manufacturer = "JVC"
  76. };
  77. var profile = new DeviceProfile()
  78. {
  79. Name = "Test Profile",
  80. FriendlyName = "My Device",
  81. Manufacturer = "LG Electronics",
  82. ManufacturerUrl = "http://www.lge.com",
  83. ModelDescription = "LG WebOSTV DMRplus",
  84. ModelName = "LG TV",
  85. ModelNumber = "1.0",
  86. Identification = new()
  87. {
  88. FriendlyName = "My Device",
  89. Manufacturer = "LG Electronics",
  90. ManufacturerUrl = "http://www.lge.com",
  91. ModelDescription = "LG WebOSTV DMRplus",
  92. ModelName = "LG TV",
  93. ModelNumber = "1.0",
  94. }
  95. };
  96. var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification);
  97. Assert.False(deviceMatch);
  98. }
  99. [Fact]
  100. public void IsMatch_GivenNamesAndRegExMatch_ReturnsTrue()
  101. {
  102. var device = new DeviceInfo()
  103. {
  104. Name = "My Device"
  105. };
  106. var profile = new DeviceProfile()
  107. {
  108. Name = "Test Profile",
  109. FriendlyName = "My .*",
  110. Identification = new()
  111. };
  112. var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification);
  113. Assert.True(deviceMatch);
  114. }
  115. }
  116. }