From 53e1b302cc08181c7909719df0cd837fd4b182f4 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Wed, 21 Apr 2021 10:18:29 +0100 Subject: Changes as requested --- Emby.Dlna/DlnaManager.cs | 14 +-- tests/Jellyfin.Dlna.Tests/DlnaManagerTests.cs | 130 ++++++++++++++++++++++++++ tests/Jellyfin.Dlna.Tests/ProfileTester.cs | 107 --------------------- 3 files changed, 137 insertions(+), 114 deletions(-) create mode 100644 tests/Jellyfin.Dlna.Tests/DlnaManagerTests.cs delete mode 100644 tests/Jellyfin.Dlna.Tests/ProfileTester.cs diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.cs index 57a6c20598..5f2be07cf3 100644 --- a/Emby.Dlna/DlnaManager.cs +++ b/Emby.Dlna/DlnaManager.cs @@ -150,13 +150,13 @@ namespace Emby.Dlna public bool IsMatch(DeviceIdentification deviceInfo, DeviceIdentification profileInfo) { return IsRegexOrSubstringMatch(deviceInfo.FriendlyName, profileInfo.FriendlyName) - && IsRegexOrSubstringMatch(deviceInfo.Manufacturer, profileInfo.Manufacturer) - && IsRegexOrSubstringMatch(deviceInfo.ManufacturerUrl, profileInfo.ManufacturerUrl) - && IsRegexOrSubstringMatch(deviceInfo.ModelDescription, profileInfo.ModelDescription) - && IsRegexOrSubstringMatch(deviceInfo.ModelName, profileInfo.ModelName) - && IsRegexOrSubstringMatch(deviceInfo.ModelNumber, profileInfo.ModelNumber) - && IsRegexOrSubstringMatch(deviceInfo.ModelUrl, profileInfo.ModelUrl) - && IsRegexOrSubstringMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber); + && IsRegexOrSubstringMatch(deviceInfo.Manufacturer, profileInfo.Manufacturer) + && IsRegexOrSubstringMatch(deviceInfo.ManufacturerUrl, profileInfo.ManufacturerUrl) + && IsRegexOrSubstringMatch(deviceInfo.ModelDescription, profileInfo.ModelDescription) + && IsRegexOrSubstringMatch(deviceInfo.ModelName, profileInfo.ModelName) + && IsRegexOrSubstringMatch(deviceInfo.ModelNumber, profileInfo.ModelNumber) + && IsRegexOrSubstringMatch(deviceInfo.ModelUrl, profileInfo.ModelUrl) + && IsRegexOrSubstringMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber); } private bool IsRegexOrSubstringMatch(string input, string pattern) diff --git a/tests/Jellyfin.Dlna.Tests/DlnaManagerTests.cs b/tests/Jellyfin.Dlna.Tests/DlnaManagerTests.cs new file mode 100644 index 0000000000..087d43a779 --- /dev/null +++ b/tests/Jellyfin.Dlna.Tests/DlnaManagerTests.cs @@ -0,0 +1,130 @@ +using Emby.Dlna; +using Emby.Dlna.PlayTo; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Controller; +using MediaBrowser.Model.Dlna; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.Serialization; +using Microsoft.Extensions.Logging; +using Moq; +using Xunit; + +namespace Jellyfin.Dlna.Tests +{ + public class DlnaManagerTests + { + private DlnaManager GetManager() + { + var xmlSerializer = new Mock(); + var fileSystem = new Mock(); + var appPaths = new Mock(); + var loggerFactory = new Mock(); + var appHost = new Mock(); + + return new DlnaManager(xmlSerializer.Object, fileSystem.Object, appPaths.Object, loggerFactory.Object, appHost.Object); + } + + [Fact] + public void IsMatch_GivenMatchingName_ReturnsTrue() + { + var device = new DeviceInfo() + { + Name = "My Device", + Manufacturer = "LG Electronics", + ManufacturerUrl = "http://www.lge.com", + ModelDescription = "LG WebOSTV DMRplus", + ModelName = "LG TV", + ModelNumber = "1.0", + }; + + var profile = new DeviceProfile() + { + Name = "Test Profile", + FriendlyName = "My Device", + Manufacturer = "LG Electronics", + ManufacturerUrl = "http://www.lge.com", + ModelDescription = "LG WebOSTV DMRplus", + ModelName = "LG TV", + ModelNumber = "1.0", + Identification = new () + { + FriendlyName = "My Device", + Manufacturer = "LG Electronics", + ManufacturerUrl = "http://www.lge.com", + ModelDescription = "LG WebOSTV DMRplus", + ModelName = "LG TV", + ModelNumber = "1.0", + } + }; + + Assert.True(GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification)); + + var profile2 = new DeviceProfile() + { + Name = "Test Profile", + FriendlyName = "My Device", + Identification = new DeviceIdentification() + { + FriendlyName = "My Device", + } + }; + + var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile2.Identification); + Assert.True(deviceMatch); + } + + [Fact] + public void IsMatch_GivenNamesAndManufacturersDoNotMatch_ReturnsFalse() + { + var device = new DeviceInfo() + { + Name = "My Device", + Manufacturer = "JVC" + }; + + var profile = new DeviceProfile() + { + Name = "Test Profile", + FriendlyName = "My Device", + Manufacturer = "LG Electronics", + ManufacturerUrl = "http://www.lge.com", + ModelDescription = "LG WebOSTV DMRplus", + ModelName = "LG TV", + ModelNumber = "1.0", + Identification = new () + { + FriendlyName = "My Device", + Manufacturer = "LG Electronics", + ManufacturerUrl = "http://www.lge.com", + ModelDescription = "LG WebOSTV DMRplus", + ModelName = "LG TV", + ModelNumber = "1.0", + } + }; + + var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification); + + Assert.False(deviceMatch); + } + + [Fact] + public void IsMatch_GivenNamesAndRegExMatch_ReturnsTrue() + { + var device = new DeviceInfo() + { + Name = "My Device" + }; + + var profile = new DeviceProfile() + { + Name = "Test Profile", + FriendlyName = "My .*", + Identification = new () + }; + + var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification); + + Assert.True(deviceMatch); + } + } +} diff --git a/tests/Jellyfin.Dlna.Tests/ProfileTester.cs b/tests/Jellyfin.Dlna.Tests/ProfileTester.cs deleted file mode 100644 index 004933ca95..0000000000 --- a/tests/Jellyfin.Dlna.Tests/ProfileTester.cs +++ /dev/null @@ -1,107 +0,0 @@ -using Emby.Dlna; -using Emby.Dlna.PlayTo; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Controller; -using MediaBrowser.Model.Dlna; -using MediaBrowser.Model.IO; -using MediaBrowser.Model.Serialization; -using Microsoft.Extensions.Logging; -using Moq; -using Xunit; - -namespace Jellyfin.Dlna.Tests -{ - public class DlnaManagerTests - { - private DlnaManager GetManager() - { - var xmlSerializer = new Mock(); - var fileSystem = new Mock(); - var appPaths = new Mock(); - var loggerFactory = new Mock(); - var appHost = new Mock(); - - return new DlnaManager(xmlSerializer.Object, fileSystem.Object, appPaths.Object, loggerFactory.Object, appHost.Object); - } - - [Fact] - public void IsMatch_GivenMatchingName_ReturnsTrue() - { - var device = new DeviceInfo() - { - Name = "My Device", - Manufacturer = "LG Electronics", - ManufacturerUrl = "http://www.lge.com", - ModelDescription = "LG WebOSTV DMRplus", - ModelName = "LG TV", - ModelNumber = "1.0", - }; - - var profile = new DeviceProfile() - { - Name = "Test Profile", - FriendlyName = "My Device", - Manufacturer = "LG Electronics", - ManufacturerUrl = "http://www.lge.com", - ModelDescription = "LG WebOSTV DMRplus", - ModelName = "LG TV", - ModelNumber = "1.0", - Identification = new DeviceIdentification() - { - FriendlyName = "My Device", - Manufacturer = "LG Electronics", - ManufacturerUrl = "http://www.lge.com", - ModelDescription = "LG WebOSTV DMRplus", - ModelName = "LG TV", - ModelNumber = "1.0", - } - }; - - Assert.True(GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification)); - - var profile2 = new DeviceProfile() - { - Name = "Test Profile", - FriendlyName = "My Device", - Identification = new DeviceIdentification() - { - FriendlyName = "My Device", - } - }; - - Assert.True(GetManager().IsMatch(device.ToDeviceIdentification(), profile2.Identification)); - } - - [Fact] - public void IsMatch_GivenNamesAndManufacturersDoNotMatch_ReturnsFalse() - { - var device = new DeviceInfo() - { - Name = "My Device", - Manufacturer = "JVC" - }; - - var profile = new DeviceProfile() - { - Name = "Test Profile", - FriendlyName = "My Device", - Manufacturer = "LG Electronics", - ManufacturerUrl = "http://www.lge.com", - ModelDescription = "LG WebOSTV DMRplus", - ModelName = "LG TV", - ModelNumber = "1.0", - Identification = new DeviceIdentification() - { - FriendlyName = "My Device", - Manufacturer = "LG Electronics", - ManufacturerUrl = "http://www.lge.com", - ModelDescription = "LG WebOSTV DMRplus", - ModelName = "LG TV", - ModelNumber = "1.0", - } - }; - - Assert.False(GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification)); - } - } -} -- cgit v1.2.3