jellyfin/tests/Jellyfin.Dlna.Tests/DlnaManagerTests.cs

132 lines
4.3 KiB
C#
Raw Normal View History

2021-04-19 13:07:14 +00:00
using Emby.Dlna;
2021-04-19 11:36:30 +00:00
using Emby.Dlna.PlayTo;
2021-04-20 17:04:16 +00:00
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller;
2021-04-19 11:36:30 +00:00
using MediaBrowser.Model.Dlna;
2021-04-20 17:04:16 +00:00
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
using Moq;
2021-04-19 11:36:30 +00:00
using Xunit;
namespace Jellyfin.Dlna.Tests
{
public class DlnaManagerTests
2021-04-19 11:36:30 +00:00
{
2021-04-20 17:04:16 +00:00
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);
}
2021-04-19 13:07:14 +00:00
[Fact]
public void IsMatch_GivenMatchingName_ReturnsTrue()
2021-04-19 11:36:30 +00:00
{
2021-04-19 13:07:14 +00:00
var device = new DeviceInfo()
2021-04-19 11:36:30 +00:00
{
2021-04-19 13:07:14 +00:00
Name = "My Device",
Manufacturer = "LG Electronics",
ManufacturerUrl = "http://www.lge.com",
ModelDescription = "LG WebOSTV DMRplus",
ModelName = "LG TV",
ModelNumber = "1.0",
};
2021-04-19 11:36:30 +00:00
2021-04-19 13:07:14 +00:00
var profile = new DeviceProfile()
2021-04-19 11:36:30 +00:00
{
2021-04-19 13:07:14 +00:00
Name = "Test Profile",
FriendlyName = "My Device",
Manufacturer = "LG Electronics",
ManufacturerUrl = "http://www.lge.com",
ModelDescription = "LG WebOSTV DMRplus",
ModelName = "LG TV",
ModelNumber = "1.0",
2021-12-24 17:28:27 +00:00
Identification = new()
2021-04-19 11:36:30 +00:00
{
2021-04-19 13:07:14 +00:00
FriendlyName = "My Device",
Manufacturer = "LG Electronics",
ManufacturerUrl = "http://www.lge.com",
ModelDescription = "LG WebOSTV DMRplus",
ModelName = "LG TV",
ModelNumber = "1.0",
2021-04-19 11:36:30 +00:00
}
2021-04-19 13:07:14 +00:00
};
2021-04-19 11:36:30 +00:00
2021-04-19 13:07:14 +00:00
var profile2 = new DeviceProfile()
2021-04-19 11:36:30 +00:00
{
2021-04-19 13:07:14 +00:00
Name = "Test Profile",
FriendlyName = "My Device",
Identification = new DeviceIdentification()
2021-04-19 11:36:30 +00:00
{
2021-04-19 13:07:14 +00:00
FriendlyName = "My Device",
2021-04-19 11:36:30 +00:00
}
2021-04-19 13:07:14 +00:00
};
2021-04-19 11:36:30 +00:00
2021-04-21 09:18:29 +00:00
var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile2.Identification);
2021-04-21 11:08:02 +00:00
var deviceMatch2 = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification);
2021-04-21 09:18:29 +00:00
Assert.True(deviceMatch);
2021-04-21 11:08:02 +00:00
Assert.True(deviceMatch2);
2021-04-19 11:36:30 +00:00
}
[Fact]
public void IsMatch_GivenNamesAndManufacturersDoNotMatch_ReturnsFalse()
2021-04-19 11:36:30 +00:00
{
2021-04-19 13:07:14 +00:00
var device = new DeviceInfo()
2021-04-19 11:36:30 +00:00
{
2021-04-19 13:07:14 +00:00
Name = "My Device",
Manufacturer = "JVC"
2021-04-19 11:36:30 +00:00
};
2021-04-19 13:07:14 +00:00
var profile = new DeviceProfile()
2021-04-19 11:36:30 +00:00
{
2021-04-19 13:07:14 +00:00
Name = "Test Profile",
FriendlyName = "My Device",
2021-04-19 11:36:30 +00:00
Manufacturer = "LG Electronics",
ManufacturerUrl = "http://www.lge.com",
ModelDescription = "LG WebOSTV DMRplus",
ModelName = "LG TV",
ModelNumber = "1.0",
2021-12-24 17:28:27 +00:00
Identification = new()
2021-04-19 11:36:30 +00:00
{
2021-04-19 13:07:14 +00:00
FriendlyName = "My Device",
2021-04-19 11:36:30 +00:00
Manufacturer = "LG Electronics",
ManufacturerUrl = "http://www.lge.com",
ModelDescription = "LG WebOSTV DMRplus",
ModelName = "LG TV",
ModelNumber = "1.0",
}
};
2021-04-21 09:18:29 +00:00
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 .*",
2021-12-24 17:28:27 +00:00
Identification = new()
2021-04-21 09:18:29 +00:00
};
var deviceMatch = GetManager().IsMatch(device.ToDeviceIdentification(), profile.Identification);
Assert.True(deviceMatch);
2021-04-19 11:36:30 +00:00
}
}
}