public void TestConstructor()
        {
            var tcc = new TorznabCapabilitiesCategories();

            Assert.IsEmpty(tcc.GetTorznabCategories());
            Assert.IsEmpty(tcc.GetTrackerCategories());
        }
        private static TorznabCapabilitiesCategories CreateTestDataset()
        {
            var tcc = new TorznabCapabilitiesCategories();

            TestCategories.AddTestCategories(tcc);
            return(tcc);
        }
        public void TestConcat()
        {
            var lhs = new TorznabCapabilitiesCategories();
            var rhs = CreateTestDataset();

            lhs.Concat(rhs);
            Assert.AreEqual(5, lhs.GetTorznabCategories().Count); // removed custom cats
            Assert.AreEqual(0, lhs.GetTrackerCategories().Count); // removed tracker mapping
        }
Beispiel #4
0
        private static TorznabCapabilitiesCategories CreateTestDataset()
        {
            var tcc = new TorznabCapabilitiesCategories();

            tcc.AddCategoryMapping("1", TorznabCatType.Movies);
            tcc.AddCategoryMapping("mov_sd", TorznabCatType.MoviesSD);
            tcc.AddCategoryMapping("33", TorznabCatType.BooksComics);
            tcc.AddCategoryMapping("44", TorznabCatType.ConsoleXBox, "Console/Xbox_c");
            tcc.AddCategoryMapping("con_wii", TorznabCatType.ConsoleWii, "Console/Wii_c");
            tcc.AddCategoryMapping("45", TorznabCatType.ConsoleXBox, "Console/Xbox_c2");
            return(tcc);
        }
