DlnaManagerTests.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 jsonSerializer = new Mock<IJsonSerializer>();
  22. var appHost = new Mock<IServerApplicationHost>();
  23. return new DlnaManager(xmlSerializer.Object, fileSystem.Object, appPaths.Object, loggerFactory.Object, jsonSerializer.Object, appHost.Object);
  24. }
  25. [Fact]
  26. public void IsMatch_GivenMatchingName_ReturnsTrue()
  27. {
  28. var device = new DeviceInfo()
  29. {
  30. Name = "My Device",
  31. Manufacturer = "LG Electronics",
  32. ManufacturerUrl = "http://www.lge.com",
  33. ModelDescription = "LG WebOSTV DMRplus",
  34. ModelName = "LG TV",
  35. ModelNumber = "1.0",
  36. };
  37. var profile = new DeviceProfile()
  38. {
  39. Name = "Test Profile",
  40. FriendlyName = "My Device",
  41. Manufacturer = "LG Electronics",
  42. ManufacturerUrl = "http://www.lge.com",
  43. ModelDescription = "LG WebOSTV DMRplus",
  44. ModelName = "LG TV",
  45. ModelNumber = "1.0",
  46. Identification = new ()
  47. {
  48. FriendlyName = "My Device",
  49. Manufacturer = "LG Electronics",
  50. ManufacturerUrl = "http://www.lge.com",
  51. ModelDescription = "LG WebOSTV DMRplus",
  52. ModelName = "LG TV",
  53. ModelNumber = "1.0",
  54. }
  55. };
  56. var profile2 = new DeviceProfile()
  57. {
  58. Name = "Test Profile",
  59. FriendlyName = "My Device",
  60. Identification = new DeviceIdentification()
  61. {
  62. FriendlyName = "My Device",
  63. }
  64. };
  65. var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile2.Identification);
  66. var deviceMatch2 = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification);
  67. Assert.True(deviceMatch);
  68. Assert.True(deviceMatch2);
  69. }
  70. [Fact]
  71. public void IsMatch_GivenNamesAndManufacturersDoNotMatch_ReturnsFalse()
  72. {
  73. var device = new DeviceInfo()
  74. {
  75. Name = "My Device",
  76. Manufacturer = "JVC"
  77. };
  78. var profile = new DeviceProfile()
  79. {
  80. Name = "Test Profile",
  81. FriendlyName = "My Device",
  82. Manufacturer = "LG Electronics",
  83. ManufacturerUrl = "http://www.lge.com",
  84. ModelDescription = "LG WebOSTV DMRplus",
  85. ModelName = "LG TV",
  86. ModelNumber = "1.0",
  87. Identification = new ()
  88. {
  89. FriendlyName = "My Device",
  90. Manufacturer = "LG Electronics",
  91. ManufacturerUrl = "http://www.lge.com",
  92. ModelDescription = "LG WebOSTV DMRplus",
  93. ModelName = "LG TV",
  94. ModelNumber = "1.0",
  95. }
  96. };
  97. var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification);
  98. Assert.False(deviceMatch);
  99. }
  100. [Fact]
  101. public void IsMatch_GivenNamesAndRegExMatch_ReturnsTrue()
  102. {
  103. var device = new DeviceInfo()
  104. {
  105. Name = "My Device"
  106. };
  107. var profile = new DeviceProfile()
  108. {
  109. Name = "Test Profile",
  110. FriendlyName = "My .*",
  111. Identification = new ()
  112. };
  113. var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification);
  114. Assert.True(deviceMatch);
  115. }
  116. }
  117. }