You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/tests/Jellyfin.Providers.Tests/MediaInfo/AudioResolverTests.cs

90 lines
3.2 KiB

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Emby.Naming.Common;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
3 years ago
using MediaBrowser.Model.IO;
using MediaBrowser.Providers.MediaInfo;
using Moq;
using Xunit;
namespace Jellyfin.Providers.Tests.MediaInfo;
public class AudioResolverTests
{
private readonly AudioResolver _audioResolver;
public AudioResolverTests()
{
// prep BaseItem and Video for calls made that expect managers
Video.LiveTvManager = Mock.Of<ILiveTvManager>();
var applicationPaths = new Mock<IServerApplicationPaths>().Object;
var serverConfig = new Mock<IServerConfigurationManager>();
serverConfig.Setup(c => c.ApplicationPaths)
.Returns(applicationPaths);
BaseItem.ConfigurationManager = serverConfig.Object;
// build resolver to test with
var localizationManager = Mock.Of<ILocalizationManager>();
var mediaEncoder = new Mock<IMediaEncoder>(MockBehavior.Strict);
mediaEncoder.Setup(me => me.GetMediaInfo(It.IsAny<MediaInfoRequest>(), It.IsAny<CancellationToken>()))
.Returns<MediaInfoRequest, CancellationToken>((_, _) => Task.FromResult(new MediaBrowser.Model.MediaInfo.MediaInfo
{
MediaStreams = new List<MediaStream>
{
new()
{
Type = MediaStreamType.Audio
}
}
}));
3 years ago
var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.VideoDirectoryRegex)))
3 years ago
.Returns(true);
fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.MetadataDirectoryRegex)))
3 years ago
.Returns(true);
_audioResolver = new AudioResolver(localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
}
[Theory]
[InlineData("My.Video.srt", false, false)]
[InlineData("My.Video.mp3", false, true)]
[InlineData("My.Video.srt", true, false)]
[InlineData("My.Video.mp3", true, true)]
public async void GetExternalStreams_MixedFilenames_PicksAudio(string file, bool metadataDirectory, bool matches)
{
BaseItem.MediaSourceManager = Mock.Of<IMediaSourceManager>();
var video = new Movie
{
Path = MediaInfoResolverTests.VideoDirectoryPath + "/My.Video.mkv"
};
var directoryService = MediaInfoResolverTests.GetDirectoryServiceForExternalFile(file, metadataDirectory);
var streams = await _audioResolver.GetExternalStreamsAsync(video, 0, directoryService, false, CancellationToken.None);
if (matches)
{
Assert.Single(streams);
var actual = streams[0];
Assert.Equal(MediaStreamType.Audio, actual.Type);
}
else
{
Assert.Empty(streams);
}
}
}