From 13d62c597798026f45c041f20768b1a3b4b40ebf Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Wed, 9 Dec 2020 08:16:40 +0100 Subject: Merge pull request #4741 from jellyfin/tests8 Add tests for HdHomerunHost.GetLineup (cherry picked from commit 31e82737953700a53970e31010bc6c710be25872) Signed-off-by: Joshua M. Boniface --- .../Jellyfin.Server.Implementations.Tests.csproj | 1 + .../LiveTv/HdHomerunHostTests.cs | 69 ++++++++++++++++++++-- .../LiveTv/lineup.json | 1 + 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 tests/Jellyfin.Server.Implementations.Tests/LiveTv/lineup.json (limited to 'tests') diff --git a/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj b/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj index 08392b25ea..310219e742 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj +++ b/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj @@ -37,6 +37,7 @@ + diff --git a/tests/Jellyfin.Server.Implementations.Tests/LiveTv/HdHomerunHostTests.cs b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/HdHomerunHostTests.cs index c38d9ea4d8..fb7cf6a471 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/LiveTv/HdHomerunHostTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/HdHomerunHostTests.cs @@ -22,15 +22,26 @@ namespace Jellyfin.Server.Implementations.Tests.LiveTv public HdHomerunHostTests() { - const string ResourceName = "Jellyfin.Server.Implementations.Tests.LiveTv.discover.json"; + const string BaseResourcePath = "Jellyfin.Server.Implementations.Tests.LiveTv."; var messageHandler = new Mock(); - messageHandler.Protected().Setup>("SendAsync", ItExpr.IsAny(), ItExpr.IsAny()) - .Returns( - () => Task.FromResult(new HttpResponseMessage() + messageHandler.Protected() + .Setup>("SendAsync", ItExpr.IsAny(), ItExpr.IsAny()) + .Returns( + (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(); http.Setup(x => x.CreateClient(It.IsAny())) @@ -73,5 +84,51 @@ namespace Jellyfin.Server.Implementations.Tests.LiveTv await Assert.ThrowsAsync(() => _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); + } } } diff --git a/tests/Jellyfin.Server.Implementations.Tests/LiveTv/lineup.json b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/lineup.json new file mode 100644 index 0000000000..4cb5ebc8ec --- /dev/null +++ b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/lineup.json @@ -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" } ] -- cgit v1.2.3