public void InitializeNewznabIndexers_should_initialize_new_indexers_only()
        {
            //Setup
            var definitions = Builder <NewznabDefinition> .CreateListOfSize(5)
                              .All()
                              .With(d => d.Id = 0)
                              .TheFirst(2)
                              .With(d => d.Url = "http://www.nzbdrone2.com")
                              .TheLast(3)
                              .With(d => d.Url = "http://www.nzbdrone.com")
                              .Build();


            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            db.Insert(definitions[0]);
            db.Insert(definitions[2]);

            //Act
            Mocker.Resolve <NewznabProvider>().InitializeNewznabIndexers(definitions);

            //Assert
            var result = db.Fetch <NewznabDefinition>();

            result.Should().HaveCount(2);
            result.Where(d => d.Url == "http://www.nzbdrone.com").Should().HaveCount(1);
            result.Where(d => d.Url == "http://www.nzbdrone2.com").Should().HaveCount(1);
        }
Exemplo n.º 2
0
        public void get_season_files()
        {
            var firstSeriesFiles = Builder <EpisodeFile> .CreateListOfSize(10)
                                   .All()
                                   .With(c => c.Quality      = QualityTypes.SDTV)
                                   .With(s => s.SeriesId     = 12)
                                   .With(s => s.SeasonNumber = 1)
                                   .Build();

            var secondSeriesFiles = Builder <EpisodeFile> .CreateListOfSize(10)
                                    .All()
                                    .With(c => c.Quality      = QualityTypes.SDTV)
                                    .With(s => s.SeriesId     = 12)
                                    .With(s => s.SeasonNumber = 2)
                                    .Build();



            var database = TestDbHelper.GetEmptyDatabase();

            database.InsertMany(firstSeriesFiles);
            database.InsertMany(secondSeriesFiles);

            Mocker.SetConstant(database);

            var result = Mocker.Resolve <MediaFileProvider>().GetSeasonFiles(12, 1);

            result.Should().HaveSameCount(firstSeriesFiles);
        }
        public void SaveAll_should_clean_urls_before_updating()
        {
            //Setup
            var definitions = Builder <NewznabDefinition> .CreateListOfSize(5)
                              .All()
                              .With(d => d.Url = "http://www.nzbdrone.com")
                              .Build();

            var expectedUrl = "http://www.nzbdrone.com";
            var newUrl      = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world";


            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            db.InsertMany(definitions);

            definitions.ToList().ForEach(d => d.Url = newUrl);

            //Act
            Mocker.Resolve <NewznabProvider>().SaveAll(definitions);

            //Assert
            db.Fetch <NewznabDefinition>().Where(d => d.Url == expectedUrl).Should().HaveCount(5);
        }
        public void InitializeNewznabIndexers_should_not_blow_up_if_more_than_one_indexer_with_the_same_url_is_found()
        {
            //Setup
            var definition = Builder <NewznabDefinition> .CreateNew()
                             .With(d => d.Url     = "http://www.nzbdrone2.com")
                             .With(d => d.BuiltIn = false)
                             .Build();

            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            db.Insert(definition);
            db.Insert(definition);

            //Act
            Mocker.Resolve <NewznabProvider>().InitializeNewznabIndexers(new List <NewznabDefinition> {
                definition
            });

            //Assert
            var result = db.Fetch <NewznabDefinition>();

            result.Should().HaveCount(2);
        }
        public void Update_Success()
        {
            //Arrange

            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            var testProfile = new QualityProfile
            {
                Name   = Guid.NewGuid().ToString(),
                Cutoff = QualityTypes.SDTV
            };

            //Act
            var id             = Convert.ToInt32(db.Insert(testProfile));
            var currentProfile = db.SingleOrDefault <QualityProfile>(id);


            //Update
            currentProfile.Cutoff = QualityTypes.Bluray720p;
            Mocker.Resolve <QualityProvider>().Update(currentProfile);

            var updated = Mocker.Resolve <QualityProvider>().Get(currentProfile.QualityProfileId);

            //Assert
            updated.Name.Should().Be(currentProfile.Name);
            updated.Cutoff.Should().Be(QualityTypes.Bluray720p);
            updated.AllowedString.Should().Be(currentProfile.AllowedString);
        }
        public void Test_Series_Quality()
        {
            //Arrange
            var database = TestDbHelper.GetEmptyDatabase();

            var testProfile = new QualityProfile
            {
                Name    = Guid.NewGuid().ToString(),
                Cutoff  = QualityTypes.SDTV,
                Allowed = new List <QualityTypes> {
                    QualityTypes.HDTV720p, QualityTypes.DVD
                },
            };


            var profileId = Convert.ToInt32(database.Insert(testProfile));

            var series = Builder <Series> .CreateNew().Build();

            series.QualityProfileId = profileId;

            database.Insert(testProfile);
            database.Insert(series);

            var result = database.Fetch <Series>();

            result.Should().HaveCount(1);
            var profile = database.SingleOrDefault <QualityProfile>(result[0].QualityProfileId);

            Assert.AreEqual(profileId, result[0].QualityProfileId);
            Assert.AreEqual(testProfile.Name, profile.Name);
        }
        public void Delete_should_delete_newznab_provider()
        {
            //Setup
            var definitions = Builder <NewznabDefinition> .CreateListOfSize(5)
                              .TheFirst(2)
                              .With(d => d.Enable = false)
                              .TheLast(3)
                              .With(d => d.Enable = true)
                              .Build();


            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            db.InsertMany(definitions);

            //Act
            Mocker.Resolve <NewznabProvider>().Delete(1);

            //Assert
            var result = db.Fetch <NewznabDefinition>();

            result.Should().HaveCount(4);
            result.Any(d => d.Id == 1).Should().BeFalse();
        }
        public void InitializeNewznabIndexers_should_update_matching_indexer_to_be_builtin()
        {
            //Setup
            var definition = Builder <NewznabDefinition> .CreateNew()
                             .With(d => d.Url     = "http://www.nzbdrone2.com")
                             .With(d => d.BuiltIn = false)
                             .Build();

            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            db.Insert(definition);

            //Act
            Mocker.Resolve <NewznabProvider>().InitializeNewznabIndexers(new List <NewznabDefinition> {
                definition
            });

            //Assert
            var result = db.Fetch <NewznabDefinition>();

            result.Should().HaveCount(1);
            result.First().BuiltIn.Should().BeTrue();
        }
