From 9799b6ae81aa8efbf6a3f402b6dc5af88a8daef7 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Tue, 8 Dec 2020 20:20:33 +0100 Subject: Merge pull request #4738 from jellyfin/tests8 Add tests for HdHomerunHost.GetModelInfo (cherry picked from commit e6650651b3fd85bb359420c72eaf4335b89d0c2c) Signed-off-by: Joshua M. Boniface --- .../Jellyfin.Server.Implementations.Tests.csproj | 4 ++ .../LiveTv/HdHomerunHostTests.cs | 77 ++++++++++++++++++++++ .../LiveTv/discover.json | 1 + 3 files changed, 82 insertions(+) create mode 100644 tests/Jellyfin.Server.Implementations.Tests/LiveTv/HdHomerunHostTests.cs create mode 100644 tests/Jellyfin.Server.Implementations.Tests/LiveTv/discover.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 fffbc6212a..08392b25ea 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj +++ b/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj @@ -35,6 +35,10 @@ + + + + ../jellyfin-tests.ruleset diff --git a/tests/Jellyfin.Server.Implementations.Tests/LiveTv/HdHomerunHostTests.cs b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/HdHomerunHostTests.cs new file mode 100644 index 0000000000..c38d9ea4d8 --- /dev/null +++ b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/HdHomerunHostTests.cs @@ -0,0 +1,77 @@ +using System; +using System.Net; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using AutoFixture.AutoMoq; +using Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun; +using MediaBrowser.Model.LiveTv; +using Moq; +using Moq.Protected; +using Xunit; + +namespace Jellyfin.Server.Implementations.Tests.LiveTv +{ + public class HdHomerunHostTests + { + private const string TestIp = "http://192.168.1.182"; + + private readonly Fixture _fixture; + private readonly HdHomerunHost _hdHomerunHost; + + public HdHomerunHostTests() + { + const string ResourceName = "Jellyfin.Server.Implementations.Tests.LiveTv.discover.json"; + + var messageHandler = new Mock(); + messageHandler.Protected().Setup>("SendAsync", ItExpr.IsAny(), ItExpr.IsAny()) + .Returns( + () => Task.FromResult(new HttpResponseMessage() + { + Content = new StreamContent(typeof(HdHomerunHostTests).Assembly.GetManifestResourceStream(ResourceName)!) + })); + + var http = new Mock(); + http.Setup(x => x.CreateClient(It.IsAny())) + .Returns(new HttpClient(messageHandler.Object)); + _fixture = new Fixture(); + _fixture.Customize(new AutoMoqCustomization + { + ConfigureMembers = true + }).Inject(http); + _hdHomerunHost = _fixture.Create(); + } + + [Fact] + public async Task GetModelInfo_Valid_Success() + { + var host = new TunerHostInfo() + { + Url = TestIp + }; + + var modelInfo = await _hdHomerunHost.GetModelInfo(host, true, CancellationToken.None).ConfigureAwait(false); + Assert.Equal("HDHomeRun PRIME", modelInfo.FriendlyName); + Assert.Equal("HDHR3-CC", modelInfo.ModelNumber); + Assert.Equal("hdhomerun3_cablecard", modelInfo.FirmwareName); + Assert.Equal("20160630atest2", modelInfo.FirmwareVersion); + Assert.Equal("FFFFFFFF", modelInfo.DeviceID); + Assert.Equal("FFFFFFFF", modelInfo.DeviceAuth); + Assert.Equal(3, modelInfo.TunerCount); + Assert.Equal("http://192.168.1.182:80", modelInfo.BaseURL); + Assert.Equal("http://192.168.1.182:80/lineup.json", modelInfo.LineupURL); + } + + [Fact] + public async Task GetModelInfo_EmptyUrl_ArgumentException() + { + var host = new TunerHostInfo() + { + Url = string.Empty + }; + + await Assert.ThrowsAsync(() => _hdHomerunHost.GetModelInfo(host, true, CancellationToken.None)); + } + } +} diff --git a/tests/Jellyfin.Server.Implementations.Tests/LiveTv/discover.json b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/discover.json new file mode 100644 index 0000000000..851f17bb26 --- /dev/null +++ b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/discover.json @@ -0,0 +1 @@ +{"FriendlyName":"HDHomeRun PRIME","ModelNumber":"HDHR3-CC","FirmwareName":"hdhomerun3_cablecard","FirmwareVersion":"20160630atest2","DeviceID":"FFFFFFFF","DeviceAuth":"FFFFFFFF","TunerCount":3,"ConditionalAccess":1,"BaseURL":"http://192.168.1.182:80","LineupURL":"http://192.168.1.182:80/lineup.json"} -- cgit v1.2.3