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 MovieNfoReaderTests { [SetUp] public void SetUp() => _movieNfoReader = new MovieNfoReader( new RecyclableMemoryStreamManager(), Substitute.For(), new NullLogger()); private MovieNfoReader _movieNfoReader; [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 _movieNfoReader.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 _movieNfoReader.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 _movieNfoReader.Read(stream); result.IsRight.Should().BeTrue(); } [Test] public async Task FullSample_Should_Return_Nfo() { await using var stream = new MemoryStream( Encoding.UTF8.GetBytes( @" Zack Snyder's Justice League Zack Snyder's Justice League Justice League 2 8.300000 197786 8.700000 3461 8.195670 4247 0 140 Determined to ensure Superman's ultimate sacrifice was not in vain, Bruce Wayne aligns forces with Diana Prince with plans to recruit a team of metahumans to protect the world from an approaching threat of catastrophic proportions. 242 https://assets.fanart.tv/fanart/movies/791373/movieposter/zack-snyders-justice-league-603fdb873f474.jpg https://image.tmdb.org/t/p/original/tnAuB8q5vv7Ax9UAEje5Xi4BXik.jpg https://assets.fanart.tv/fanart/movies/791373/moviethumb/zack-snyders-justice-league-6050310135cf6.jpg https://image.tmdb.org/t/p/original/wcYBuOZDP6Vi8Ye4qax3Zx9dCan.jpg https://assets.fanart.tv/fanart/movies/791373/movieposter/zack-snyders-justice-league-603fdba9bdd16.jpg https://assets.fanart.tv/fanart/movies/791373/hdmovielogo/zack-snyders-justice-league-5ed3f2e4952e9.png https://assets.fanart.tv/fanart/movies/791373/moviebanner/zack-snyders-justice-league-6050049514d4c.jpg https://assets.fanart.tv/fanart/movies/791373/moviebackground/zack-snyders-justice-league-5fee5b9fe0e0d.jpg https://image.tmdb.org/t/p/original/43NwryODVEsbBDC0jK3wYfVyb5q.jpg Australia:M 0 791373 tt12361974 791373 SuperHero TV Recording Justice League Collection Based on the DC Comics superhero team USA Chris Terrio Zack Snyder 2021-03-18 2021 Warner Bros. Pictures eng Ben Affleck Bruce Wayne / Batman 0 https://image.tmdb.org/t/p/original/u525jeDOzg9hVdvYfeehTGnw7Aa.jpg Henry Cavill Clark Kent / Superman / Kal-El 1 https://image.tmdb.org/t/p/original/hErUwonrQgY5Y7RfxOfv8Fq11MB.jpg Gal Gadot Diana Prince / Wonder Woman 2 https://image.tmdb.org/t/p/original/fysvehTvU6bE3JgxaOTRfvQJzJ4.jpg 0.000000 0.000000 2021-03-26 11:35:50 ")); Either result = await _movieNfoReader.Read(stream); result.IsRight.Should().BeTrue(); foreach (MovieNfo nfo in result.RightToSeq()) { nfo.Title.Should().Be("Zack Snyder's Justice League"); nfo.SortTitle.Should().Be("Justice League 2"); nfo.Outline.Should().BeNullOrEmpty(); nfo.Year.Should().Be(2021); nfo.ContentRating.Should().Be("Australia:M"); nfo.Premiered.IsSome.Should().BeTrue(); foreach (DateTime premiered in nfo.Premiered) { premiered.Should().Be(new DateTime(2021, 03, 18)); } nfo.Plot.Should().Be( "Determined to ensure Superman's ultimate sacrifice was not in vain, Bruce Wayne aligns forces with Diana Prince with plans to recruit a team of metahumans to protect the world from an approaching threat of catastrophic proportions."); // nfo.Tagline.Should().BeNullOrEmpty(); nfo.Genres.Should().BeEquivalentTo(new List { "SuperHero" }); nfo.Tags.Should().BeEquivalentTo(new List { "TV Recording" }); nfo.Studios.Should().BeEquivalentTo(new List { "Warner Bros. Pictures" }); nfo.Actors.Should().BeEquivalentTo( new List { new() { Name = "Ben Affleck", Order = 0, Role = "Bruce Wayne / Batman", Thumb = "https://image.tmdb.org/t/p/original/u525jeDOzg9hVdvYfeehTGnw7Aa.jpg" }, new() { Name = "Henry Cavill", Order = 1, Role = "Clark Kent / Superman / Kal-El", Thumb = "https://image.tmdb.org/t/p/original/hErUwonrQgY5Y7RfxOfv8Fq11MB.jpg" }, new() { Name = "Gal Gadot", Order = 2, Role = "Diana Prince / Wonder Woman", Thumb = "https://image.tmdb.org/t/p/original/fysvehTvU6bE3JgxaOTRfvQJzJ4.jpg" } }); nfo.Writers.Should().BeEquivalentTo(new List { "Chris Terrio" }); nfo.Directors.Should().BeEquivalentTo(new List { "Zack Snyder" }); nfo.UniqueIds.Should().BeEquivalentTo( new List { new() { Type = "imdb", Guid = "tt12361974", Default = false }, new() { Type = "tmdb", Guid = "791373", Default = true } }); } } [Test] public async Task MetadataNfo_With_Tag_Should_Return_Nfo() { await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(@"Test Tag")); Either result = await _movieNfoReader.Read(stream); result.IsRight.Should().BeTrue(); foreach (MovieNfo nfo in result.RightToSeq()) { nfo.Tags.Should().BeEquivalentTo(new List { "Test Tag" }); } } [Test] public async Task MetadataNfo_With_Outline_Should_Return_Nfo() { await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(@"Test Outline")); Either result = await _movieNfoReader.Read(stream); result.IsRight.Should().BeTrue(); foreach (MovieNfo nfo in result.RightToSeq()) { nfo.Outline.Should().Be("Test Outline"); } } }