mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-08 02:34:19 -04:00
Merge pull request #4741 from jellyfin/tests8
Add tests for HdHomerunHost.GetLineup (cherry picked from commit 31e82737953700a53970e31010bc6c710be25872) Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
This commit is contained in:
parent
9799b6ae81
commit
13d62c5977
@ -0,0 +1,21 @@
|
|||||||
|
namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
|
{
|
||||||
|
internal class Channels
|
||||||
|
{
|
||||||
|
public string GuideNumber { get; set; }
|
||||||
|
|
||||||
|
public string GuideName { get; set; }
|
||||||
|
|
||||||
|
public string VideoCodec { get; set; }
|
||||||
|
|
||||||
|
public string AudioCodec { get; set; }
|
||||||
|
|
||||||
|
public string URL { get; set; }
|
||||||
|
|
||||||
|
public bool Favorite { get; set; }
|
||||||
|
|
||||||
|
public bool DRM { get; set; }
|
||||||
|
|
||||||
|
public bool HD { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,8 @@
|
|||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
{
|
{
|
||||||
public class DiscoverResponse
|
internal class DiscoverResponse
|
||||||
{
|
{
|
||||||
public string FriendlyName { get; set; }
|
public string FriendlyName { get; set; }
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Common.Json.Converters;
|
using MediaBrowser.Common.Json;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
@ -39,6 +39,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
private readonly INetworkManager _networkManager;
|
private readonly INetworkManager _networkManager;
|
||||||
private readonly IStreamHelper _streamHelper;
|
private readonly IStreamHelper _streamHelper;
|
||||||
|
|
||||||
|
private readonly JsonSerializerOptions _jsonOptions;
|
||||||
|
|
||||||
private readonly Dictionary<string, DiscoverResponse> _modelCache = new Dictionary<string, DiscoverResponse>();
|
private readonly Dictionary<string, DiscoverResponse> _modelCache = new Dictionary<string, DiscoverResponse>();
|
||||||
|
|
||||||
public HdHomerunHost(
|
public HdHomerunHost(
|
||||||
@ -58,6 +60,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
_socketFactory = socketFactory;
|
_socketFactory = socketFactory;
|
||||||
_networkManager = networkManager;
|
_networkManager = networkManager;
|
||||||
_streamHelper = streamHelper;
|
_streamHelper = streamHelper;
|
||||||
|
|
||||||
|
_jsonOptions = JsonDefaults.GetOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => "HD Homerun";
|
public string Name => "HD Homerun";
|
||||||
@ -69,13 +73,13 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
private string GetChannelId(TunerHostInfo info, Channels i)
|
private string GetChannelId(TunerHostInfo info, Channels i)
|
||||||
=> ChannelIdPrefix + i.GuideNumber;
|
=> ChannelIdPrefix + i.GuideNumber;
|
||||||
|
|
||||||
private async Task<List<Channels>> GetLineup(TunerHostInfo info, CancellationToken cancellationToken)
|
internal async Task<List<Channels>> GetLineup(TunerHostInfo info, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var model = await GetModelInfo(info, false, cancellationToken).ConfigureAwait(false);
|
var model = await GetModelInfo(info, false, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(model.LineupURL, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(model.LineupURL, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
||||||
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||||
var lineup = await JsonSerializer.DeserializeAsync<List<Channels>>(stream, cancellationToken: cancellationToken)
|
var lineup = await JsonSerializer.DeserializeAsync<List<Channels>>(stream, _jsonOptions, cancellationToken)
|
||||||
.ConfigureAwait(false) ?? new List<Channels>();
|
.ConfigureAwait(false) ?? new List<Channels>();
|
||||||
|
|
||||||
if (info.ImportFavoritesOnly)
|
if (info.ImportFavoritesOnly)
|
||||||
@ -102,7 +106,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
Id = GetChannelId(info, i),
|
Id = GetChannelId(info, i),
|
||||||
IsFavorite = i.Favorite,
|
IsFavorite = i.Favorite,
|
||||||
TunerHostId = info.Id,
|
TunerHostId = info.Id,
|
||||||
IsHD = i.HD == 1,
|
IsHD = i.HD,
|
||||||
AudioCodec = i.AudioCodec,
|
AudioCodec = i.AudioCodec,
|
||||||
VideoCodec = i.VideoCodec,
|
VideoCodec = i.VideoCodec,
|
||||||
ChannelType = ChannelType.TV,
|
ChannelType = ChannelType.TV,
|
||||||
@ -133,7 +137,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||||
var discoverResponse = await JsonSerializer.DeserializeAsync<DiscoverResponse>(stream, cancellationToken: cancellationToken)
|
var discoverResponse = await JsonSerializer.DeserializeAsync<DiscoverResponse>(stream, _jsonOptions, cancellationToken)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(cacheKey))
|
if (!string.IsNullOrEmpty(cacheKey))
|
||||||
@ -331,25 +335,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
return new Uri(url).AbsoluteUri.TrimEnd('/');
|
return new Uri(url).AbsoluteUri.TrimEnd('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Channels
|
|
||||||
{
|
|
||||||
public string GuideNumber { get; set; }
|
|
||||||
|
|
||||||
public string GuideName { get; set; }
|
|
||||||
|
|
||||||
public string VideoCodec { get; set; }
|
|
||||||
|
|
||||||
public string AudioCodec { get; set; }
|
|
||||||
|
|
||||||
public string URL { get; set; }
|
|
||||||
|
|
||||||
public bool Favorite { get; set; }
|
|
||||||
|
|
||||||
public bool DRM { get; set; }
|
|
||||||
|
|
||||||
public int HD { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected EncodingOptions GetEncodingOptions()
|
protected EncodingOptions GetEncodingOptions()
|
||||||
{
|
{
|
||||||
return Config.GetConfiguration<EncodingOptions>("encoding");
|
return Config.GetConfiguration<EncodingOptions>("encoding");
|
||||||
@ -729,7 +714,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<TunerHostInfo> TryGetTunerHostInfo(string url, CancellationToken cancellationToken)
|
internal async Task<TunerHostInfo> TryGetTunerHostInfo(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var hostInfo = new TunerHostInfo
|
var hostInfo = new TunerHostInfo
|
||||||
{
|
{
|
||||||
@ -741,6 +726,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
|
|
||||||
hostInfo.DeviceId = modelInfo.DeviceID;
|
hostInfo.DeviceId = modelInfo.DeviceID;
|
||||||
hostInfo.FriendlyName = modelInfo.FriendlyName;
|
hostInfo.FriendlyName = modelInfo.FriendlyName;
|
||||||
|
hostInfo.TunerCount = modelInfo.TunerCount;
|
||||||
|
|
||||||
return hostInfo;
|
return hostInfo;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="LiveTv\discover.json" />
|
<EmbeddedResource Include="LiveTv\discover.json" />
|
||||||
|
<EmbeddedResource Include="LiveTv\lineup.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
|
@ -22,15 +22,26 @@ namespace Jellyfin.Server.Implementations.Tests.LiveTv
|
|||||||
|
|
||||||
public HdHomerunHostTests()
|
public HdHomerunHostTests()
|
||||||
{
|
{
|
||||||
const string ResourceName = "Jellyfin.Server.Implementations.Tests.LiveTv.discover.json";
|
const string BaseResourcePath = "Jellyfin.Server.Implementations.Tests.LiveTv.";
|
||||||
|
|
||||||
var messageHandler = new Mock<HttpMessageHandler>();
|
var messageHandler = new Mock<HttpMessageHandler>();
|
||||||
messageHandler.Protected().Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
|
messageHandler.Protected()
|
||||||
.Returns(
|
.Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
|
||||||
() => Task.FromResult(new HttpResponseMessage()
|
.Returns<HttpRequestMessage, CancellationToken>(
|
||||||
|
(m, _) =>
|
||||||
{
|
{
|
||||||
Content = new StreamContent(typeof(HdHomerunHostTests).Assembly.GetManifestResourceStream(ResourceName)!)
|
var resource = BaseResourcePath + m.RequestUri?.Segments[^1];
|
||||||
}));
|
var stream = typeof(HdHomerunHostTests).Assembly.GetManifestResourceStream(resource);
|
||||||
|
if (stream == null)
|
||||||
|
{
|
||||||
|
throw new NullReferenceException("Resource doesn't exist: " + resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult(new HttpResponseMessage()
|
||||||
|
{
|
||||||
|
Content = new StreamContent(stream)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var http = new Mock<IHttpClientFactory>();
|
var http = new Mock<IHttpClientFactory>();
|
||||||
http.Setup(x => x.CreateClient(It.IsAny<string>()))
|
http.Setup(x => x.CreateClient(It.IsAny<string>()))
|
||||||
@ -73,5 +84,51 @@ namespace Jellyfin.Server.Implementations.Tests.LiveTv
|
|||||||
|
|
||||||
await Assert.ThrowsAsync<ArgumentException>(() => _hdHomerunHost.GetModelInfo(host, true, CancellationToken.None));
|
await Assert.ThrowsAsync<ArgumentException>(() => _hdHomerunHost.GetModelInfo(host, true, CancellationToken.None));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetLineup_Valid_Success()
|
||||||
|
{
|
||||||
|
var host = new TunerHostInfo()
|
||||||
|
{
|
||||||
|
Url = TestIp
|
||||||
|
};
|
||||||
|
|
||||||
|
var channels = await _hdHomerunHost.GetLineup(host, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
Assert.Equal(6, channels.Count);
|
||||||
|
Assert.Equal("4.1", channels[0].GuideNumber);
|
||||||
|
Assert.Equal("WCMH-DT", channels[0].GuideName);
|
||||||
|
Assert.True(channels[0].HD);
|
||||||
|
Assert.True(channels[0].Favorite);
|
||||||
|
Assert.Equal("http://192.168.1.111:5004/auto/v4.1", channels[0].URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetLineup_ImportFavoritesOnly_Success()
|
||||||
|
{
|
||||||
|
var host = new TunerHostInfo()
|
||||||
|
{
|
||||||
|
Url = TestIp,
|
||||||
|
ImportFavoritesOnly = true
|
||||||
|
};
|
||||||
|
|
||||||
|
var channels = await _hdHomerunHost.GetLineup(host, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
Assert.Single(channels);
|
||||||
|
Assert.Equal("4.1", channels[0].GuideNumber);
|
||||||
|
Assert.Equal("WCMH-DT", channels[0].GuideName);
|
||||||
|
Assert.True(channels[0].HD);
|
||||||
|
Assert.True(channels[0].Favorite);
|
||||||
|
Assert.Equal("http://192.168.1.111:5004/auto/v4.1", channels[0].URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task TryGetTunerHostInfo_Valid_Success()
|
||||||
|
{
|
||||||
|
var host = await _hdHomerunHost.TryGetTunerHostInfo(TestIp, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
Assert.Equal(_hdHomerunHost.Type, host.Type);
|
||||||
|
Assert.Equal(TestIp, host.Url);
|
||||||
|
Assert.Equal("HDHomeRun PRIME", host.FriendlyName);
|
||||||
|
Assert.Equal("FFFFFFFF", host.DeviceId);
|
||||||
|
Assert.Equal(3, host.TunerCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
[ { "GuideNumber": "4.1", "GuideName": "WCMH-DT", "HD": 1, "Favorite": 1, "URL": "http://192.168.1.111:5004/auto/v4.1" }, { "GuideNumber": "4.2", "GuideName": "MeTV", "URL": "http://192.168.1.111:5004/auto/v4.2" }, { "GuideNumber": "4.3", "GuideName": "ION TV", "URL": "http://192.168.1.111:5004/auto/v4.3" }, { "GuideNumber": "6.1", "GuideName": "WSYX DT", "HD": 1, "URL": "http://192.168.1.111:5004/auto/v6.1" }, { "GuideNumber": "6.2", "GuideName": "MYTV", "URL": "http://192.168.1.111:5004/auto/v6.2" }, { "GuideNumber": "6.3", "GuideName": "ANTENNA", "URL": "http://192.168.1.111:5004/auto/v6.3" } ]
|
Loading…
x
Reference in New Issue
Block a user