Beispiel #1
0
        public void RemoveShowsThatAreNotUpdated_Should_Remove_All_Shows_That_Are_Not_Updated()
        {
            RunTest(() =>
            {
                var now     = DateTime.Now;
                var showOne = new ShowBuilder(Guid.NewGuid().ToString(), "1").AddUpdateState(now.AddDays(-1)).Build();
                var showTwo = new ShowBuilder(Guid.NewGuid().ToString(), "1").AddUpdateState(now.AddDays(1)).Build();

                _showRepository.InsertShow(showOne);
                _showRepository.InsertShow(showTwo);

                var count = _showRepository.GetMediaCount(new string[0]);
                count.Should().Be(2);

                _showRepository.RemoveShowsThatAreNotUpdated(now);

                var shows = _showRepository.GetAllShows(new string[0], true, true);
                shows.Should().NotContainNulls();
                shows.Count.Should().Be(1);

                var episodes = _showRepository.GetAllEpisodesForShow(showOne.Id);
                episodes.Should().NotContainNulls();
                episodes.Should().BeEmpty();

                episodes = _showRepository.GetAllEpisodesForShow(showTwo.Id);
                episodes.Should().NotContainNulls();
                episodes.Should().NotBeEmpty();
            });
        }
Beispiel #2
0
        public void HasShowChangedEpisode_Should_Return_False_If_Shows_Are_Equal()
        {
            var oldShow = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
            var changed = oldShow.HasShowChangedEpisodes(oldShow);

            changed.Should().BeFalse();
        }
Beispiel #3
0
        public void GetAllShows_With_Library_Filter_Should_Return_All_Shows_Without_Seasons_Or_Episodes()
        {
            RunTest(() =>
            {
                var showOne   = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                var showTwo   = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                var showThree = new ShowBuilder(Guid.NewGuid().ToString(), "2").Build();

                _showRepository.InsertShow(showOne);
                _showRepository.InsertShow(showTwo);
                _showRepository.InsertShow(showThree);

                var shows = _showRepository.GetAllShows(new[] { "2" }, false, false);
                shows.Should().NotContainNulls();
                shows.Count.Should().Be(1);

                shows[0].Episodes.Count.Should().Be(2);
                shows[0].Episodes[0].Id.Should().Be(showThree.Episodes[0].Id);
                shows[0].Episodes[0].Name.Should().BeNull();
                shows[0].Episodes[1].Id.Should().Be(showThree.Episodes[1].Id);
                shows[0].Episodes[1].Name.Should().BeNull();

                shows[0].Seasons.Count.Should().Be(1);
                shows[0].Seasons[0].Id.Should().Be(showThree.Seasons[0].Id);
                shows[0].Seasons[0].Name.Should().BeNull();
            });
        }
Beispiel #4
0
        public void NeedsShowSync_Should_Return_True_If_Show_Needs_Syncing()
        {
            var show        = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
            var needsUpdate = show.NeedsShowSync();

            needsUpdate.Should().BeTrue();
        }
Beispiel #5
0
        public void HasShowChangedEpisode_Should_Return_True_If_Show_Is_New()
        {
            var newShow = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
            var changed = newShow.HasShowChangedEpisodes(null);

            changed.Should().BeTrue();
        }
Beispiel #6
0
        public void NeedsShowSync_Should_Return_False_If_Show_Already_Synced()
        {
            var show = new ShowBuilder(Guid.NewGuid().ToString(), "1")
                       .AddTvdbSynced(true).Build();
            var needsUpdate = show.NeedsShowSync();

            needsUpdate.Should().BeFalse();
        }
Beispiel #7
0
        public void NeedsShowSync_Should_Return_True_If_Show_Failed_Sync()
        {
            var show = new ShowBuilder(Guid.NewGuid().ToString(), "1")
                       .AddTvdbSynced(true)
                       .AddFailedSync(true).Build();
            var needsUpdate = show.NeedsShowSync();

            needsUpdate.Should().BeTrue();
        }
Beispiel #8
0
        public void Any_Should_Return_True_If_Any_Shows_Are_In_Database()
        {
            RunTest(() =>
            {
                var movieOne = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                _showRepository.InsertShow(movieOne);

                var result = _showRepository.Any();
                result.Should().BeTrue();
            });
        }
Beispiel #9
0
        public void HasShowChangedEpisode_Should_Return_True_If_Show_Has_Changed_Episodes()
        {
            var oldShow = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
            var newShow = new ShowBuilder(Guid.NewGuid().ToString(), oldShow.Id)
                          .AddEpisode(new EpisodeBuilder(Guid.NewGuid().ToString(), oldShow.Id, "1").Build())
                          .Build();

            var changed = newShow.HasShowChangedEpisodes(oldShow);

            changed.Should().BeTrue();
        }
