aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Jellyfin.Dlna.Tests/ProfileTester.cs112
1 files changed, 44 insertions, 68 deletions
diff --git a/tests/Jellyfin.Dlna.Tests/ProfileTester.cs b/tests/Jellyfin.Dlna.Tests/ProfileTester.cs
index 83638c7c4..cc7cf92e7 100644
--- a/tests/Jellyfin.Dlna.Tests/ProfileTester.cs
+++ b/tests/Jellyfin.Dlna.Tests/ProfileTester.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
+using Emby.Dlna;
using Emby.Dlna.PlayTo;
using MediaBrowser.Model.Dlna;
using Xunit;
@@ -12,92 +13,67 @@ namespace Jellyfin.Dlna.Tests
{
public class ProfileTester
{
- private bool IsMatch(DeviceIdentification deviceInfo, DeviceIdentification profileInfo)
+ [Fact]
+ public void Test_Profile_Matches()
{
- if (!string.IsNullOrEmpty(profileInfo.FriendlyName))
- {
- if (deviceInfo.FriendlyName == null || !IsRegexOrSubstringMatch(deviceInfo.FriendlyName, profileInfo.FriendlyName))
- {
- return false;
- }
- }
-
- if (!string.IsNullOrEmpty(profileInfo.Manufacturer))
- {
- if (deviceInfo.Manufacturer == null || !IsRegexOrSubstringMatch(deviceInfo.Manufacturer, profileInfo.Manufacturer))
- {
- return false;
- }
- }
-
- if (!string.IsNullOrEmpty(profileInfo.ManufacturerUrl))
- {
- if (deviceInfo.ManufacturerUrl == null || !IsRegexOrSubstringMatch(deviceInfo.ManufacturerUrl, profileInfo.ManufacturerUrl))
- {
- return false;
- }
- }
-
- if (!string.IsNullOrEmpty(profileInfo.ModelDescription))
- {
- if (deviceInfo.ModelDescription == null || !IsRegexOrSubstringMatch(deviceInfo.ModelDescription, profileInfo.ModelDescription))
- {
- return false;
- }
- }
-
- if (!string.IsNullOrEmpty(profileInfo.ModelName))
+ var device = new DeviceInfo()
{
- if (deviceInfo.ModelName == null || !IsRegexOrSubstringMatch(deviceInfo.ModelName, profileInfo.ModelName))
- {
- return false;
- }
- }
+ Name = "My Device",
+ Manufacturer = "LG Electronics",
+ ManufacturerUrl = "http://www.lge.com",
+ ModelDescription = "LG WebOSTV DMRplus",
+ ModelName = "LG TV",
+ ModelNumber = "1.0",
+ };
- if (!string.IsNullOrEmpty(profileInfo.ModelNumber))
+ var profile = new DeviceProfile()
{
- if (deviceInfo.ModelNumber == null || !IsRegexOrSubstringMatch(deviceInfo.ModelNumber, profileInfo.ModelNumber))
+ 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()
{
- return false;
+ FriendlyName = "My Device",
+ Manufacturer = "LG Electronics",
+ ManufacturerUrl = "http://www.lge.com",
+ ModelDescription = "LG WebOSTV DMRplus",
+ ModelName = "LG TV",
+ ModelNumber = "1.0",
}
- }
+ };
- if (!string.IsNullOrEmpty(profileInfo.ModelUrl))
- {
- if (deviceInfo.ModelUrl == null || !IsRegexOrSubstringMatch(deviceInfo.ModelUrl, profileInfo.ModelUrl))
- {
- return false;
- }
- }
+ Assert.True(DlnaManager.IsMatch(device.ToDeviceIdentification(), profile.Identification));
- if (!string.IsNullOrEmpty(profileInfo.SerialNumber))
+ var profile2 = new DeviceProfile()
{
- if (deviceInfo.SerialNumber == null || !IsRegexOrSubstringMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber))
+ Name = "Test Profile",
+ FriendlyName = "My Device",
+ Identification = new DeviceIdentification()
{
- return false;
+ FriendlyName = "My Device",
}
- }
+ };
- return true;
- }
-
- private bool IsRegexOrSubstringMatch(string input, string pattern)
- {
- return input.Contains(pattern, StringComparison.OrdinalIgnoreCase) || Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
+ Assert.True(DlnaManager.IsMatch(device.ToDeviceIdentification(), profile2.Identification));
}
[Fact]
- public void Test_Profile_Matches()
+ public void Test_Profile_NoMatch()
{
- var source = new DeviceInfo()
+ var device = new DeviceInfo()
{
- Name = "HelloWorld"
+ Name = "My Device",
+ Manufacturer = "JVC"
};
- var dest = new DeviceProfile()
+ var profile = new DeviceProfile()
{
- Name = "Test Subject 1",
- FriendlyName = "HelloWorld",
+ Name = "Test Profile",
+ FriendlyName = "My Device",
Manufacturer = "LG Electronics",
ManufacturerUrl = "http://www.lge.com",
ModelDescription = "LG WebOSTV DMRplus",
@@ -105,7 +81,7 @@ namespace Jellyfin.Dlna.Tests
ModelNumber = "1.0",
Identification = new DeviceIdentification()
{
- FriendlyName = "HelloWorld",
+ FriendlyName = "My Device",
Manufacturer = "LG Electronics",
ManufacturerUrl = "http://www.lge.com",
ModelDescription = "LG WebOSTV DMRplus",
@@ -114,7 +90,7 @@ namespace Jellyfin.Dlna.Tests
}
};
- Assert.True(IsMatch(dest.Identification, source.ToDeviceIdentification()));
+ Assert.False(DlnaManager.IsMatch(device.ToDeviceIdentification(), profile.Identification));
}
}
}