aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Jellyfin.Common.Tests/Json/JsonBoolNumberTests.cs34
-rw-r--r--tests/Jellyfin.Common.Tests/Json/JsonGuidConverterTests.cs6
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj5
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/LiveTv/HdHomerunHostTests.cs134
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/LiveTv/discover.json1
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/LiveTv/lineup.json1
6 files changed, 178 insertions, 3 deletions
diff --git a/tests/Jellyfin.Common.Tests/Json/JsonBoolNumberTests.cs b/tests/Jellyfin.Common.Tests/Json/JsonBoolNumberTests.cs
new file mode 100644
index 000000000..9ded01f2b
--- /dev/null
+++ b/tests/Jellyfin.Common.Tests/Json/JsonBoolNumberTests.cs
@@ -0,0 +1,34 @@
+using System.Text.Json;
+using MediaBrowser.Common.Json.Converters;
+using Xunit;
+
+namespace Jellyfin.Common.Tests.Json
+{
+ public static class JsonBoolNumberTests
+ {
+ [Theory]
+ [InlineData("1", true)]
+ [InlineData("0", false)]
+ [InlineData("2", true)]
+ [InlineData("true", true)]
+ [InlineData("false", false)]
+ public static void Deserialize_Number_Valid_Success(string input, bool? output)
+ {
+ var options = new JsonSerializerOptions();
+ options.Converters.Add(new JsonBoolNumberConverter());
+ var value = JsonSerializer.Deserialize<bool>(input, options);
+ Assert.Equal(value, output);
+ }
+
+ [Theory]
+ [InlineData(true, "true")]
+ [InlineData(false, "false")]
+ public static void Serialize_Bool_Success(bool input, string output)
+ {
+ var options = new JsonSerializerOptions();
+ options.Converters.Add(new JsonBoolNumberConverter());
+ var value = JsonSerializer.Serialize(input, options);
+ Assert.Equal(value, output);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/Jellyfin.Common.Tests/Json/JsonGuidConverterTests.cs b/tests/Jellyfin.Common.Tests/Json/JsonGuidConverterTests.cs
index 3c94db491..663cc3c78 100644
--- a/tests/Jellyfin.Common.Tests/Json/JsonGuidConverterTests.cs
+++ b/tests/Jellyfin.Common.Tests/Json/JsonGuidConverterTests.cs
@@ -3,7 +3,7 @@ using System.Text.Json;
using MediaBrowser.Common.Json.Converters;
using Xunit;
-namespace Jellyfin.Common.Tests.Extensions
+namespace Jellyfin.Common.Tests.Json
{
public class JsonGuidConverterTests
{
@@ -44,9 +44,9 @@ namespace Jellyfin.Common.Tests.Extensions
}
[Fact]
- public void Serialize_EmptyGuid_Null()
+ public void Serialize_EmptyGuid_EmptyGuid()
{
- Assert.Equal("null", JsonSerializer.Serialize(Guid.Empty, _options));
+ Assert.Equal($"\"{Guid.Empty}\"", JsonSerializer.Serialize(Guid.Empty, _options));
}
}
}
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 fffbc6212..310219e74 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,11 @@
<ProjectReference Include="..\..\Emby.Server.Implementations\Emby.Server.Implementations.csproj" />
</ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="LiveTv\discover.json" />
+ <EmbeddedResource Include="LiveTv\lineup.json" />
+ </ItemGroup>
+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<CodeAnalysisRuleSet>../jellyfin-tests.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
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 000000000..fb7cf6a47
--- /dev/null
+++ b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/HdHomerunHostTests.cs
@@ -0,0 +1,134 @@
+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 BaseResourcePath = "Jellyfin.Server.Implementations.Tests.LiveTv.";
+
+ var messageHandler = new Mock<HttpMessageHandler>();
+ messageHandler.Protected()
+ .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
+ .Returns<HttpRequestMessage, CancellationToken>(
+ (m, _) =>
+ {
+ 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>();
+ http.Setup(x => x.CreateClient(It.IsAny<string>()))
+ .Returns(new HttpClient(messageHandler.Object));
+ _fixture = new Fixture();
+ _fixture.Customize(new AutoMoqCustomization
+ {
+ ConfigureMembers = true
+ }).Inject(http);
+ _hdHomerunHost = _fixture.Create<HdHomerunHost>();
+ }
+
+ [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<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);
+ }
+ }
+}
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 000000000..851f17bb2
--- /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"}
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 000000000..4cb5ebc8e
--- /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" } ]