Load data files

This commit is contained in:
Ben Magee 2018-12-12 22:37:15 +00:00
parent 6ce4672b10
commit 757d3e7c7d
3 changed files with 192 additions and 10 deletions

View File

@ -20,4 +20,10 @@
<ProjectReference Include="..\..\Emby.XmlTv\Emby.XmlTv\Emby.XmlTv.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="XmlFiles\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@ -8,11 +8,18 @@ namespace Jellyfin.XmlTv.Test
[TestFixture]
public class XmlTvReaderDateTimeTests
{
private string _testFilePath;
[SetUp]
public void BeforeEachTest()
{
_testFilePath = Path.GetFullPath(Path.Combine("XmlFiles", "MultilanguageData.xml"));
}
[Test]
public void ShouldHandlePartDates()
{
var testFile = Path.GetFullPath(@"MultilanguageData.xml");
var reader = new XmlTvReader(testFile, "es");
var reader = new XmlTvReader(_testFilePath, "es");
Assert.AreEqual(Parse("01 Jan 2016 00:00:00"), reader.ParseDate("2016"));
Assert.AreEqual(Parse("01 Jan 2016 00:00:00"), reader.ParseDate("201601"));
@ -25,8 +32,7 @@ namespace Jellyfin.XmlTv.Test
[Test]
public void ShouldHandleDateWithOffset()
{
var testFile = Path.GetFullPath(@"MultilanguageData.xml");
var reader = new XmlTvReader(testFile, "es");
var reader = new XmlTvReader(_testFilePath, "es");
// parse variations on 1:00AM
Assert.AreEqual(Parse("01 Jan 2016 12:00:00"), reader.ParseDate("20160101120000 +0000"));
@ -44,8 +50,7 @@ namespace Jellyfin.XmlTv.Test
[Test]
public void ShouldHandlePartDatesWithOffset()
{
var testFile = Path.GetFullPath(@"MultilanguageData.xml");
var reader = new XmlTvReader(testFile, "es");
var reader = new XmlTvReader(_testFilePath, "es");
Assert.AreEqual(Parse("01 Jan 2016 01:00:00"), reader.ParseDate("2016 -0100"));
Assert.AreEqual(Parse("01 Jan 2016 01:00:00"), reader.ParseDate("201601 -0100"));
@ -58,8 +63,7 @@ namespace Jellyfin.XmlTv.Test
[Test]
public void ShouldHandleSpaces()
{
var testFile = Path.GetFullPath(@"MultilanguageData.xml");
var reader = new XmlTvReader(testFile, "es");
var reader = new XmlTvReader(_testFilePath, "es");
// parse variations on 1:00AM
Assert.AreEqual(Parse("01 Jan 2016 12:00:00"), reader.ParseDate("20160101120000 +000"));
@ -70,8 +74,7 @@ namespace Jellyfin.XmlTv.Test
[Test]
public void ShouldHandleSpaces2()
{
var testFile = Path.GetFullPath(@"MultilanguageData.xml");
var reader = new XmlTvReader(testFile, "es");
var reader = new XmlTvReader(_testFilePath, "es");
// parse variations on 1:00AM
Assert.AreEqual(Parse("01 Jan 2016 12:00:00"), reader.ParseDate("20160101120000 0"));

View File

@ -0,0 +1,173 @@
using System;
using System.IO;
using System.Linq;
using System.Threading;
using Emby.XmlTv.Classes;
using NUnit.Framework;
namespace Jellyfin.XmlTv.Test
{
[TestFixture]
public class XmlTvReaderLanguageTests
{
private string _testFilePath;
[SetUp]
public void BeforeEachTest()
{
_testFilePath = Path.GetFullPath(Path.Combine("XmlFiles", "MultilanguageData.xml"));
}
/*
<title lang="es">Homes Under the Hammer - Spanish</title>
<title lang="es">Homes Under the Hammer - Spanish 2</title>
<title lang="en">Homes Under the Hammer - English</title>
<title lang="en">Homes Under the Hammer - English 2</title>
<title lang="">Homes Under the Hammer - Empty Language</title>
<title lang="">Homes Under the Hammer - Empty Language 2</title>
<title>Homes Under the Hammer - No Language</title>
<title>Homes Under the Hammer - No Language 2</title>
*/
/* Expected Behaviour:
- Language = Null Homes Under the Hammer - No Language
- Language = "" Homes Under the Hammer - No Language
- Language = es Homes Under the Hammer - Spanish
- Language = en Homes Under the Hammer - English
*/
[Test]
public void Should_Return_The_First_Matching_Language_ES()
{
var reader = new XmlTvReader(_testFilePath, "es");
var channel = reader.GetChannels().FirstOrDefault();
Assert.IsNotNull(channel);
var startDate = new DateTime(2015, 11, 26);
var cancellationToken = new CancellationToken();
var programme = reader.GetProgrammes(channel.Id, startDate, startDate.AddDays(1), cancellationToken).FirstOrDefault();
Assert.IsNotNull(programme);
Assert.AreEqual("Homes Under the Hammer - Spanish", programme.Title);
Assert.AreEqual(1, programme.Categories.Count);
Assert.AreEqual("Property - Spanish", programme.Categories[0]);
}
[Test]
public void Should_Return_The_First_Matching_Language_EN()
{
var reader = new XmlTvReader(_testFilePath, "en");
var channel = reader.GetChannels().FirstOrDefault();
Assert.IsNotNull(channel);
var startDate = new DateTime(2015, 11, 26);
var cancellationToken = new CancellationToken();
var programme = reader.GetProgrammes(channel.Id, startDate, startDate.AddDays(1), cancellationToken).FirstOrDefault();
Assert.IsNotNull(programme);
Assert.AreEqual("Homes Under the Hammer - English", programme.Title);
Assert.AreEqual(1, programme.Categories.Count);
Assert.AreEqual("Property - English", programme.Categories[0]);
}
[Test]
public void Should_Return_The_First_Matching_With_No_Language()
{
var reader = new XmlTvReader(_testFilePath, null);
var channel = reader.GetChannels().FirstOrDefault();
Assert.IsNotNull(channel);
var startDate = new DateTime(2015, 11, 26);
var cancellationToken = new CancellationToken();
var programme = reader.GetProgrammes(channel.Id, startDate, startDate.AddDays(1), cancellationToken).FirstOrDefault();
Assert.IsNotNull(programme);
Assert.AreEqual("Homes Under the Hammer - No Language", programme.Title);
Assert.AreEqual(1, programme.Categories.Count);
Assert.AreEqual("Property - No Language", programme.Categories[0]);
}
[Test]
public void Should_Return_The_First_Matching_With_Empty_Language()
{
var reader = new XmlTvReader(_testFilePath, String.Empty);
var channel = reader.GetChannels().FirstOrDefault();
Assert.IsNotNull(channel);
var startDate = new DateTime(2015, 11, 26);
var cancellationToken = new CancellationToken();
var programme = reader.GetProgrammes(channel.Id, startDate, startDate.AddDays(1), cancellationToken).FirstOrDefault();
Assert.IsNotNull(programme);
Assert.AreEqual("Homes Under the Hammer - Empty Language", programme.Title);
Assert.AreEqual(1, programme.Categories.Count);
Assert.AreEqual("Property - Empty Language", programme.Categories[0]);
}
[Test]
public void Should_Return_The_First_When_NoMatchFound()
{
var reader = new XmlTvReader(_testFilePath, "es"); // There are no titles or categories for spanish
var channel = reader.GetChannels().FirstOrDefault();
Assert.IsNotNull(channel);
var startDate = new DateTime(2015, 11, 26);
var cancellationToken = new CancellationToken();
var programme = reader.GetProgrammes(channel.Id, startDate, startDate.AddDays(1), cancellationToken).Skip(1).FirstOrDefault();
Assert.IsNotNull(programme);
Assert.AreEqual("Homes Under the Hammer - English", programme.Title);
// Should return all categories
Assert.AreEqual(2, programme.Categories.Count);
Assert.IsTrue(programme.Categories.Contains("Property - English"));
Assert.IsTrue(programme.Categories.Contains("Property - Empty Language"));
}
[Test]
public void Should_Return_The_First_When_NoLanguage()
{
var reader = new XmlTvReader(_testFilePath, null);
var channel = reader.GetChannels().FirstOrDefault();
Assert.IsNotNull(channel);
var startDate = new DateTime(2015, 11, 26);
var cancellationToken = new CancellationToken();
var programme = reader.GetProgrammes(channel.Id, startDate, startDate.AddDays(1), cancellationToken).Skip(1).FirstOrDefault();
Assert.IsNotNull(programme);
Assert.AreEqual("Homes Under the Hammer - English", programme.Title); // Should return the first in the list
// Should return all categories
Assert.AreEqual(2, programme.Categories.Count);
Assert.IsTrue(programme.Categories.Contains("Property - English"));
Assert.IsTrue(programme.Categories.Contains("Property - Empty Language"));
}
[Test]
public void Should_Return_All_Languages()
{
var reader = new XmlTvReader(_testFilePath);
var cancellationToken = new CancellationToken();
var results = reader.GetLanguages(cancellationToken);
Assert.IsNotNull(results);
foreach (var result in results)
{
Console.WriteLine("{0} - {1}", result.Name, result.Relevance);
}
Assert.AreEqual(2, results.Count);
Assert.AreEqual("en", results[0].Name);
Assert.AreEqual(11, results[0].Relevance);
Assert.AreEqual("es", results[1].Name);
Assert.AreEqual(3, results[1].Relevance);
}
}
}