Beispiel #5
0
 public static void AddTestCategories(TorznabCapabilitiesCategories tcc)
 {
     // these categories are chosen to test all kind of category types:
     // - with integer and string id
     // - with and without description
     // - parent and child categories
     // - custom categories are not added automatically but they are created from other categories automatically
     tcc.AddCategoryMapping("1", TorznabCatType.Movies);
     tcc.AddCategoryMapping("mov_sd", TorznabCatType.MoviesSD);
     tcc.AddCategoryMapping("33", TorznabCatType.BooksComics);
     tcc.AddCategoryMapping("44", TorznabCatType.ConsoleXBox, "Console/Xbox_c");
     tcc.AddCategoryMapping("con_wii", TorznabCatType.ConsoleWii, "Console/Wii_c");
     tcc.AddCategoryMapping("45", TorznabCatType.ConsoleXBox, "Console/Xbox_c2");
 }
        public void TestAddCategoryMapping()
        {
            var tcc  = new TorznabCapabilitiesCategories();
            var cats = tcc.GetTorznabCategories();

            // add "int" category (parent category)
            tcc.AddCategoryMapping("1", TorznabCatType.Movies);
            Assert.AreEqual(1, cats.Count);
            Assert.AreEqual(2000, cats[0].ID);

            // add "string" category (child category)
            tcc.AddCategoryMapping("mov_sd", TorznabCatType.MoviesSD);
            Assert.AreEqual(2, cats.Count);
            Assert.AreEqual(2030, cats[1].ID);

            // add subcategory of books (child category)
            tcc.AddCategoryMapping("33", TorznabCatType.BooksComics);
            Assert.AreEqual(3, cats.Count);
            Assert.AreEqual(7030, cats[2].ID);

            // add int category with description => custom category. it's converted into 2 different categories
            tcc.AddCategoryMapping("44", TorznabCatType.ConsoleXBox, "Console/Xbox_c");
            Assert.AreEqual(5, cats.Count);
            Assert.AreEqual(1040, cats[3].ID);
            Assert.AreEqual(100044, cats[4].ID);

            // TODO: we should add a way to add custom categories for string categories
            // https://github.com/Sonarr/Sonarr/wiki/Implementing-a-Torznab-indexer#caps-endpoint
            // add string category with description. it's converted into 1 category
            tcc.AddCategoryMapping("con_wii", TorznabCatType.ConsoleWii, "Console/Wii_c");
            Assert.AreEqual(6, cats.Count);
            Assert.AreEqual(1030, cats[5].ID);

            // add another int category with description that maps to ConsoleXbox (there are 2 tracker cats => 1 torznab cat)
            tcc.AddCategoryMapping("45", TorznabCatType.ConsoleXBox, "Console/Xbox_c2");
            Assert.AreEqual(7, cats.Count);
            Assert.AreEqual(100045, cats[6].ID); // 1040 is duplicated and it is not added
        }
        public void TestConcat()
        {
            var lhs = new TorznabCapabilitiesCategories();
            var rhs = CreateTestDataset();

            lhs.Concat(rhs);
            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
            Assert.AreEqual(0, lhs.GetTrackerCategories().Count);                        // removed tracker mapping

            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"),
                new TorznabCategory(137107, "Console/Wii_c"),
                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
        }
        public void TestAddCategoryMapping()
        {
            var tcc  = new TorznabCapabilitiesCategories();
            var cats = tcc.GetTorznabCategoryTree();

            // add "int" category (parent category)
            // + Movies
            tcc.AddCategoryMapping("1", TorznabCatType.Movies);
            var expected = new List <TorznabCategory>
            {
                TorznabCatType.Movies.CopyWithoutSubCategories()
            };

            TestCategories.CompareCategoryTrees(expected, cats);

            // add "string" category (child category)
            // - Movies
            //   + MoviesSD
            tcc.AddCategoryMapping("mov_sd", TorznabCatType.MoviesSD);
            expected[0].SubCategories.Add(TorznabCatType.MoviesSD.CopyWithoutSubCategories());
            TestCategories.CompareCategoryTrees(expected, cats);

            // add subcategory of books (child category)
            // - Movies
            //   - MoviesSD
            // + Books
            //   + BooksComics
            tcc.AddCategoryMapping("33", TorznabCatType.BooksComics);
            expected.Add(TorznabCatType.Books.CopyWithoutSubCategories());
            expected[1].SubCategories.Add(TorznabCatType.BooksComics.CopyWithoutSubCategories());
            TestCategories.CompareCategoryTrees(expected, cats);

            // add int category with description => custom category. it's converted into 2 different categories
            // - Movies
            //   - MoviesSD
            // - Books
            //   - BooksComics
            // + Console
            //   + ConsoleXBox
            // + Custom Cat "Console/Xbox_c"
            tcc.AddCategoryMapping("44", TorznabCatType.ConsoleXBox, "Console/Xbox_c");
            expected.Add(TorznabCatType.Console.CopyWithoutSubCategories());
            expected[2].SubCategories.Add(TorznabCatType.ConsoleXBox.CopyWithoutSubCategories());
            expected.Add(new TorznabCategory(100044, "Console/Xbox_c"));
            TestCategories.CompareCategoryTrees(expected, cats);

            // add string category with description => custom category. it's converted into 2 different categories
            // - Movies
            //   - MoviesSD
            // - Books
            //   - BooksComics
            // - Console
            //   - ConsoleXBox
            //   + ConsoleWii
            // - Custom Cat "Console/Xbox_c"
            // + Custom Cat "Console/Wii_c"
            tcc.AddCategoryMapping("con_wii", TorznabCatType.ConsoleWii, "Console/Wii_c");
            expected[2].SubCategories.Add(TorznabCatType.ConsoleWii.CopyWithoutSubCategories());
            expected.Add(new TorznabCategory(137107, "Console/Wii_c"));
            TestCategories.CompareCategoryTrees(expected, cats);

            // add another int category with description that maps to ConsoleXbox (there are 2 tracker cats => 1 torznab cat)
            // - Movies
            //   - MoviesSD
            // - Books
            //   - BooksComics
            // - Console
            //   - ConsoleXBox (this is not added again)
            //   - ConsoleWii
            // - Custom Cat "Console/Xbox_c"
            // - Custom Cat "Console/Wii_c"
            // + Custom Cat "Console/Xbox_c2"
            tcc.AddCategoryMapping("45", TorznabCatType.ConsoleXBox, "Console/Xbox_c2");
            expected.Add(new TorznabCategory(100045, "Console/Xbox_c2"));
            TestCategories.CompareCategoryTrees(expected, cats);
        }