Exemplo n.º 9
0
        public void Delete_TvDbId_multiple_series()
        {
            //Setup
            const int seriesId     = 71663;
            const int episodeCount = 10;

            var tvDbSeries = Builder <TvdbEpisode> .CreateListOfSize(episodeCount).
                             All()
                             .With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
                             .Build();

            var fakeSeries = Builder <Series> .CreateNew()
                             .With(c => c.SeriesId = seriesId)
                             .Build();

            var fakeEpisode = Builder <Episode> .CreateNew()
                              .With(e => e.SeriesId      = seriesId)
                              .With(e => e.SeasonNumber  = 20)
                              .With(e => e.EpisodeNumber = 20)
                              .With(e => e.TvDbEpisodeId = 300)
                              .Build();

            //Other Series
            var otherFakeSeries = Builder <Series> .CreateNew()
                                  .With(c => c.SeriesId = 12345)
                                  .Build();

            var otherFakeEpisode = Builder <Episode> .CreateNew()
                                   .With(e => e.SeriesId      = 12345)
                                   .With(e => e.SeasonNumber  = 20)
                                   .With(e => e.EpisodeNumber = 20)
                                   .With(e => e.TvDbEpisodeId = 300)
                                   .Build();



            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            db.Insert(fakeSeries);
            db.Insert(fakeEpisode);
            db.Insert(otherFakeSeries);
            db.Insert(otherFakeEpisode);

            //Act
            Mocker.Resolve <EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);

            //Assert
            var result = db.Fetch <Episode>();

            result.Should().HaveCount(1);
        }
