aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Model.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Jellyfin.Model.Tests')
-rw-r--r--tests/Jellyfin.Model.Tests/Dlna/StreamBuilderTests.cs36
-rw-r--r--tests/Jellyfin.Model.Tests/Drawing/ImageFormatExtensionsTests.cs13
2 files changed, 31 insertions, 18 deletions
diff --git a/tests/Jellyfin.Model.Tests/Dlna/StreamBuilderTests.cs b/tests/Jellyfin.Model.Tests/Dlna/StreamBuilderTests.cs
index c30dad6f90..210ce4a47f 100644
--- a/tests/Jellyfin.Model.Tests/Dlna/StreamBuilderTests.cs
+++ b/tests/Jellyfin.Model.Tests/Dlna/StreamBuilderTests.cs
@@ -351,11 +351,11 @@ namespace Jellyfin.Model.Tests
// Assert.Contains(uri.Extension, containers);
// Check expected video codec (1)
- Assert.Contains(targetVideoStream.Codec, streamInfo.TargetVideoCodec);
+ Assert.Contains(targetVideoStream?.Codec, streamInfo.TargetVideoCodec);
Assert.Single(streamInfo.TargetVideoCodec);
// Check expected audio codecs (1)
- Assert.Contains(targetAudioStream.Codec, streamInfo.TargetAudioCodec);
+ Assert.Contains(targetAudioStream?.Codec, streamInfo.TargetAudioCodec);
Assert.Single(streamInfo.TargetAudioCodec);
// Assert.Single(val.AudioCodecs);
@@ -410,13 +410,13 @@ namespace Jellyfin.Model.Tests
else
{
// Check expected video codec (1)
- Assert.Contains(targetVideoStream.Codec, streamInfo.TargetVideoCodec);
+ Assert.Contains(targetVideoStream?.Codec, streamInfo.TargetVideoCodec);
Assert.Single(streamInfo.TargetVideoCodec);
if (transcodeMode.Equals("DirectStream", StringComparison.Ordinal))
{
// Check expected audio codecs (1)
- if (!targetAudioStream.IsExternal)
+ if (targetAudioStream?.IsExternal == false)
{
// Check expected audio codecs (1)
if (streamInfo.TranscodeReasons.HasFlag(TranscodeReason.ContainerNotSupported))
@@ -432,7 +432,7 @@ namespace Jellyfin.Model.Tests
else if (transcodeMode.Equals("Remux", StringComparison.Ordinal))
{
// Check expected audio codecs (1)
- Assert.Contains(targetAudioStream.Codec, streamInfo.AudioCodecs);
+ Assert.Contains(targetAudioStream?.Codec, streamInfo.AudioCodecs);
Assert.Single(streamInfo.AudioCodecs);
}
@@ -440,10 +440,10 @@ namespace Jellyfin.Model.Tests
var videoStream = targetVideoStream;
Assert.False(streamInfo.EstimateContentLength);
Assert.Equal(TranscodeSeekInfo.Auto, streamInfo.TranscodeSeekInfo);
- Assert.Contains(videoStream.Profile?.ToLowerInvariant() ?? string.Empty, streamInfo.TargetVideoProfile?.Split(",").Select(s => s.ToLowerInvariant()) ?? Array.Empty<string>());
- Assert.Equal(videoStream.Level, streamInfo.TargetVideoLevel);
- Assert.Equal(videoStream.BitDepth, streamInfo.TargetVideoBitDepth);
- Assert.InRange(streamInfo.VideoBitrate.GetValueOrDefault(), videoStream.BitRate.GetValueOrDefault(), int.MaxValue);
+ Assert.Contains(videoStream?.Profile?.ToLowerInvariant() ?? string.Empty, streamInfo.TargetVideoProfile?.Split(",").Select(s => s.ToLowerInvariant()) ?? Array.Empty<string>());
+ Assert.Equal(videoStream?.Level, streamInfo.TargetVideoLevel);
+ Assert.Equal(videoStream?.BitDepth, streamInfo.TargetVideoBitDepth);
+ Assert.InRange(streamInfo.VideoBitrate.GetValueOrDefault(), videoStream?.BitRate.GetValueOrDefault() ?? 0, int.MaxValue);
// Audio codec not supported
if ((why & TranscodeReason.AudioCodecNotSupported) != 0)
@@ -452,7 +452,7 @@ namespace Jellyfin.Model.Tests
if (options.AudioStreamIndex >= 0)
{
// TODO:fixme
- if (!targetAudioStream.IsExternal)
+ if (targetAudioStream?.IsExternal == false)
{
Assert.DoesNotContain(targetAudioStream.Codec, streamInfo.AudioCodecs);
}
@@ -488,16 +488,16 @@ namespace Jellyfin.Model.Tests
private static async ValueTask<T> TestData<T>(string name)
{
var path = Path.Join("Test Data", typeof(T).Name + "-" + name + ".json");
- using (var stream = File.OpenRead(path))
- {
- var value = await JsonSerializer.DeserializeAsync<T>(stream, JsonDefaults.Options);
- if (value is not null)
- {
- return value;
- }
- throw new SerializationException("Invalid test data: " + name);
+ using var stream = File.OpenRead(path);
+
+ var value = await JsonSerializer.DeserializeAsync<T>(stream, JsonDefaults.Options);
+ if (value is not null)
+ {
+ return value;
}
+
+ throw new SerializationException("Invalid test data: " + name);
}
private StreamBuilder GetStreamBuilder()
diff --git a/tests/Jellyfin.Model.Tests/Drawing/ImageFormatExtensionsTests.cs b/tests/Jellyfin.Model.Tests/Drawing/ImageFormatExtensionsTests.cs
index a5bdb42d89..198ad5a274 100644
--- a/tests/Jellyfin.Model.Tests/Drawing/ImageFormatExtensionsTests.cs
+++ b/tests/Jellyfin.Model.Tests/Drawing/ImageFormatExtensionsTests.cs
@@ -30,4 +30,17 @@ public static class ImageFormatExtensionsTests
[InlineData((ImageFormat)5)]
public static void GetMimeType_Valid_ThrowsInvalidEnumArgumentException(ImageFormat format)
=> Assert.Throws<InvalidEnumArgumentException>(() => format.GetMimeType());
+
+ [Theory]
+ [MemberData(nameof(GetAllImageFormats))]
+ public static void GetExtension_Valid_Valid(ImageFormat format)
+ => Assert.Null(Record.Exception(() => format.GetExtension()));
+
+ [Theory]
+ [InlineData((ImageFormat)int.MinValue)]
+ [InlineData((ImageFormat)int.MaxValue)]
+ [InlineData((ImageFormat)(-1))]
+ [InlineData((ImageFormat)5)]
+ public static void GetExtension_Valid_ThrowsInvalidEnumArgumentException(ImageFormat format)
+ => Assert.Throws<InvalidEnumArgumentException>(() => format.GetExtension());
}