2020-11-01 11:07:24 +00:00
|
|
|
using System.Collections.Generic;
|
2020-10-27 21:17:03 +00:00
|
|
|
using System.Linq;
|
|
|
|
using Jackett.Common.Models;
|
2020-10-31 00:12:35 +00:00
|
|
|
using Jackett.Test.TestHelpers;
|
2020-10-27 21:17:03 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using Assert = NUnit.Framework.Assert;
|
|
|
|
|
|
|
|
namespace Jackett.Test.Common.Models
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class TorznabCapabilitiesCategoriesTests
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestConstructor()
|
|
|
|
{
|
|
|
|
var tcc = new TorznabCapabilitiesCategories();
|
2020-11-01 11:07:24 +00:00
|
|
|
Assert.IsEmpty(tcc.GetTorznabCategoryTree());
|
2020-10-27 21:17:03 +00:00
|
|
|
Assert.IsEmpty(tcc.GetTrackerCategories());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2020-11-01 11:07:24 +00:00
|
|
|
public void TestGetTrackerCategories()
|
2020-10-27 21:17:03 +00:00
|
|
|
{
|
|
|
|
var tcc = CreateTestDataset();
|
2020-11-01 11:07:24 +00:00
|
|
|
var trackerCats = tcc.GetTrackerCategories();
|
|
|
|
Assert.AreEqual(6, trackerCats.Count);
|
|
|
|
Assert.AreEqual("1", trackerCats[0]);
|
2020-10-27 21:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2020-11-01 11:07:24 +00:00
|
|
|
public void TestGetTorznabCategoryTree()
|
2020-10-27 21:17:03 +00:00
|
|
|
{
|
|
|
|
var tcc = CreateTestDataset();
|
2020-11-01 11:07:24 +00:00
|
|
|
|
|
|
|
// unsorted tree
|
|
|
|
var cats = tcc.GetTorznabCategoryTree();
|
|
|
|
var expected = new List<TorznabCategory>
|
|
|
|
{
|
|
|
|
TorznabCatType.Movies.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.Books.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.Console.CopyWithoutSubCategories(),
|
|
|
|
new TorznabCategory(100044, "Console/Xbox_c"),
|
2020-11-02 00:42:00 +00:00
|
|
|
new TorznabCategory(137107, "Console/Wii_c"),
|
2020-11-01 11:07:24 +00:00
|
|
|
new TorznabCategory(100040, "Console/Xbox_c2")
|
|
|
|
};
|
|
|
|
expected[0].SubCategories.Add(TorznabCatType.MoviesSD.CopyWithoutSubCategories());
|
|
|
|
expected[1].SubCategories.Add(TorznabCatType.BooksComics.CopyWithoutSubCategories());
|
|
|
|
expected[2].SubCategories.Add(TorznabCatType.ConsoleXBox.CopyWithoutSubCategories());
|
|
|
|
expected[2].SubCategories.Add(TorznabCatType.ConsoleWii.CopyWithoutSubCategories());
|
|
|
|
TestCategories.CompareCategoryTrees(expected, cats);
|
|
|
|
|
|
|
|
// sorted tree
|
|
|
|
cats = tcc.GetTorznabCategoryTree(true);
|
|
|
|
expected = new List<TorznabCategory>
|
|
|
|
{
|
|
|
|
TorznabCatType.Console.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.Movies.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.Books.CopyWithoutSubCategories(),
|
2020-11-02 00:42:00 +00:00
|
|
|
new TorznabCategory(137107, "Console/Wii_c"),
|
2020-11-01 11:07:24 +00:00
|
|
|
new TorznabCategory(100044, "Console/Xbox_c"),
|
|
|
|
new TorznabCategory(100040, "Console/Xbox_c2")
|
|
|
|
};
|
|
|
|
expected[0].SubCategories.Add(TorznabCatType.ConsoleWii.CopyWithoutSubCategories());
|
|
|
|
expected[0].SubCategories.Add(TorznabCatType.ConsoleXBox.CopyWithoutSubCategories());
|
|
|
|
expected[1].SubCategories.Add(TorznabCatType.MoviesSD.CopyWithoutSubCategories());
|
|
|
|
expected[2].SubCategories.Add(TorznabCatType.BooksComics.CopyWithoutSubCategories());
|
|
|
|
TestCategories.CompareCategoryTrees(expected, cats);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetTorznabCategoryList()
|
|
|
|
{
|
|
|
|
var tcc = CreateTestDataset();
|
|
|
|
|
|
|
|
// unsorted list
|
|
|
|
var cats = tcc.GetTorznabCategoryList();
|
|
|
|
var expected = new List<TorznabCategory>
|
|
|
|
{
|
|
|
|
TorznabCatType.Movies.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.MoviesSD.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.Books.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.BooksComics.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.Console.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.ConsoleXBox.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.ConsoleWii.CopyWithoutSubCategories(),
|
|
|
|
new TorznabCategory(100044, "Console/Xbox_c"),
|
2020-11-02 00:42:00 +00:00
|
|
|
new TorznabCategory(137107, "Console/Wii_c"),
|
2020-11-01 11:07:24 +00:00
|
|
|
new TorznabCategory(100040, "Console/Xbox_c2")
|
|
|
|
};
|
|
|
|
TestCategories.CompareCategoryTrees(expected, cats);
|
|
|
|
|
|
|
|
// sorted list
|
|
|
|
cats = tcc.GetTorznabCategoryList(true);
|
|
|
|
expected = new List<TorznabCategory>
|
|
|
|
{
|
|
|
|
TorznabCatType.Console.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.ConsoleWii.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.ConsoleXBox.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.Movies.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.MoviesSD.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.Books.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.BooksComics.CopyWithoutSubCategories(),
|
2020-11-02 00:42:00 +00:00
|
|
|
new TorznabCategory(137107, "Console/Wii_c"),
|
2020-11-01 11:07:24 +00:00
|
|
|
new TorznabCategory(100044, "Console/Xbox_c"),
|
|
|
|
new TorznabCategory(100040, "Console/Xbox_c2")
|
|
|
|
};
|
|
|
|
TestCategories.CompareCategoryTrees(expected, cats);
|
2020-10-27 21:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddCategoryMapping()
|
|
|
|
{
|
|
|
|
var tcc = new TorznabCapabilitiesCategories();
|
2020-11-01 11:07:24 +00:00
|
|
|
var cats = tcc.GetTorznabCategoryTree();
|
2020-10-27 21:17:03 +00:00
|
|
|
|
|
|
|
// add "int" category (parent category)
|
2020-11-01 11:07:24 +00:00
|
|
|
// + Movies
|
2020-10-27 21:17:03 +00:00
|
|
|
tcc.AddCategoryMapping("1", TorznabCatType.Movies);
|
2020-11-01 11:07:24 +00:00
|
|
|
var expected = new List<TorznabCategory>
|
|
|
|
{
|
|
|
|
TorznabCatType.Movies.CopyWithoutSubCategories()
|
|
|
|
};
|
|
|
|
TestCategories.CompareCategoryTrees(expected, cats);
|
2020-10-27 21:17:03 +00:00
|
|
|
|
|
|
|
// add "string" category (child category)
|
2020-11-01 11:07:24 +00:00
|
|
|
// - Movies
|
|
|
|
// + MoviesSD
|
2020-10-27 21:17:03 +00:00
|
|
|
tcc.AddCategoryMapping("mov_sd", TorznabCatType.MoviesSD);
|
2020-11-01 11:07:24 +00:00
|
|
|
expected[0].SubCategories.Add(TorznabCatType.MoviesSD.CopyWithoutSubCategories());
|
|
|
|
TestCategories.CompareCategoryTrees(expected, cats);
|
2020-10-27 21:17:03 +00:00
|
|
|
|
|
|
|
// add subcategory of books (child category)
|
2020-11-01 11:07:24 +00:00
|
|
|
// - Movies
|
|
|
|
// - MoviesSD
|
|
|
|
// + Books
|
|
|
|
// + BooksComics
|
2020-10-27 21:17:03 +00:00
|
|
|
tcc.AddCategoryMapping("33", TorznabCatType.BooksComics);
|
2020-11-01 11:07:24 +00:00
|
|
|
expected.Add(TorznabCatType.Books.CopyWithoutSubCategories());
|
|
|
|
expected[1].SubCategories.Add(TorznabCatType.BooksComics.CopyWithoutSubCategories());
|
|
|
|
TestCategories.CompareCategoryTrees(expected, cats);
|
2020-10-27 21:17:03 +00:00
|
|
|
|
|
|
|
// add int category with description => custom category. it's converted into 2 different categories
|
2020-11-01 11:07:24 +00:00
|
|
|
// - Movies
|
|
|
|
// - MoviesSD
|
|
|
|
// - Books
|
|
|
|
// - BooksComics
|
|
|
|
// + Console
|
|
|
|
// + ConsoleXBox
|
|
|
|
// + Custom Cat "Console/Xbox_c"
|
2020-10-28 19:00:48 +00:00
|
|
|
tcc.AddCategoryMapping("44", TorznabCatType.ConsoleXBox, "Console/Xbox_c");
|
2020-11-01 11:07:24 +00:00
|
|
|
expected.Add(TorznabCatType.Console.CopyWithoutSubCategories());
|
|
|
|
expected[2].SubCategories.Add(TorznabCatType.ConsoleXBox.CopyWithoutSubCategories());
|
|
|
|
expected.Add(new TorznabCategory(100044, "Console/Xbox_c"));
|
|
|
|
TestCategories.CompareCategoryTrees(expected, cats);
|
2020-10-27 21:17:03 +00:00
|
|
|
|
2020-11-02 00:42:00 +00:00
|
|
|
// add string category with description => custom category. it's converted into 2 different categories
|
2020-11-01 11:07:24 +00:00
|
|
|
// - Movies
|
|
|
|
// - MoviesSD
|
|
|
|
// - Books
|
|
|
|
// - BooksComics
|
|
|
|
// - Console
|
|
|
|
// - ConsoleXBox
|
|
|
|
// + ConsoleWii
|
|
|
|
// - Custom Cat "Console/Xbox_c"
|
2020-11-02 00:42:00 +00:00
|
|
|
// + Custom Cat "Console/Wii_c"
|
2020-10-27 21:17:03 +00:00
|
|
|
tcc.AddCategoryMapping("con_wii", TorznabCatType.ConsoleWii, "Console/Wii_c");
|
2020-11-01 11:07:24 +00:00
|
|
|
expected[2].SubCategories.Add(TorznabCatType.ConsoleWii.CopyWithoutSubCategories());
|
2020-11-02 00:42:00 +00:00
|
|
|
expected.Add(new TorznabCategory(137107, "Console/Wii_c"));
|
2020-11-01 11:07:24 +00:00
|
|
|
TestCategories.CompareCategoryTrees(expected, cats);
|
2020-10-27 21:17:03 +00:00
|
|
|
|
|
|
|
// add another int category with description that maps to ConsoleXbox (there are 2 tracker cats => 1 torznab cat)
|
2020-11-01 11:07:24 +00:00
|
|
|
// - Movies
|
|
|
|
// - MoviesSD
|
|
|
|
// - Books
|
|
|
|
// - BooksComics
|
|
|
|
// - Console
|
|
|
|
// - ConsoleXBox (this is not added again)
|
|
|
|
// - ConsoleWii
|
|
|
|
// - Custom Cat "Console/Xbox_c"
|
2020-11-02 00:42:00 +00:00
|
|
|
// - Custom Cat "Console/Wii_c"
|
2020-11-01 11:07:24 +00:00
|
|
|
// + Custom Cat "Console/Xbox_c2"
|
2020-10-28 19:00:48 +00:00
|
|
|
tcc.AddCategoryMapping("45", TorznabCatType.ConsoleXBox, "Console/Xbox_c2");
|
2020-11-01 11:07:24 +00:00
|
|
|
expected.Add(new TorznabCategory(100045, "Console/Xbox_c2"));
|
|
|
|
TestCategories.CompareCategoryTrees(expected, cats);
|
2020-10-27 21:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMapTorznabCapsToTrackers()
|
|
|
|
{
|
|
|
|
// MapTorznabCapsToTrackers: maps TorznabQuery cats => Tracker cats
|
|
|
|
var tcc = CreateTestDataset();
|
|
|
|
|
|
|
|
var query = new TorznabQuery(); // no cats
|
|
|
|
var trackerCats = tcc.MapTorznabCapsToTrackers(query);
|
|
|
|
Assert.AreEqual(0, trackerCats.Count);
|
|
|
|
|
|
|
|
query = new TorznabQuery // int category with subcategories (parent cat)
|
|
|
|
{
|
2021-05-16 18:13:54 +00:00
|
|
|
Categories = new[] { TorznabCatType.Movies.ID }
|
2020-10-27 21:17:03 +00:00
|
|
|
};
|
|
|
|
trackerCats = tcc.MapTorznabCapsToTrackers(query);
|
|
|
|
Assert.AreEqual(2, trackerCats.Count);
|
|
|
|
Assert.AreEqual("1", trackerCats[0]); // Movies
|
|
|
|
Assert.AreEqual("mov_sd", trackerCats[1]); // Movies SD
|
|
|
|
|
|
|
|
query = new TorznabQuery // string child category
|
|
|
|
{
|
2021-05-16 18:13:54 +00:00
|
|
|
Categories = new[] { TorznabCatType.MoviesSD.ID }
|
2020-10-27 21:17:03 +00:00
|
|
|
};
|
|
|
|
trackerCats = tcc.MapTorznabCapsToTrackers(query);
|
|
|
|
Assert.AreEqual(1, trackerCats.Count);
|
|
|
|
Assert.AreEqual("mov_sd", trackerCats[0]); // Movies SD
|
|
|
|
trackerCats = tcc.MapTorznabCapsToTrackers(query, true); // get parent
|
|
|
|
Assert.AreEqual(2, trackerCats.Count);
|
|
|
|
Assert.AreEqual("1", trackerCats[0]); // Movies
|
|
|
|
Assert.AreEqual("mov_sd", trackerCats[1]); // Movies SD
|
|
|
|
|
2020-11-02 00:42:00 +00:00
|
|
|
query = new TorznabQuery // duplicate category (1 torznab cat => 2 indexer cats)
|
2020-10-27 21:17:03 +00:00
|
|
|
{
|
2021-05-16 18:13:54 +00:00
|
|
|
Categories = new[] { TorznabCatType.ConsoleXBox.ID }
|
2020-10-27 21:17:03 +00:00
|
|
|
};
|
|
|
|
trackerCats = tcc.MapTorznabCapsToTrackers(query);
|
|
|
|
Assert.AreEqual(2, trackerCats.Count);
|
|
|
|
Assert.AreEqual("44", trackerCats[0]);
|
2020-11-01 11:07:24 +00:00
|
|
|
Assert.AreEqual("40", trackerCats[1]);
|
2020-10-27 21:17:03 +00:00
|
|
|
|
2020-11-02 00:42:00 +00:00
|
|
|
query = new TorznabQuery // custom cat "integer"
|
2020-10-27 21:17:03 +00:00
|
|
|
{
|
2021-05-16 18:13:54 +00:00
|
|
|
Categories = new[] { 100044 } // Console/Xbox_c
|
2020-10-27 21:17:03 +00:00
|
|
|
};
|
|
|
|
trackerCats = tcc.MapTorznabCapsToTrackers(query);
|
|
|
|
Assert.AreEqual(1, trackerCats.Count);
|
2020-11-02 00:42:00 +00:00
|
|
|
Assert.AreEqual("44", trackerCats[0]); // Console/Xbox_c
|
|
|
|
|
|
|
|
query = new TorznabQuery // custom cat "string"
|
|
|
|
{
|
2021-05-16 18:13:54 +00:00
|
|
|
Categories = new[] { 137107 } // Console/Wii_c
|
2020-11-02 00:42:00 +00:00
|
|
|
};
|
|
|
|
trackerCats = tcc.MapTorznabCapsToTrackers(query);
|
|
|
|
Assert.AreEqual(1, trackerCats.Count);
|
|
|
|
Assert.AreEqual("con_wii", trackerCats[0]); // Console/Wii_c
|
2020-10-27 21:17:03 +00:00
|
|
|
|
|
|
|
query = new TorznabQuery // unknown category
|
|
|
|
{
|
2021-05-16 18:13:54 +00:00
|
|
|
Categories = new[] { 9999 }
|
2020-10-27 21:17:03 +00:00
|
|
|
};
|
|
|
|
trackerCats = tcc.MapTorznabCapsToTrackers(query);
|
|
|
|
Assert.AreEqual(0, trackerCats.Count);
|
2020-11-02 00:42:00 +00:00
|
|
|
|
|
|
|
query = new TorznabQuery // unknown custom cat
|
|
|
|
{
|
2021-05-16 18:13:54 +00:00
|
|
|
Categories = new[] { 100001 }
|
2020-11-02 00:42:00 +00:00
|
|
|
};
|
|
|
|
trackerCats = tcc.MapTorznabCapsToTrackers(query);
|
|
|
|
Assert.AreEqual(0, trackerCats.Count);
|
2020-10-27 21:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMapTrackerCatToNewznab()
|
|
|
|
{
|
|
|
|
// MapTrackerCatToNewznab: maps Tracker cat ID => Torznab cats
|
|
|
|
var tcc = CreateTestDataset();
|
|
|
|
|
2020-11-02 00:42:00 +00:00
|
|
|
var torznabCats = tcc.MapTrackerCatToNewznab("1").ToList(); // "integer" id without custom cat
|
|
|
|
Assert.AreEqual(1, torznabCats.Count);
|
2020-10-27 21:17:03 +00:00
|
|
|
Assert.AreEqual(2000, torznabCats[0]);
|
|
|
|
|
2020-11-02 00:42:00 +00:00
|
|
|
torznabCats = tcc.MapTrackerCatToNewznab("mov_sd").ToList(); // "string" id without custom cat
|
2020-10-27 21:17:03 +00:00
|
|
|
Assert.AreEqual(1, torznabCats.Count);
|
|
|
|
Assert.AreEqual(2030, torznabCats[0]);
|
|
|
|
|
2020-11-02 00:42:00 +00:00
|
|
|
// "integer" id with custom cats. 44 and 40 maps to ConsoleXbox but different custom cat
|
2021-05-16 18:13:54 +00:00
|
|
|
torznabCats = tcc.MapTrackerCatToNewznab("44").ToList();
|
2020-10-27 21:17:03 +00:00
|
|
|
Assert.AreEqual(2, torznabCats.Count);
|
|
|
|
Assert.AreEqual(1040, torznabCats[0]);
|
|
|
|
Assert.AreEqual(100044, torznabCats[1]);
|
2020-11-01 11:07:24 +00:00
|
|
|
torznabCats = tcc.MapTrackerCatToNewznab("40").ToList();
|
2020-10-27 21:17:03 +00:00
|
|
|
Assert.AreEqual(2, torznabCats.Count);
|
|
|
|
Assert.AreEqual(1040, torznabCats[0]);
|
2020-11-01 11:07:24 +00:00
|
|
|
Assert.AreEqual(100040, torznabCats[1]);
|
2020-10-27 21:17:03 +00:00
|
|
|
|
2020-11-02 00:42:00 +00:00
|
|
|
// "string" id with custom cats
|
2021-05-16 18:13:54 +00:00
|
|
|
torznabCats = tcc.MapTrackerCatToNewznab("con_wii").ToList();
|
2020-11-02 00:42:00 +00:00
|
|
|
Assert.AreEqual(2, torznabCats.Count);
|
|
|
|
Assert.AreEqual(1030, torznabCats[0]);
|
|
|
|
Assert.AreEqual(137107, torznabCats[1]);
|
|
|
|
|
|
|
|
torznabCats = tcc.MapTrackerCatToNewznab("9999").ToList(); // unknown cat
|
|
|
|
Assert.AreEqual(0, torznabCats.Count);
|
|
|
|
|
|
|
|
torznabCats = tcc.MapTrackerCatToNewznab("con_unknown").ToList(); // unknown custom cat
|
|
|
|
Assert.AreEqual(0, torznabCats.Count);
|
2020-10-27 21:17:03 +00:00
|
|
|
|
|
|
|
torznabCats = tcc.MapTrackerCatToNewznab(null).ToList(); // null
|
|
|
|
Assert.AreEqual(0, torznabCats.Count);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMapTrackerCatDescToNewznab()
|
|
|
|
{
|
|
|
|
// MapTrackerCatDescToNewznab: maps Tracker cat Description => Torznab cats
|
|
|
|
var tcc = CreateTestDataset();
|
|
|
|
|
2020-11-02 00:42:00 +00:00
|
|
|
// "integer" id with custom cats
|
|
|
|
// Console/Xbox_c and Console/Xbox_c2 maps to ConsoleXbox but different custom cat
|
|
|
|
var torznabCats = tcc.MapTrackerCatDescToNewznab("Console/Xbox_c").ToList();
|
2020-10-27 21:17:03 +00:00
|
|
|
Assert.AreEqual(2, torznabCats.Count);
|
|
|
|
Assert.AreEqual(1040, torznabCats[0]);
|
|
|
|
Assert.AreEqual(100044, torznabCats[1]);
|
|
|
|
torznabCats = tcc.MapTrackerCatDescToNewznab("Console/Xbox_c2").ToList();
|
|
|
|
Assert.AreEqual(2, torznabCats.Count);
|
|
|
|
Assert.AreEqual(1040, torznabCats[0]);
|
2020-11-01 11:07:24 +00:00
|
|
|
Assert.AreEqual(100040, torznabCats[1]);
|
2020-10-27 21:17:03 +00:00
|
|
|
|
2020-11-02 00:42:00 +00:00
|
|
|
// "string" id with custom cats
|
2020-10-27 21:17:03 +00:00
|
|
|
torznabCats = tcc.MapTrackerCatDescToNewznab("Console/Wii_c").ToList();
|
2020-11-02 00:42:00 +00:00
|
|
|
Assert.AreEqual(2, torznabCats.Count);
|
2020-10-27 21:17:03 +00:00
|
|
|
Assert.AreEqual(1030, torznabCats[0]);
|
2020-11-02 00:42:00 +00:00
|
|
|
Assert.AreEqual(137107, torznabCats[1]);
|
2020-10-27 21:17:03 +00:00
|
|
|
|
2020-11-02 00:42:00 +00:00
|
|
|
torznabCats = tcc.MapTrackerCatDescToNewznab("Unknown/Cat").ToList(); // unknown cat
|
2020-10-27 21:17:03 +00:00
|
|
|
Assert.AreEqual(0, torznabCats.Count);
|
|
|
|
|
|
|
|
torznabCats = tcc.MapTrackerCatDescToNewznab(null).ToList(); // null
|
|
|
|
Assert.AreEqual(0, torznabCats.Count);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2020-11-08 22:27:54 +00:00
|
|
|
public void TestSupportedCategories()
|
2020-10-27 21:17:03 +00:00
|
|
|
{
|
|
|
|
var tcc = CreateTestDataset();
|
|
|
|
|
2021-05-16 18:13:54 +00:00
|
|
|
Assert.AreEqual(new[] { TorznabCatType.Movies.ID }, // parent cat
|
|
|
|
tcc.SupportedCategories(new[] { TorznabCatType.Movies.ID }));
|
|
|
|
Assert.AreEqual(new[] { TorznabCatType.MoviesSD.ID }, // child cat
|
|
|
|
tcc.SupportedCategories(new[] { TorznabCatType.MoviesSD.ID }));
|
|
|
|
Assert.AreEqual(new[] { TorznabCatType.Movies.ID, TorznabCatType.MoviesSD.ID }, // parent & child cat
|
|
|
|
tcc.SupportedCategories(new[] { TorznabCatType.Movies.ID, TorznabCatType.MoviesSD.ID }));
|
|
|
|
Assert.AreEqual(new[] { 100040 }, // custom cat
|
|
|
|
tcc.SupportedCategories(new[] { 100040 }));
|
|
|
|
Assert.AreEqual(new[] { TorznabCatType.Movies.ID }, // mixed good and bad
|
|
|
|
tcc.SupportedCategories(new[] { TorznabCatType.Movies.ID, 9999 }));
|
|
|
|
Assert.AreEqual(new int[] { }, // not supported child cat
|
|
|
|
tcc.SupportedCategories(new[] { TorznabCatType.Movies3D.ID }));
|
|
|
|
Assert.AreEqual(new int[] { }, // unknown cat
|
|
|
|
tcc.SupportedCategories(new[] { 9999 }));
|
|
|
|
Assert.AreEqual(new int[] { }, // unknown custom cat
|
|
|
|
tcc.SupportedCategories(new[] { 100001 }));
|
|
|
|
Assert.AreEqual(new int[] { }, // empty list
|
|
|
|
tcc.SupportedCategories(new int[] { }));
|
|
|
|
Assert.AreEqual(new int[] { }, // null
|
2020-11-08 22:27:54 +00:00
|
|
|
tcc.SupportedCategories(null));
|
2020-10-27 21:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestConcat()
|
|
|
|
{
|
|
|
|
var lhs = new TorznabCapabilitiesCategories();
|
|
|
|
var rhs = CreateTestDataset();
|
|
|
|
lhs.Concat(rhs);
|
2020-11-01 11:07:24 +00:00
|
|
|
var expected = new List<TorznabCategory>
|
|
|
|
{
|
|
|
|
TorznabCatType.Movies.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.Books.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.Console.CopyWithoutSubCategories()
|
|
|
|
};
|
|
|
|
expected[0].SubCategories.Add(TorznabCatType.MoviesSD.CopyWithoutSubCategories());
|
|
|
|
expected[1].SubCategories.Add(TorznabCatType.BooksComics.CopyWithoutSubCategories());
|
|
|
|
expected[2].SubCategories.Add(TorznabCatType.ConsoleXBox.CopyWithoutSubCategories());
|
|
|
|
expected[2].SubCategories.Add(TorznabCatType.ConsoleWii.CopyWithoutSubCategories());
|
|
|
|
TestCategories.CompareCategoryTrees(expected, lhs.GetTorznabCategoryTree()); // removed custom cats
|
2020-10-27 21:17:03 +00:00
|
|
|
Assert.AreEqual(0, lhs.GetTrackerCategories().Count); // removed tracker mapping
|
2020-11-01 11:07:24 +00:00
|
|
|
|
|
|
|
lhs = CreateTestDataset();
|
|
|
|
rhs = CreateTestDataset();
|
|
|
|
lhs.Concat(rhs);
|
|
|
|
expected = new List<TorznabCategory>
|
|
|
|
{
|
|
|
|
TorznabCatType.Movies.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.Books.CopyWithoutSubCategories(),
|
|
|
|
TorznabCatType.Console.CopyWithoutSubCategories(),
|
|
|
|
new TorznabCategory(100044, "Console/Xbox_c"),
|
2020-11-02 00:42:00 +00:00
|
|
|
new TorznabCategory(137107, "Console/Wii_c"),
|
2020-11-01 11:07:24 +00:00
|
|
|
new TorznabCategory(100040, "Console/Xbox_c2")
|
|
|
|
};
|
|
|
|
expected[0].SubCategories.Add(TorznabCatType.MoviesSD.CopyWithoutSubCategories());
|
|
|
|
expected[1].SubCategories.Add(TorznabCatType.BooksComics.CopyWithoutSubCategories());
|
|
|
|
expected[2].SubCategories.Add(TorznabCatType.ConsoleXBox.CopyWithoutSubCategories());
|
|
|
|
expected[2].SubCategories.Add(TorznabCatType.ConsoleWii.CopyWithoutSubCategories());
|
|
|
|
TestCategories.CompareCategoryTrees(expected, lhs.GetTorznabCategoryTree()); // check there are not duplicates
|
2020-10-27 21:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static TorznabCapabilitiesCategories CreateTestDataset()
|
|
|
|
{
|
|
|
|
var tcc = new TorznabCapabilitiesCategories();
|
2020-10-31 00:12:35 +00:00
|
|
|
TestCategories.AddTestCategories(tcc);
|
2020-10-27 21:17:03 +00:00
|
|
|
return tcc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|