Exemplo n.º 10
0
        public void SetupInitial_should_add_two_profiles()
        {
            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            //Act
            Mocker.Resolve <QualityProvider>().SetupDefaultProfiles();

            //Assert
            var profiles = Mocker.Resolve <QualityProvider>().All();


            profiles.Should().HaveCount(2);
            profiles.Should().Contain(e => e.Name == "HD");
            profiles.Should().Contain(e => e.Name == "SD");
        }
Exemplo n.º 11
0
        public void Init_indexer_should_not_enable_indexer_that_is_not_enabled_by_default()
        {
            Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());

            //Act
            var indexerProvider = Mocker.Resolve <IndexerProvider>();

            indexerProvider.InitializeIndexers(new List <IndexerBase> {
                Mocker.Resolve <MockIndexer>()
            });

            //Assert
            indexerProvider.All();
            indexerProvider.All().Should().HaveCount(1);
            indexerProvider.GetEnabledIndexers().Should().HaveCount(0);
            indexerProvider.GetSettings(typeof(MockIndexer)).Enable.Should().BeFalse();
        }
Exemplo n.º 12
0
        public void SetupDefault_already_exists_should_insert_missing()
        {
            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            db.Insert(new QualityType {
                QualityTypeId = 1, Name = "SDTV", MinSize = 0, MaxSize = 100
            });

            //Act
            Mocker.Resolve <QualityTypeProvider>().SetupDefault();

            //Assert
            var types = Mocker.Resolve <QualityTypeProvider>().All();

            types.Should().HaveCount(QualityTypes.All().Count - 1);
        }
Exemplo n.º 13
0
        //This confirms that new profiles are added only if no other profiles exists.
        //We don't want to keep adding them back if a user deleted them on purpose.
        public void SetupInitial_should_skip_if_any_profile_exists()
        {
            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);
            var fakeProfile = Builder <QualityProfile> .CreateNew().With(p => p.Cutoff = QualityTypes.DVD).With(p => p.Allowed = new List <QualityTypes> {
                QualityTypes.SDTV, QualityTypes.DVD
            }).Build();

            //Act
            Mocker.Resolve <QualityProvider>().Add(fakeProfile);
            Mocker.Resolve <QualityProvider>().SetupDefaultProfiles();

            //Assert
            var profiles = Mocker.Resolve <QualityProvider>().All();


            profiles.Should().HaveCount(1);
        }
        public void Save_should_clean_url_before_inserting_when_url_is_not_empty()
        {
            //Setup
            var newznab = new NewznabDefinition {
                Name = "Newznab Provider", Enable = true, Url = ""
            };
            var expectedUrl = "";


            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            //Act
            var result = Mocker.Resolve <NewznabProvider>().Save(newznab);

            //Assert
            db.Single <NewznabDefinition>(result).Url.Should().Be(expectedUrl);
        }
        public void Save_should_clean_url_before_inserting()
        {
            //Setup
            var newznab = new NewznabDefinition {
                Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world"
            };
            var expectedUrl = "http://www.nzbdrone.com";


            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            //Act
            var result = Mocker.Resolve <NewznabProvider>().Save(newznab);

            //Assert
            db.Single <NewznabDefinition>(result).Url.Should().Be(expectedUrl);
        }
Exemplo n.º 16
0
        public void Init_indexer_with_disabled_job()
        {
            Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());

            //Act
            var indexerProvider = Mocker.Resolve <IndexerProvider>();

            indexerProvider.InitializeIndexers(new List <IndexerBase> {
                Mocker.Resolve <MockIndexer>()
            });
            var settings = indexerProvider.GetSettings(typeof(MockIndexer));

            settings.Enable = false;
            indexerProvider.SaveSettings(settings);

            //Assert

            indexerProvider.All().Should().HaveCount(1);
            indexerProvider.GetEnabledIndexers().Should().BeEmpty();
        }
