Esempio n. 1
0
        public void Setup()
        {
            PropertyMappings = Substitute.For <IPropertyMappingCollection>();
            PropertyMappings.Apply(Arg.Any <IEnumerable <object> >(), Arg.Any <MetadataResult <Series> >(),
                                   Arg.Any <Action <string> >())
            .Returns(x => x.Arg <MetadataResult <Series> >());
            PropertyMappings.GetEnumerator()
            .Returns(new IPropertyMapping[]
            {
                new PropertyMapping <AniDbSeriesData, MetadataResult <Series>, string>("Name", s => s.Item.Name,
                                                                                       (s, t) => t.Item.Name = "Name", SourceNames.AniDb)
            }.AsEnumerable().GetEnumerator());

            PluginConfiguration = Substitute.For <IPluginConfiguration>();

            var embyItemData = Substitute.For <IEmbyItemData>();

            embyItemData.Language.Returns("en");

            _sources = new TestSources();
            var aniDbSourceData = new SourceData <AniDbSeriesData>(_sources.AniDb, 33, new ItemIdentifier(33, 1, "Name"),
                                                                   new AniDbSeriesData());

            MediaItem = Substitute.For <IMediaItem>();
            MediaItem.GetAllSourceData().Returns(new ISourceData[] { aniDbSourceData });
            MediaItem.GetDataFromSource(null).ReturnsForAnyArgs(aniDbSourceData);
            MediaItem.EmbyData.Returns(embyItemData);

            MediaItemType = new MediaItemType <Series>("Series", (c, l) => PropertyMappings);
        }
Esempio n. 2
0
            public void RemovesIdsThatNoLongerExist()
            {
                var source = Substitute.For <ISource>();

                source.Name.Returns(new SourceName("SourceName"));

                var sourceData = Substitute.For <ISourceData>();

                sourceData.Source.Returns(source);

                MediaItem.GetAllSourceData().Returns(new[] { sourceData });

                PropertyMappings.Apply(Arg.Any <IEnumerable <object> >(), Arg.Any <MetadataResult <Series> >(),
                                       Arg.Any <Action <string> >())
                .Returns(m =>
                {
                    var r = m.Arg <MetadataResult <Series> >();

                    r.Item.Name        = "Name";
                    r.Item.ProviderIds = new Dictionary <string, string> {
                        { "SourceName", "3" }
                    };

                    return(r);
                });

                var result = MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                result.IsRight.Should().BeTrue();
                result.IfRight(r =>
                {
                    r.EmbyMetadataResult.Item.ProviderIds.Should().NotContainKey("SourceName");
                    r.EmbyMetadataResult.Item.ProviderIds.Should().NotContainValue("3");
                });
            }
Esempio n. 3
0
            public void NoLibrarySourceData_ReturnsFailure()
            {
                MediaItem.GetAllSourceData().Returns(new ISourceData[] { });
                MediaItem.GetDataFromSource(null).ReturnsForAnyArgs(Option <ISourceData> .None);

                var result = MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                result.IsLeft.Should().BeTrue();
                result.IfLeft(r => r.Reason.Should().Be("No data returned by library structure source"));
            }
Esempio n. 4
0
            public void AppliesPropertyMappingsForIdentifierOnlySourceData()
            {
                var identifierOnlySourceData = new IdentifierOnlySourceData(_sources.AniDb, 33, new ItemIdentifier(33, 1, "Name"));

                MediaItem = Substitute.For <IMediaItem>();
                MediaItem.GetAllSourceData().Returns(new ISourceData[] { identifierOnlySourceData });

                MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                PropertyMappings.Received(1)
                .Apply(Arg.Is <IEnumerable <object> >(e => e.Contains(identifierOnlySourceData)), Arg.Any <MetadataResult <Series> >(),
                       Arg.Any <Action <string> >());
            }
Esempio n. 5
0
            public void AddsProviderIdsForNonAdditionalSources()
            {
                var source = Substitute.For <ISource>();

                source.Name.Returns(new SourceName("SourceName"));

                var additionalSource = source.ForAdditionalData();

                var sourceData = Substitute.For <ISourceData>();

                sourceData.Id.Returns(3);
                sourceData.Source.Returns(source);

                var additionalSourceData = Substitute.For <ISourceData>();

                additionalSourceData.Id.Returns(3);
                additionalSourceData.Source.Returns(additionalSource);

                MediaItem.GetAllSourceData().Returns(new[] { sourceData });

                PropertyMappings.Apply(Arg.Any <IEnumerable <object> >(), Arg.Any <MetadataResult <Series> >(),
                                       Arg.Any <Action <string> >())
                .Returns(m =>
                {
                    var r = m.Arg <MetadataResult <Series> >();

                    r.Item.Name = "Name";

                    return(r);
                });

                var result = MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                result.IsRight.Should().BeTrue();
                result.IfRight(r =>
                {
                    r.EmbyMetadataResult.Item.ProviderIds.Should().ContainKey("SourceName");
                    r.EmbyMetadataResult.Item.ProviderIds.Should().ContainValue("3");
                });
            }