Beispiel #10
0
        public void Should_Return_Correct_Season()
        {
            RunTest(() =>
            {
                var showOne = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                _showRepository.InsertShow(showOne);

                var season = _showRepository.GetSeasonById(showOne.Seasons.First().Id);
                season.Should().NotBeNull();
                season.Id.Should().Be(showOne.Seasons.First().Id);
                season.ParentId.Should().Be(showOne.Id);
            });
        }
Beispiel #11
0
        public void Should_Return_Correct_Episode()
        {
            RunTest(() =>
            {
                var showOne = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                _showRepository.InsertShow(showOne);

                var episode = _showRepository.GetEpisodeById(showOne.Id, showOne.Episodes.First().Id);
                episode.Should().NotBeNull();
                episode.Id.Should().Be(showOne.Episodes.First().Id);
                episode.ParentId.Should().Be("1");
            });
        }
Beispiel #12
0
        public void GetMediaCount_Should_Return_Correct_Count()
        {
            RunTest(() =>
            {
                var showOne = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                var showTwo = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();

                _showRepository.InsertShow(showOne);
                _showRepository.InsertShow(showTwo);

                var count = _showRepository.GetMediaCount(new string[0]);
                count.Should().Be(2);
            });
        }
Beispiel #13
0
        public void GetNonSpecialEpisodeCount_Should_Count_Multi_Episode_Entries()
        {
            var id      = Guid.NewGuid().ToString();
            var episode = new EpisodeBuilder(Guid.NewGuid().ToString(), id, Guid.NewGuid().ToString())
                          .WithIndexNumber(8)
                          .WithIndexNumberEnd(9)
                          .Build();

            var show = new ShowBuilder(_show)
                       .AddEpisode(episode)
                       .Build();

            var count = show.GetNonSpecialEpisodeCount(false);

            count.Should().Be(9);
        }
Beispiel #14
0
        public void GetMediaCount_With_Library_Filter_Should_Return_Correct_Count()
        {
            RunTest(() =>
            {
                var showOne   = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                var showTwo   = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                var showThree = new ShowBuilder(Guid.NewGuid().ToString(), "2").Build();

                _showRepository.InsertShow(showOne);
                _showRepository.InsertShow(showTwo);
                _showRepository.InsertShow(showThree);

                var count = _showRepository.GetMediaCount(new[] { "2" });
                count.Should().Be(1);
            });
        }
Beispiel #15
0
        public void RemoveShows_Should_Remove_All_Shows()
        {
            RunTest(() =>
            {
                var showOne   = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                var showTwo   = new ShowBuilder(Guid.NewGuid().ToString(), "1").AddCreateDate(new DateTime(2000, 1, 1)).Build();
                var showThree = new ShowBuilder(Guid.NewGuid().ToString(), "2").AddCreateDate(new DateTime(2017, 1, 1)).Build();
                _showRepository.InsertShow(showOne);
                _showRepository.InsertShow(showTwo);
                _showRepository.InsertShow(showThree);

                _showRepository.RemoveShows();

                var shows = _showRepository.GetAllShows(new List <string>(), false, false);
                shows.Count.Should().Be(0);
            });
        }
        public void GetCollectedRateChart()
        {
            var showFour = new ShowBuilder(Guid.NewGuid().ToString(), _collections.First().Id).ClearEpisodes().Build();
            var subject  = CreateShowService(_showOne, _showTwo, _showThree, showFour);
            var stat     = subject.GetStatistics(_collections.Select(x => x.Id).ToList());

            stat.Should().NotBeNull();
            stat.Should().NotBeNull();
            stat.BarCharts.Count.Should().Be(4);
            stat.BarCharts.Any(x => x.Title == Constants.CountPerCollectedPercentage).Should().BeTrue();

            var graph = stat.BarCharts.Single(x => x.Title == Constants.CountPerCollectedPercentage);

            graph.Should().NotBeNull();
            graph.SeriesCount.Should().Be(1);
            graph.DataSets.Should().Be("[{\"Label\":\"0% - 4%\",\"Val0\":1},{\"Label\":\"5% - 9%\",\"Val0\":0},{\"Label\":\"10% - 14%\",\"Val0\":0},{\"Label\":\"15% - 19%\",\"Val0\":0},{\"Label\":\"20% - 24%\",\"Val0\":0},{\"Label\":\"25% - 29%\",\"Val0\":1},{\"Label\":\"30% - 34%\",\"Val0\":0},{\"Label\":\"35% - 39%\",\"Val0\":0},{\"Label\":\"40% - 44%\",\"Val0\":0},{\"Label\":\"45% - 49%\",\"Val0\":0},{\"Label\":\"50% - 54%\",\"Val0\":0},{\"Label\":\"55% - 59%\",\"Val0\":0},{\"Label\":\"60% - 64%\",\"Val0\":1},{\"Label\":\"65% - 69%\",\"Val0\":0},{\"Label\":\"70% - 74%\",\"Val0\":0},{\"Label\":\"75% - 79%\",\"Val0\":0},{\"Label\":\"80% - 84%\",\"Val0\":0},{\"Label\":\"85% - 89%\",\"Val0\":0},{\"Label\":\"90% - 94%\",\"Val0\":0},{\"Label\":\"95% - 99%\",\"Val0\":0}]");
        }