Exemplo n.º 17
0
        public void Test_Storage_no_allowed()
        {
            //Arrange
            var database    = TestDbHelper.GetEmptyDatabase();
            var testProfile = new QualityProfile
            {
                Name   = Guid.NewGuid().ToString(),
                Cutoff = QualityTypes.SDTV
            };

            //Act
            var id    = Convert.ToInt32(database.Insert(testProfile));
            var fetch = database.SingleOrDefault <QualityProfile>(id);

            //Assert
            Assert.AreEqual(id, fetch.QualityProfileId);
            Assert.AreEqual(testProfile.Name, fetch.Name);
            Assert.AreEqual(testProfile.Cutoff, fetch.Cutoff);
            fetch.Allowed.Should().HaveCount(0);
        }
Exemplo n.º 18
0
        public void GetList_multiple_quality_type()
        {
            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            var fakeQualityTypes = Builder <QualityType> .CreateListOfSize(6)
                                   .Build();

            var ids = new List <int> {
                1, 2
            };

            db.InsertMany(fakeQualityTypes);

            //Act
            var result = Mocker.Resolve <QualityTypeProvider>().GetList(ids);

            //Assert
            result.Should().HaveCount(ids.Count);
        }
        public void InitializeNewznabIndexers_should_initialize_new_indexers()
        {
            //Setup
            var definitions = Builder <NewznabDefinition> .CreateListOfSize(5)
                              .All()
                              .With(d => d.Url = "http://www.nzbdrone.com")
                              .Build();


            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            //Act
            Mocker.Resolve <NewznabProvider>().InitializeNewznabIndexers(definitions);

            //Assert
            var result = db.Fetch <NewznabDefinition>();

            result.Should().HaveCount(5);
            result.Should().OnlyContain(i => i.BuiltIn);
        }
Exemplo n.º 20
0
        public void DeleteEpisodeFile()
        {
            //Setup
            var episodeFiles = Builder <EpisodeFile>
                               .CreateListOfSize(10)
                               .All()
                               .With(c => c.Quality = QualityTypes.SDTV)
                               .Build();


            var database = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(database);
            database.InsertMany(episodeFiles);

            //Act
            Mocker.Resolve <MediaFileProvider>().Delete(1);
            var result = database.Fetch <EpisodeFile>();

            //Assert
            result.Should().HaveCount(9);
            result.Should().NotContain(e => e.EpisodeFileId == 1);
        }
Exemplo n.º 21
0
        public void Test_Storage()
        {
            //Arrange
            var database    = TestDbHelper.GetEmptyDatabase();
            var testProfile = new QualityProfile
            {
                Name    = Guid.NewGuid().ToString(),
                Cutoff  = QualityTypes.SDTV,
                Allowed = new List <QualityTypes> {
                    QualityTypes.HDTV720p, QualityTypes.DVD
                },
            };

            //Act
            var id    = Convert.ToInt32(database.Insert(testProfile));
            var fetch = database.SingleOrDefault <QualityProfile>(id);

            //Assert
            Assert.AreEqual(id, fetch.QualityProfileId);
            Assert.AreEqual(testProfile.Name, fetch.Name);
            Assert.AreEqual(testProfile.Cutoff, fetch.Cutoff);
            Assert.AreEqual(testProfile.Allowed, fetch.Allowed);
        }
        public void Save_should_clean_url_before_updating_when_url_is_not_empty()
        {
            //Setup
            var newznab = new NewznabDefinition {
                Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com"
            };
            var expectedUrl = "";
            var newUrl      = "";


            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            newznab.Id  = Convert.ToInt32(db.Insert(newznab));
            newznab.Url = newUrl;

            //Act
            var result = Mocker.Resolve <NewznabProvider>().Save(newznab);

            //Assert
            db.Single <NewznabDefinition>(result).Url.Should().Be(expectedUrl);
        }
        public void All_should_return_all_newznab_providers()
        {
            //Setup
            var definitions = Builder <NewznabDefinition> .CreateListOfSize(5)
                              .TheFirst(2)
                              .With(d => d.Enable = false)
                              .TheLast(3)
                              .With(d => d.Enable = true)
                              .Build();


            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            db.InsertMany(definitions);

            //Act
            var result = Mocker.Resolve <NewznabProvider>().All();

            //Assert
            result.Should().HaveCount(5);
        }
