Add regression test for #8696

pull/8698/head
Bond_009 2 years ago
parent d929793251
commit ba3e7027fe

@ -32,18 +32,15 @@ namespace Emby.Server.Implementations.LiveTv.Listings
private 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";

@ -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);
}
}

@ -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>
Loading…
Cancel
Save