Beispiel #17
0
        public void GetAllEpisodesForShow_Should_Return_List_Of_Episodes()
        {
            RunTest(() =>
            {
                var showOne = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                var showTwo = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();

                _showRepository.InsertShow(showOne);
                _showRepository.InsertShow(showTwo);

                var episodes = _showRepository.GetAllEpisodesForShow(showOne.Id);
                episodes.Should().NotContainNulls();
                episodes.Count.Should().Be(2);

                episodes.OrderBy(x => x.IndexNumber).ToArray()[0].Id.Should().Be(showOne.Episodes[0].Id);
                episodes.OrderBy(x => x.IndexNumber).ToArray()[1].Id.Should().Be(showOne.Episodes[1].Id);
            });
        }
        public void GetPremiereYearChart()
        {
            var showFour = new ShowBuilder(Guid.NewGuid().ToString(), _collections.First().Id).AddPremiereDate(new DateTime(2002, 1, 10)).Build();
            var subject  = CreateShowService(_showOne, _showTwo, _showThree, showFour);

            var stat = subject.GetStatistics(_collections.Select(x => x.Id).ToList());

            stat.Should().NotBeNull();
            stat.Should().NotBeNull();
            stat.BarCharts.Count.Should().Be(4);
            stat.BarCharts.Any(x => x.Title == Constants.CountPerPremiereYear).Should().BeTrue();

            var graph = stat.BarCharts.Single(x => x.Title == Constants.CountPerPremiereYear);

            graph.Should().NotBeNull();
            graph.SeriesCount.Should().Be(1);
            graph.DataSets.Should().Be("[{\"Label\":\"1990 - 1994\",\"Val0\":1},{\"Label\":\"1995 - 1999\",\"Val0\":0},{\"Label\":\"2000 - 2004\",\"Val0\":2},{\"Label\":\"2005 - 2009\",\"Val0\":0},{\"Label\":\"2010 - 2014\",\"Val0\":0},{\"Label\":\"2015 - 2019\",\"Val0\":1}]");
        }
Beispiel #19
0
        public void GetShowById_Should_Return_Correct_Show()
        {
            RunTest(() =>
            {
                var showOne = new ShowBuilder(Guid.NewGuid().ToString(), "1").AddName("Wallander").Build();
                var showTwo = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                using (var database = _context.LiteDatabase)
                {
                    var collection = database.GetCollection <Show>();
                    collection.InsertBulk(new[] { showOne, showTwo });
                }

                var show = _showRepository.GetShowById(showOne.Id);
                show.Should().NotBeNull();
                show.Id.Should().Be(showOne.Id);
                show.Name.Should().Be(showOne.Name);
            });
        }
        public void ConvertToEpisode_Should_Convert_Virtual_Episode()
        {
            var show        = new ShowBuilder("1", "1").Build();
            var showEpisode = show.Episodes.First();
            var showSeason  = show.Seasons.First();

            var virtualEpisode = new VirtualEpisode(showEpisode, showSeason);
            var episode        = virtualEpisode.ConvertToEpisode(show, showSeason);

            episode.ShowId.Should().Be(show.Id);
            episode.ShowName.Should().Be(show.Name);
            episode.Name.Should().Be(showEpisode.Name);
            episode.LocationType.Should().Be(LocationType.Virtual);
            episode.IndexNumber.Should().Be(showEpisode.IndexNumber);
            episode.ParentId.Should().Be(showSeason.Id);
            // ReSharper disable once PossibleInvalidOperationException
            episode.PremiereDate.Should().Be(showEpisode.PremiereDate);
        }
