Ejemplo n.º 1
0
        public void Setup()
        {
            _episodeMapper = Substitute.For <IEpisodeMapper>();
            _sources       = Substitute.For <ISources>();
            _mappingList   = Substitute.For <IMappingList>();

            _embyData = Substitute.For <IEmbyItemData>();
            _embyData.Identifier.Returns(new ItemIdentifier(67, 53, "Name"));
            _embyData.Language.Returns("en");

            var aniDbSource = Substitute.For <IAniDbSource>();

            _sources.AniDb.Returns(aniDbSource);

            var tvDbSource = Substitute.For <ITvDbSource>();

            _sources.TvDb.Returns(tvDbSource);

            _tvDbSourceData = Substitute.For <ISourceData <TvDbEpisodeData> >();

            _mediaItem = Substitute.For <IMediaItem>();
            _mediaItem.EmbyData.Returns(_embyData);
            _mediaItem.ItemType.Returns(MediaItemTypes.Episode);

            SetUpTvDbEpisodeData(56, 67, 53);

            _noMappingResult = new ProcessFailedResult("", "", null, "");
            _mappingList.GetSeriesMappingsFromTvDb(Arg.Any <int>(), Arg.Any <ProcessResultContext>())
            .Returns(Left <ProcessFailedResult, IEnumerable <ISeriesMapping> >(_noMappingResult));
        }
Ejemplo n.º 2
0
        private Task <Either <ProcessFailedResult, AniDbEpisodeData> > MapEpisodeDataAsync(int aniDbSeriesId,
                                                                                           TvDbSeriesData tvDbSeriesData, TvDbEpisodeData tvDbEpisodeData, ProcessResultContext resultContext)
        {
            var seriesMapping = _mappingList.GetSeriesMappingsFromTvDb(tvDbSeriesData.Id, resultContext)
                                .BindAsync(sm => sm.Where(m => m.Ids.AniDbSeriesId == aniDbSeriesId)
                                           .Match(
                                               () => resultContext.Failed(
                                                   $"No series mapping between TvDb series Id '{tvDbSeriesData.Id}' and AniDb series id '{aniDbSeriesId}'"),
                                               Prelude.Right <ProcessFailedResult, ISeriesMapping>,
                                               (head, tail) =>
                                               resultContext.Failed(
                                                   $"Multiple series mappings found between TvDb series Id '{tvDbSeriesData.Id}' and AniDb series Id '{aniDbSeriesId}'")));

            return(seriesMapping.BindAsync(sm =>
            {
                var episodeGroupMapping = sm.GetEpisodeGroupMapping(tvDbEpisodeData.AiredEpisodeNumber,
                                                                    tvDbEpisodeData.AiredSeason);

                var aniDbEpisodeData = _episodeMapper.MapTvDbEpisodeAsync(tvDbEpisodeData.AiredEpisodeNumber,
                                                                          sm, episodeGroupMapping);

                return aniDbEpisodeData.ToEither(resultContext.Failed(
                                                     $"Failed to find a corresponding AniDb episode in AniDb series id '{aniDbSeriesId}'"));
            }));
        }
Ejemplo n.º 3
0
        public async Task LoadFrom_NoMatchingSeriesMappings_Fails()
        {
            SetUpTvDbSeriesData(53);
            _embyData.GetParentId(MediaItemTypes.Series, _sources.AniDb).Returns(19);

            var seriesMappings = new[]
            {
                CreateSeriesMapping(53, 55)
            };

            _mappingList.GetSeriesMappingsFromTvDb(53, Arg.Any <ProcessResultContext>()).Returns(seriesMappings);

            var loader = new AniDbEpisodeFromTvDb(_sources, _mappingList, _episodeMapper);

            var result = await loader.LoadFrom(_mediaItem, _tvDbSourceData);

            result.IsLeft.Should().BeTrue();
            result.IfLeft(f => f.Reason.Should().Be("No series mapping between TvDb series Id '53' and AniDb series id '19'"));
        }