Ejemplo n.º 1
0
        public static string FolderName(this KnownTvShowIds theTvDbId)
        {
            if (KnownSeriesFolderNames.ContainsKey(theTvDbId))
            {
                return(KnownSeriesFolderNames[theTvDbId]);
            }

            string        s     = theTvDbId.ToString("G");
            List <string> parts = new List <string>();

            int lastHumpIndex = 0;

            for (int i = 0; i < s.Length; i++)
            {
                char c                = s[i];
                bool isUpperCase      = char.IsUpper(c);
                bool wasLastUpperCase = i > 0 && char.IsUpper(s[i - 1]);

                if (isUpperCase && !wasLastUpperCase)
                {
                    parts.Add(s.Substring(lastHumpIndex, i - lastHumpIndex));
                    lastHumpIndex = i;
                }
            }
            parts.Add(s.Substring(lastHumpIndex, s.Length - lastHumpIndex));

            return(string.Join(" ", parts.Where(x => !string.IsNullOrEmpty(x)).ToArray()));
        }
Ejemplo n.º 2
0
 protected ISeriesIdentifier GetSeriesIdentifier(KnownTvShowIds tvdbShowId)
 {
     return(new SeriesIdentifier {
         Id = tvdbShowId.ToString("D")
     });
 }
        public async Task AreDataProvidersComparable(KnownTvShowIds showId)
        {
            // Arrange
            var searchTerm     = GetSearchTerm(showId);
            var dateProvider   = new RealTimeDateProvider();
            var httpDownloader = new HttpDownloader();
            var configValues   = new TestConfigurationValues();
            var localPaths     = new TestLocalPaths();

            var v2Config        = new V2.TheTvDbConfigurationValues(configValues);
            var v2ApiDownloader = new V2.TheTvDbApiDownloader(v2Config, httpDownloader);
            var v2Authenticator = new V2.TheTvDbAuthenticator(dateProvider, v2Config, localPaths, v2ApiDownloader);
            var v2DataProvider  = new V2.TheTvDbEpisodeDataProvider(v2Config, v2Authenticator, v2ApiDownloader);

            var v4Config        = new V4.TheTvDbConfigurationValuesV4(configValues);
            var v4ApiDownloader = new V4.TheTvDbApiDownloaderV4(v4Config, httpDownloader);
            var v4Authenticator = new V4.TheTvDbAuthenticatorV4(dateProvider, v4Config, localPaths, v4ApiDownloader);
            var v4DataProvider  = new V4.TheTvDbEpisodeDataProviderV4(v4Authenticator, v4ApiDownloader);

            var searchParams = new SeriesSearchParams {
                Name = searchTerm
            };

            // Act
            var v2SearchResult = await v2DataProvider.SearchAsync(searchParams, null);

            var v4SearchResult = await v4DataProvider.SearchAsync(searchParams, null);

            // Assert
            Assert.That(v2SearchResult, Is.Not.Null, "Expected v2 search results to be not null.");
            Assert.That(v4SearchResult, Is.Not.Null, "Expected v4 search results to be not null.");

            Assert.That(v2SearchResult.Length, Is.GreaterThan(0), "Expected to have v2 search results.");
            Assert.That(v4SearchResult.Length, Is.GreaterThan(0), "Expected to have v4 search results.");

            var v2BestMatch = v2SearchResult.FirstOrDefault(x => x.Id == showId.ToString("D"));

            Assert.That(v2BestMatch, Is.Not.Null, "Expected best matching v2 search result to be not null.");
            Assert.That(v2BestMatch.Id, Is.EqualTo(showId.ToString("D")), "Expected best matching v2 search result to be {0}, but was {1}.", searchTerm, v2BestMatch.Name);

            var v4BestMatch = v4SearchResult.FirstOrDefault(x => x.Id == v2BestMatch.Id);

            Assert.That(v4BestMatch, Is.Not.Null, "Expected equivalent v4 search result.");

            Assert.That(v4BestMatch.Name, Is.EqualTo(v2BestMatch.Name), "Expected names to match.");
            //Assert.That(v4BestMatch.SeriesIdentifier.ImdbId, Is.EqualTo(v2BestMatch.SeriesIdentifier.ImdbId), "Expected IMDB IDs to match.");
            Assert.That(v4BestMatch.Year, Is.EqualTo(v2BestMatch.Year), "Expected years to match.");
            //Assert.That(v4BestMatch.Description, Is.EqualTo(v2BestMatch.Description), "Expected descriptions to match.");

            var seriesIdentifier = GetSeriesIdentifier(showId);
            var v2Series         = await v2DataProvider.GetEpisodesAsync(seriesIdentifier, null);

            var v4Series = await v4DataProvider.GetEpisodesAsync(seriesIdentifier, null);

            Assert.That(v2Series, Is.Not.Null, "Expected v2 series to be not null.");
            Assert.That(v4Series, Is.Not.Null, "Expected v4 series to be not null.");

            Assert.That(v4Series.Id, Is.EqualTo(v2Series.Id), "Expected series IDs to match.");
            Assert.That(v4Series.Name, Is.EqualTo(v2Series.Name), "Expected series names to match.");
            //Assert.That(v4Series.ImdbId, Is.EqualTo(v2Series.ImdbId), "Expected series IMDB IDs to match.");
            //Assert.That(v4Series.Year, Is.EqualTo(v2Series.Year), "Expected series years to match.");
            //Assert.That(v4Series.AirDate, Is.EqualTo(v2Series.AirDate), "Expected series air dates to match.");
            //Assert.That(v4Series.Network, Is.EqualTo(v2Series.Network), "Expected series networks to match.");
            Assert.That(v4Series.Status, Is.EqualTo(v2Series.Status), "Expected series statuses to match.");


            Assert.That(v2Series.Seasons, Is.Not.Null);
            Assert.That(v4Series.Seasons, Is.Not.Null);
            Assert.That(v4Series.Seasons.Count, Is.EqualTo(v2Series.Seasons.Count), "Expected season counts to match.");
            for (int i = 0; i < v4Series.Seasons.Count; i++)
            {
                var v2Season = v2Series.Seasons[i];
                var v4Season = v4Series.Seasons[i];

                Assert.That(v4Season.SeasonNumber, Is.EqualTo(v2Season.SeasonNumber));

                Assert.That(v2Season.Episodes, Is.Not.Null);
                Assert.That(v4Season.Episodes, Is.Not.Null);
                Assert.That(v4Season.Episodes.Count, Is.EqualTo(v2Season.Episodes.Count), "Expected episode counts to match.");

                for (int j = 0; j < v4Season.Episodes.Count; j++)
                {
                    var v2Episode = v2Season.Episodes[j];
                    var v4Episode = v4Season.Episodes[j];

                    Assert.That(v4Episode.EpisodeNumber, Is.EqualTo(v2Episode.EpisodeNumber));
                    Assert.That(IsCloseEnough(v4Episode.Title, v2Episode.Title), "Expected \"{0}\", but was \"{1}\", Season {2} Episode {3}.", v2Episode.Title, v4Episode.Title, v4Season.SeasonNumber, v4Episode.EpisodeNumber);
                }
            }
        }