Beispiel #21
0
        public void InsertShow_Should_Succeed()
        {
            RunTest(() =>
            {
                var showOne = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();

                _showRepository.InsertShow(showOne);

                var showList = _showRepository.GetAllShows(new string[0], false, false);
                showList.Should().NotBeNull();
                showList.Should().NotContainNulls();
                showList.Count.Should().Be(1);

                showList.First().Id.Should().Be(showOne.Id);

                var count = _showRepository.GetMediaCount(new string[0]);
                count.Should().Be(1);
            });
        }
Beispiel #22
0
        public void GetMediaCountForPerson_Should_Return_Show_Count_For_Person_Id()
        {
            RunTest(() =>
            {
                var showOne = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                var showTwo = new ShowBuilder(Guid.NewGuid().ToString(), "1").ReplacePersons(new ExtraPerson {
                    Id = showOne.People.First().Id, Type = PersonType.Actor, Name = "Test"
                }).Build();
                var showThree = new ShowBuilder(Guid.NewGuid().ToString(), "2").Build();

                _showRepository.InsertShow(showOne);
                _showRepository.InsertShow(showTwo);
                _showRepository.InsertShow(showThree);

                var count = _showRepository.GetMediaCountForPerson(showOne.People.First().Name);

                count.Should().Be(2);
            });
        }
Beispiel #23
0
        public void GetLatestAddedMedia_With_library_Filter_Should_Return_Latest_Added_Show()
        {
            RunTest(() =>
            {
                var showOne   = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                var showTwo   = new ShowBuilder(Guid.NewGuid().ToString(), "1").AddCreateDate(new DateTime(2000, 1, 1)).Build();
                var showThree = new ShowBuilder(Guid.NewGuid().ToString(), "2").AddCreateDate(new DateTime(2017, 1, 1)).Build();
                _showRepository.InsertShow(showOne);
                _showRepository.InsertShow(showTwo);
                _showRepository.InsertShow(showThree);

                var shows = _showRepository
                            .GetLatestAddedMedia(new[] { "1" }, 1)
                            .ToList();

                shows.Should().NotBeNull();
                shows.Count.Should().Be(1);

                shows[0].Id.Should().Be(showOne.Id);
            });
        }
Beispiel #24
0
        public void GetLowestRatedMedia_With_library_Filter_Should_Return_Lowest_Rated_Show()
        {
            RunTest(() =>
            {
                var showOne   = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                var showTwo   = new ShowBuilder(Guid.NewGuid().ToString(), "1").AddCommunityRating(9).Build();
                var showThree = new ShowBuilder(Guid.NewGuid().ToString(), "2").AddCommunityRating(1).Build();
                _showRepository.InsertShow(showOne);
                _showRepository.InsertShow(showTwo);
                _showRepository.InsertShow(showThree);

                var shows = _showRepository
                            .GetLowestRatedMedia(new[] { "1" }, 1)
                            .ToList();

                shows.Should().NotBeNull();
                shows.Count.Should().Be(1);

                shows[0].Id.Should().Be(showOne.Id);
            });
        }
