Example #1
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");
                });
            }
Example #2
0
            public void AppliesPropertyMappings()
            {
                MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                PropertyMappings.Received(1)
                .Apply(Arg.Any <IEnumerable <object> >(), Arg.Any <MetadataResult <Series> >(),
                       Arg.Any <Action <string> >());
            }
Example #3
0
            public void NoNameMappingForLibrarySourceData_ReturnsFailure()
            {
                PropertyMappings.GetEnumerator()
                .Returns(Enumerable.Empty <IPropertyMapping>().GetEnumerator());

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

                result.IsLeft.Should().BeTrue();
                result.IfLeft(r => r.Reason.Should().Be("No value for Name property mapped from library source"));
            }
Example #4
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"));
            }
Example #5
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> >());
            }
Example #6
0
            public void NameNotMapped_ReturnsFailure(string name)
            {
                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());

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

                result.IsLeft.Should().BeTrue();
                result.IfLeft(r => r.Reason.Should().Be("Property mapping failed for the Name property"));
            }
Example #7
0
            public void NameIsMapped_ReturnsResultWithHasMetadataToTrue()
            {
                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.HasMetadata.Should().BeTrue());
            }
        public virtual void Setup()
        {
            PluginConfiguration = Substitute.For <IPluginConfiguration>();

            MediaItemBuilder = Substitute.For <IMediaItemBuilder>();
            MediaItemBuilder.BuildMediaItemAsync(Arg.Any <IMediaItem>())
            .Returns(x => Right <ProcessFailedResult, IMediaItem>(x.Arg <IMediaItem>()));

            MediaItemType = Substitute.For <IMediaItemType <Series> >();
            MediaItemType.CreateMetadataFoundResult(PluginConfiguration, Arg.Any <IMediaItem>(), Arg.Any <ILogManager>())
            .Returns(x => Right <ProcessFailedResult, IMetadataFoundResult <Series> >(new MetadataFoundResult <Series>(
                                                                                          x.Arg <IMediaItem>(), new MetadataResult <Series>
            {
                Item = new Series()
            })));

            Processor = new MediaItemProcessor(PluginConfiguration, MediaItemBuilder, new ConsoleLogManager());
        }
Example #9
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");
                });
            }