mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-26 07:28:43 +02:00
Changed testing
This commit is contained in:
parent
092c610fbf
commit
a99caa0daa
|
@ -156,7 +156,7 @@ namespace Emby.Dlna
|
||||||
/// <param name="deviceInfo">The <see cref="DeviceIdentification"/> of the device.</param>
|
/// <param name="deviceInfo">The <see cref="DeviceIdentification"/> of the device.</param>
|
||||||
/// <param name="profileInfo">The <see cref="DeviceIdentification"/> of the profile.</param>
|
/// <param name="profileInfo">The <see cref="DeviceIdentification"/> of the profile.</param>
|
||||||
/// <returns><b>True</b> if they match.</returns>
|
/// <returns><b>True</b> if they match.</returns>
|
||||||
public static bool IsMatch(DeviceIdentification deviceInfo, DeviceIdentification profileInfo)
|
public bool IsMatch(DeviceIdentification deviceInfo, DeviceIdentification profileInfo)
|
||||||
{
|
{
|
||||||
return IsRegexOrSubstringMatch(deviceInfo.FriendlyName, profileInfo.FriendlyName)
|
return IsRegexOrSubstringMatch(deviceInfo.FriendlyName, profileInfo.FriendlyName)
|
||||||
&& IsRegexOrSubstringMatch(deviceInfo.Manufacturer, profileInfo.Manufacturer)
|
&& IsRegexOrSubstringMatch(deviceInfo.Manufacturer, profileInfo.Manufacturer)
|
||||||
|
@ -168,7 +168,7 @@ namespace Emby.Dlna
|
||||||
&& IsRegexOrSubstringMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber);
|
&& IsRegexOrSubstringMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsRegexOrSubstringMatch(string input, string pattern)
|
private bool IsRegexOrSubstringMatch(string input, string pattern)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(pattern))
|
if (string.IsNullOrEmpty(pattern))
|
||||||
{
|
{
|
||||||
|
@ -182,16 +182,9 @@ namespace Emby.Dlna
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return input.Equals(pattern, StringComparison.OrdinalIgnoreCase)
|
return input.Equals(pattern, StringComparison.OrdinalIgnoreCase)
|
||||||
|| Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
|
|| Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
|
||||||
}
|
}
|
||||||
catch (ArgumentException ex)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Error evaluating regex pattern " + pattern, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeviceProfile GetProfile(IHeaderDictionary headers)
|
public DeviceProfile GetProfile(IHeaderDictionary headers)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
|
||||||
|
<PackageReference Include="Moq" Version="4.16.1" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
|
||||||
<PackageReference Include="coverlet.collector" Version="3.0.3" />
|
<PackageReference Include="coverlet.collector" Version="3.0.3" />
|
||||||
|
|
|
@ -1,18 +1,29 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Emby.Dlna;
|
using Emby.Dlna;
|
||||||
using Emby.Dlna.PlayTo;
|
using Emby.Dlna.PlayTo;
|
||||||
|
using MediaBrowser.Common.Configuration;
|
||||||
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Model.Dlna;
|
using MediaBrowser.Model.Dlna;
|
||||||
|
using MediaBrowser.Model.IO;
|
||||||
|
using MediaBrowser.Model.Serialization;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Jellyfin.Dlna.Tests
|
namespace Jellyfin.Dlna.Tests
|
||||||
{
|
{
|
||||||
public class ProfileTester
|
public class ProfileTester
|
||||||
{
|
{
|
||||||
|
private DlnaManager GetManager()
|
||||||
|
{
|
||||||
|
var xmlSerializer = new Mock<IXmlSerializer>();
|
||||||
|
var fileSystem = new Mock<IFileSystem>();
|
||||||
|
var appPaths = new Mock<IApplicationPaths>();
|
||||||
|
var loggerFactory = new Mock<ILoggerFactory>();
|
||||||
|
var appHost = new Mock<IServerApplicationHost>();
|
||||||
|
|
||||||
|
return new DlnaManager(xmlSerializer.Object, fileSystem.Object, appPaths.Object, loggerFactory.Object, appHost.Object);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Test_Profile_Matches()
|
public void Test_Profile_Matches()
|
||||||
{
|
{
|
||||||
|
@ -46,7 +57,7 @@ namespace Jellyfin.Dlna.Tests
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.True(DlnaManager.IsMatch(device.ToDeviceIdentification(), profile.Identification));
|
Assert.True(GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification));
|
||||||
|
|
||||||
var profile2 = new DeviceProfile()
|
var profile2 = new DeviceProfile()
|
||||||
{
|
{
|
||||||
|
@ -58,7 +69,7 @@ namespace Jellyfin.Dlna.Tests
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.True(DlnaManager.IsMatch(device.ToDeviceIdentification(), profile2.Identification));
|
Assert.True(GetManager().IsMatch(device.ToDeviceIdentification(), profile2.Identification));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -90,7 +101,7 @@ namespace Jellyfin.Dlna.Tests
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.False(DlnaManager.IsMatch(device.ToDeviceIdentification(), profile.Identification));
|
Assert.False(GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue