using System.Text; using Bugsnag; using ErsatzTV.Core; using ErsatzTV.Scanner.Core.Metadata.Nfo; using FluentAssertions; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.IO; using NSubstitute; using NUnit.Framework; namespace ErsatzTV.Scanner.Tests.Core.Metadata.Nfo; [TestFixture] public class ShowNfoReaderTests { [SetUp] public void SetUp() => _showNfoReader = new ShowNfoReader( new RecyclableMemoryStreamManager(), Substitute.For(), new NullLogger()); private ShowNfoReader _showNfoReader; [Test] public async Task ParsingNfo_Should_Return_Error() { await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(@"https://www.themoviedb.org/movie/11-star-wars")); Either result = await _showNfoReader.Read(stream); result.IsLeft.Should().BeTrue(); } [Test] public async Task MetadataNfo_Should_Return_Nfo() { await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(@"")); Either result = await _showNfoReader.Read(stream); result.IsRight.Should().BeTrue(); } [Test] public async Task CombinationNfo_Should_Return_Nfo() { await using var stream = new MemoryStream( Encoding.UTF8.GetBytes( @" https://www.themoviedb.org/movie/11-star-wars")); Either result = await _showNfoReader.Read(stream); result.IsRight.Should().BeTrue(); } [Test] public async Task FullSample_Should_Return_Nfo() { // nested "title" in "seasondetails" may cause the last encountered title to be used for the show await using var stream = new MemoryStream( Encoding.UTF8.GetBytes( @" WandaVision WandaVision WandaVision 8.200000 105359 8.500000 7230 8.077950 3284 0 0 1 9 -1 -1 Wanda Maximoff and Vision—two super-powered beings living idealized suburban lives—begin to suspect that everything is not as it seems. 0 https://image.tmdb.org/t/p/original/dUWto4NaeJFrGx7jm8m3KLymUGf.jpg https://image.tmdb.org/t/p/original/8UsAB1hgwnd80eI2ociyppB6UXL.jpg https://assets.fanart.tv/fanart/tv/362392/tvposter/wandavision-6009571d1ed1f.jpg https://assets.fanart.tv/fanart/tv/362392/hdtvlogo/marvels-wandavision-5f6ac3b1e9458.png https://assets.fanart.tv/fanart/tv/362392/hdclearart/wandavision-6009b6875a285.png https://assets.fanart.tv/fanart/tv/362392/tvthumb/wandavision-603032a5349b9.jpg https://image.tmdb.org/t/p/original/7u443QI5xNIfLgNzEsV43CYZCWX.jpg https://image.tmdb.org/t/p/original/57vVjteucIF3bGnZj6PmaoJRScw.jpg https://assets.fanart.tv/fanart/tv/362392/showbackground/marvels-wandavision-5ff4fef387a43.jpg Australia:M 0 2021-03-29 85271 tt9140560 85271 362392 SuperHero 2021-01-15 2021 Ended Disney+ Elizabeth Olsen Wanda Maximoff / The Scarlet Witch 0 https://image.tmdb.org/t/p/original/wIU675y4dofIDVuhaNWPizJNtep.jpg Paul Bettany Vision / The Vision 1 https://image.tmdb.org/t/p/original/vcAVrAOZrpqmi37qjFdztRAv1u9.jpg Season 1 0.000000 0.000000 2021-03-12 06:15:51 -1 * All Seasons false 1 1824025 false 2 Season 02 1993428 false ")); Either result = await _showNfoReader.Read(stream); result.IsRight.Should().BeTrue(); foreach (ShowNfo nfo in result.RightToSeq()) { nfo.Title.Should().Be("WandaVision"); nfo.Year.Should().Be(2021); nfo.Plot.Should().Be( "Wanda Maximoff and Vision—two super-powered beings living idealized suburban lives—begin to suspect that everything is not as it seems."); nfo.ContentRating.Should().Be("Australia:M"); nfo.Genres.Should().BeEquivalentTo(new List { "SuperHero" }); nfo.Studios.Should().BeEquivalentTo(new List { "Disney+" }); nfo.Actors.Should().BeEquivalentTo( new List { new() { Name = "Elizabeth Olsen", Order = 0, Role = "Wanda Maximoff / The Scarlet Witch", Thumb = "https://image.tmdb.org/t/p/original/wIU675y4dofIDVuhaNWPizJNtep.jpg" }, new() { Name = "Paul Bettany", Order = 1, Role = "Vision / The Vision", Thumb = "https://image.tmdb.org/t/p/original/vcAVrAOZrpqmi37qjFdztRAv1u9.jpg" } }); nfo.UniqueIds.Should().BeEquivalentTo( new List { new() { Type = "imdb", Guid = "tt9140560", Default = false }, new() { Type = "tmdb", Guid = "85271", Default = true }, new() { Type = "tvdb", Guid = "362392", Default = false } }); nfo.Premiered.IsSome.Should().BeTrue(); foreach (DateTime premiered in nfo.Premiered) { premiered.Should().Be(new DateTime(2021, 1, 15)); } } } [Test] public async Task MetadataNfo_With_Outline_Should_Return_Nfo() { await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(@"Test Outline")); Either result = await _showNfoReader.Read(stream); result.IsRight.Should().BeTrue(); foreach (ShowNfo nfo in result.RightToSeq()) { nfo.Outline.Should().Be("Test Outline"); } } [Test] public async Task MetadataNfo_With_Tagline_Should_Return_Nfo() { await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(@"Test Tagline")); Either result = await _showNfoReader.Read(stream); result.IsRight.Should().BeTrue(); foreach (ShowNfo nfo in result.RightToSeq()) { nfo.Tagline.Should().Be("Test Tagline"); } } [Test] public async Task MetadataNfo_With_Tag_Should_Return_Nfo() { await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(@"Test Tag")); Either result = await _showNfoReader.Read(stream); result.IsRight.Should().BeTrue(); foreach (ShowNfo nfo in result.RightToSeq()) { nfo.Tags.Should().BeEquivalentTo(new List { "Test Tag" }); } } }