Beispiel #25
0
        public void GetOldestPremieredMedia_Should_Return_Oldest_Premiered_Show()
        {
            RunTest(() =>
            {
                var showOne   = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                var showTwo   = new ShowBuilder(Guid.NewGuid().ToString(), "1").AddPremiereDate(new DateTime(2019, 1, 2)).Build();
                var showThree = new ShowBuilder(Guid.NewGuid().ToString(), "2").AddPremiereDate(new DateTime(1920, 1, 2)).Build();
                _showRepository.InsertShow(showOne);
                _showRepository.InsertShow(showTwo);
                _showRepository.InsertShow(showThree);

                var shows = _showRepository
                            .GetOldestPremieredMedia(new string[0], 1)
                            .ToList();

                shows.Should().NotBeNull();
                shows.Count.Should().Be(1);

                shows[0].Id.Should().Be(showThree.Id);
            });
        }
        public void GetRatingChart()
        {
            var showFour = new ShowBuilder(Guid.NewGuid().ToString(), _collections.First().Id).AddCommunityRating(9.3f).Build();
            var subject  = CreateShowService(_showOne, _showTwo, _showThree, showFour);

            var stat = subject.GetStatistics(_collections.Select(x => x.Id).ToList());

            stat.Should().NotBeNull();
            stat.Should().NotBeNull();
            stat.BarCharts.Count.Should().Be(4);
            stat.BarCharts.Any(x => x.Title == Constants.CountPerCommunityRating).Should().BeTrue();

            var graph = stat.BarCharts.Single(x => x.Title == Constants.CountPerCommunityRating);

            graph.Should().NotBeNull();
            graph.SeriesCount.Should().Be(1);
            var dataSet = "{\"Label\":\"0\",\"Val0\":0},";

            dataSet += "{\"Label\":\"" + 0.5.ToString(CultureInfo.CurrentCulture) + "\",\"Val0\":0},";
            dataSet += "{\"Label\":\"1\",\"Val0\":0},";
            dataSet += "{\"Label\":\"" + 1.5.ToString(CultureInfo.CurrentCulture) + "\",\"Val0\":0},";
            dataSet += "{\"Label\":\"2\",\"Val0\":0},";
            dataSet += "{\"Label\":\"" + 2.5.ToString(CultureInfo.CurrentCulture) + "\",\"Val0\":0},";
            dataSet += "{\"Label\":\"3\",\"Val0\":0},";
            dataSet += "{\"Label\":\"" + 3.5.ToString(CultureInfo.CurrentCulture) + "\",\"Val0\":0},";
            dataSet += "{\"Label\":\"4\",\"Val0\":0},";
            dataSet += "{\"Label\":\"" + 4.5.ToString(CultureInfo.CurrentCulture) + "\",\"Val0\":0},";
            dataSet += "{\"Label\":\"5\",\"Val0\":0},";
            dataSet += "{\"Label\":\"" + 5.5.ToString(CultureInfo.CurrentCulture) + "\",\"Val0\":0},";
            dataSet += "{\"Label\":\"6\",\"Val0\":0},";
            dataSet += "{\"Label\":\"" + 6.5.ToString(CultureInfo.CurrentCulture) + "\",\"Val0\":0},";
            dataSet += "{\"Label\":\"7\",\"Val0\":0},";
            dataSet += "{\"Label\":\"" + 7.5.ToString(CultureInfo.CurrentCulture) + "\",\"Val0\":0},";
            dataSet += "{\"Label\":\"8\",\"Val0\":0},";
            dataSet += "{\"Label\":\"" + 8.5.ToString(CultureInfo.CurrentCulture) + "\",\"Val0\":2},";
            dataSet += "{\"Label\":\"9\",\"Val0\":0},";
            dataSet += "{\"Label\":\"" + 9.5.ToString(CultureInfo.CurrentCulture) + "\",\"Val0\":1},";
            dataSet += "{\"Label\":\"UNKNOWN\",\"Val0\":1}";
            graph.DataSets.Should().Be("[" + dataSet + "]");
        }
Beispiel #27
0
        public void GetAllShows_Should_Return_All_Shows_With_Seasons_And_Episodes()
        {
            RunTest(() =>
            {
                var showOne = new ShowBuilder(Guid.NewGuid().ToString(), "1").Build();
                _showRepository.InsertShow(showOne);

                var shows = _showRepository.GetAllShows(new string[0], true, true);
                shows.Should().NotContainNulls();
                shows.Count.Should().Be(1);

                shows[0].Episodes.Count.Should().Be(2);
                shows[0].Episodes[0].Id.Should().Be(showOne.Episodes[0].Id);
                shows[0].Episodes[0].Name.Should().Be(showOne.Episodes[0].Name);
                shows[0].Episodes[1].Id.Should().Be(showOne.Episodes[1].Id);
                shows[0].Episodes[1].Name.Should().Be(showOne.Episodes[1].Name);

                shows[0].Seasons.Count.Should().Be(1);
                shows[0].Seasons[0].Id.Should().Be(showOne.Seasons[0].Id);
                shows[0].Seasons[0].Name.Should().Be(showOne.Seasons[0].Name);
            });
        }
Beispiel #28
0
 /// <summary>
 ///     Builds a show object from the given show ID.
 /// </summary>
 /// <param name="showID">ID of the show to serialize into a <see cref="Show" /> object.</param>
 /// <returns>Returns the Show object.</returns>
 public Show BuildShow(int showID)
 {
     var builder = new ShowBuilder(_dataProvider.GetShow(showID));
     return builder.GetResult();
 }
Beispiel #29
0
        /// <summary>
        ///     Builds a show object from the given show ID.
        /// </summary>
        /// <param name="showID">ID of the show to serialize into a <see cref="Show" /> object.</param>
        /// <returns>Returns the Show object.</returns>
        public Show BuildShow(int showID)
        {
            var builder = new ShowBuilder(_dataProvider.GetShow(showID));

            return(builder.GetResult());
        }