The Free Software Media System - Server Backend & API
Add regression test for #8696
Bond_009ba3e7027fee9
diff --git a/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.csindex e35ba15f61..82f0baf32e 100644--- a/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs+++ b/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs@@ -32,18 +32,15 @@ namespace Emby.Server.Implementations.LiveTv.Listingsprivate readonly IServerConfigurationManager _config;private readonly IHttpClientFactory _httpClientFactory;private readonly ILogger<XmlTvListingsProvider> _logger;- private readonly IFileSystem _fileSystem;public XmlTvListingsProvider(IServerConfigurationManager config,IHttpClientFactory httpClientFactory,- ILogger<XmlTvListingsProvider> logger,- IFileSystem fileSystem)+ ILogger<XmlTvListingsProvider> logger){_config = config;_httpClientFactory = httpClientFactory;_logger = logger;- _fileSystem = fileSystem;}public string Name => "XmlTV";diff --git a/tests/Jellyfin.Server.Implementations.Tests/LiveTv/Listings/XmlTvListingsProviderTests.cs b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/Listings/XmlTvListingsProviderTests.csnew file mode 100644index 0000000000..82ce8fc4ec--- /dev/null+++ b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/Listings/XmlTvListingsProviderTests.cs@@ -0,0 +1,70 @@+using System;+using System.IO;+using System.Linq;+using System.Net.Http;+using System.Threading;+using System.Threading.Tasks;+using AutoFixture;+using AutoFixture.AutoMoq;+using Emby.Server.Implementations.LiveTv.Listings;+using MediaBrowser.Model.LiveTv;+using Moq;+using Moq.Protected;+using Xunit;++namespace Jellyfin.Server.Implementations.Tests.LiveTv.Listings;++public class XmlTvListingsProviderTests+{+ private readonly Fixture _fixture;+ private readonly XmlTvListingsProvider _xmlTvListingsProvider;++ public XmlTvListingsProviderTests()+ {+ var messageHandler = new Mock<HttpMessageHandler>();+ messageHandler.Protected()+ .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())+ .Returns<HttpRequestMessage, CancellationToken>(+ (m, _) =>+ {+ return Task.FromResult(new HttpResponseMessage()+ {+ Content = new StreamContent(File.OpenRead(Path.Combine("Test Data/LiveTv/Listings/XmlTv", m.RequestUri!.Segments[^1])))+ });+ });++ 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);+ _xmlTvListingsProvider = _fixture.Create<XmlTvListingsProvider>();+ }++ [Theory]+ [InlineData("Test Data/LiveTv/Listings/XmlTv/notitle.xml")]+ [InlineData("https://example.com/notitle.xml")]+ public async Task GetProgramsAsync_NoTitle_Success(string path)+ {+ var info = new ListingsProviderInfo()+ {+ Path = path+ };++ var startDate = new DateTime(2022, 11, 4);+ var programs = await _xmlTvListingsProvider.GetProgramsAsync(info, "3297", startDate, startDate.AddDays(1), CancellationToken.None);+ var programsList = programs.ToList();+ Assert.Single(programsList);+ var program = programsList[0];+ Assert.Null(program.Name);+ Assert.Null(program.SeriesId);+ Assert.Null(program.EpisodeTitle);+ Assert.True(program.IsSports);+ Assert.True(program.HasImage);+ Assert.Equal("https://domain.tld/image.png", program.ImageUrl);+ Assert.Equal("3297", program.ChannelId);+ }+}diff --git a/tests/Jellyfin.Server.Implementations.Tests/Test Data/LiveTv/Listings/XmlTv/notitle.xml b/tests/Jellyfin.Server.Implementations.Tests/Test Data/LiveTv/Listings/XmlTv/notitle.xmlnew file mode 100644index 0000000000..5a5be79976--- /dev/null+++ b/tests/Jellyfin.Server.Implementations.Tests/Test Data/LiveTv/Listings/XmlTv/notitle.xml@@ -0,0 +1,10 @@+<tv date="20221104">+ <programme channel="3297" start="20221104130000 -0400" stop="20221105235959 -0400">+ <category lang="en">sports</category>+ <episode-num system="original-air-date">2022-11-04 13:00:00</episode-num>+ <icon height="" src="https://domain.tld/image.png" width=""/>+ <credits/>+ <video/>+ <date/>+ </programme>+</tv>