Exemplo n.º 24
0
        public void SetupDefault_should_add_all_profiles()
        {
            var db = TestDbHelper.GetEmptyDatabase();

            Mocker.SetConstant(db);

            //Act
            Mocker.Resolve <QualityTypeProvider>().SetupDefault();

            //Assert
            var types = Mocker.Resolve <QualityTypeProvider>().All();

            types.Should().HaveCount(10);
            types.Should().Contain(e => e.Name == "SDTV" && e.QualityTypeId == 1);
            types.Should().Contain(e => e.Name == "DVD" && e.QualityTypeId == 2);
            types.Should().Contain(e => e.Name == "WEBDL-480p" && e.QualityTypeId == 8);
            types.Should().Contain(e => e.Name == "HDTV-720p" && e.QualityTypeId == 4);
            types.Should().Contain(e => e.Name == "HDTV-1080p" && e.QualityTypeId == 9);
            types.Should().Contain(e => e.Name == "Raw-HD" && e.QualityTypeId == 10);
            types.Should().Contain(e => e.Name == "WEBDL-720p" && e.QualityTypeId == 5);
            types.Should().Contain(e => e.Name == "WEBDL-1080p" && e.QualityTypeId == 3);
            types.Should().Contain(e => e.Name == "Bluray720p" && e.QualityTypeId == 6);
            types.Should().Contain(e => e.Name == "Bluray1080p" && e.QualityTypeId == 7);
        }
Exemplo n.º 25
0
        public void Setup()
        {
            db = TestDbHelper.GetEmptyDatabase();
            int currentFileId = 0;


            var qulityProfile = new QualityProfile
            {
                Name    = "TestProfile",
                Allowed = new List <QualityTypes> {
                    QualityTypes.DVD, QualityTypes.Bluray1080p
                },
                Cutoff = QualityTypes.DVD
            };

            db.Insert(qulityProfile);

            foreach (var _seriesId in seriesIds)
            {
                int seriesId = _seriesId;
                var series   = Builder <Series> .CreateNew()
                               .With(s => s.SeriesId  = seriesId)
                               .With(s => s.Monitored = true)
                               .Build();

                db.Insert(series);

                foreach (var _seasonNumber in seasonsNumbers)
                {
                    for (int i = 1; i <= Episodes_Per_Season; i++)
                    {
                        var epFileId = 0;

                        if (i < 10)
                        {
                            var epFile = Builder <EpisodeFile> .CreateNew()
                                         .With(e => e.SeriesId    = seriesId)
                                         .And(e => e.SeasonNumber = _seasonNumber)
                                         .And(e => e.Path         = Guid.NewGuid().ToString())
                                         .Build();

                            files.Add(epFile);

                            currentFileId++;
                            epFileId = currentFileId;
                        }


                        var episode = Builder <Episode> .CreateNew()
                                      .With(e => e.SeriesId     = seriesId)
                                      .And(e => e.SeasonNumber  = _seasonNumber)
                                      .And(e => e.EpisodeNumber = i)
                                      .And(e => e.Ignored       = false)
                                      .And(e => e.TvDbEpisodeId = episodes.Count + 1)
                                      .And(e => e.EpisodeFileId = epFileId)
                                      .And(e => e.AirDate       = DateTime.Today.AddDays(-20))
                                      .Build();

                        episodes.Add(episode);
                    }
                }
            }

            db.InsertMany(episodes);
            db.InsertMany(files);
        }