コード例 #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);
        }
コード例 #2
0
        public void Setup()
        {
            _aniListClient = Substitute.For <IAniListClient>();
            _aniListClient.FindSeriesAsync(null, null)
            .ReturnsForAnyArgs(
                Left <ProcessFailedResult, IEnumerable <AniListSeriesData> >(
                    TestProcessResultContext.Failed("Failed")));

            _sources = new TestSources();

            _titleNormaliser = Substitute.For <ITitleNormaliser>();
            _titleNormaliser.GetNormalisedTitle(Arg.Any <string>()).Returns(x => $"Normalised{x.Arg<string>()}");

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

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

            _aniDbTitles     = new ItemTitleData[] { };
            _aniDbSourceData = Substitute.For <ISourceData <AniDbSeriesData> >();
            _aniDbSourceData.Data.Returns(x => new AniDbSeriesData
            {
                Titles = _aniDbTitles
            });

            _aniListConfiguration = Substitute.For <IAnilistConfiguration>();
            _aniListConfiguration.IsLinked.Returns(true);

            _loader = new AniListSeriesFromAniDb(_aniListClient, _sources, _titleNormaliser, _aniListConfiguration);
        }
コード例 #3
0
        public void TestSources_Constructor_works()
        {
            // Arrange
            TestSources testSources = new TestSources();

            // Act
            // Assert
            testSources.Name.Should().Be("__testsources__");
            testSources.Parent.Should().BeNull();
        }
コード例 #4
0
        /// <summary>
        /// Copies test sources configuration to a test folder
        /// </summary>
        public static string CopyFuncTestConfig(string destinationFolder)
        {
            var testSettingsFolder = TestSources.GetConfigFileRoot();
            var funcTestConfigPath = Path.Combine(testSettingsFolder, TestSources.ConfigFile);

            var destConfigFile = Path.Combine(destinationFolder, "NuGet.Config");

            File.Copy(funcTestConfigPath, destConfigFile);
            return(destConfigFile);
        }
コード例 #5
0
        public void GetFileByName_FileInRoot_IsNotFoundByNameInLowerCase()
        {
            // Arrange
            TestSources testSources = new TestSources();
            string      fileName    = "binfile01.rar";
            // Act
            ITestSourceItem testSourcesItem = testSources.GetFileByName(fileName, false);

            // Assert
            testSourcesItem.Should().BeNull();
        }
コード例 #6
0
        public void GetFolderByName_UnexistingFolderInRoot_IsNotFoundByNameIncludingSubDirs()
        {
            // Arrange
            TestSources testSources = new TestSources();
            string      folderName  = "IDoNotExist";
            // Act
            ITestSourceItem testSourcesItem = testSources.GetFolderByName(folderName, true);

            // Assert
            testSourcesItem.Should().BeNull();
        }
コード例 #7
0
        public void GetFileByName_UnexistingFileInRoot_IsNotFoundByNameWithoutSubdirs()
        {
            // Arrange
            TestSources testSources = new TestSources();
            string      fileName    = "IDoNotExist.ext";
            // Act
            ITestSourceItem testSourcesItem = testSources.GetFileByName(fileName, false);

            // Assert
            testSourcesItem.Should().BeNull();
        }
コード例 #8
0
        public void GetFolderByName_FolderInRoot_IsNotFoundByNameInLowerCase()
        {
            // Arrange
            TestSources testSources = new TestSources();
            string      folderName  = "filecontenttests"; //FileContentTests
            // Act
            ITestSourceItem testSourcesItem = testSources.GetFolderByName(folderName, false);

            // Assert
            testSourcesItem.Should().BeNull();
        }
コード例 #9
0
        public void GetFolderByName_FolderInRoot_IsFoundByNameIncludingSubDirs()
        {
            // Arrange
            TestSources testSources = new TestSources();
            string      folderName  = "FileContentTests";
            // Act
            ITestSourceItem testSourcesItem = testSources.GetFolderByName(folderName, true);

            // Assert
            testSourcesItem.Should().NotBeNull();
            testSourcesItem.Name.Should().Be(folderName);
        }
コード例 #10
0
        public void GetFileByName_FileInFinalSubFolder_IsFoundByNameWithSubDirsImplicit()
        {
            // Arrange
            TestSources testSources = new TestSources();
            string      fileName    = "Sub2FolderBinFile.rar";
            // Act
            ITestSourceItem testSourcesItem = testSources.GetFileByName(fileName, true);

            // Assert
            testSourcesItem.Should().NotBeNull();
            testSourcesItem.Name.Should().Be(fileName);
        }
コード例 #11
0
        public void GetFileByName_FileInSubFolder_IsFoundByNameWithSubDirsExplicit()
        {
            // Arrange
            TestSources testSources = new TestSources();
            string      fileName    = "SomeJson.json";
            // Act
            ITestSourceItem testSourcesItem = testSources.GetFileByName(fileName, true);

            // Assert
            testSourcesItem.Should().NotBeNull();
            testSourcesItem.Name.Should().Be(fileName);
        }
コード例 #12
0
        public void GetFileByName_FileInRoot_IsFoundByNameIncludingSubDirs()
        {
            // Arrange
            TestSources testSources = new TestSources();
            string      fileName    = "BinFile01.rar";
            // Act
            ITestSourceItem testSourcesItem = testSources.GetFileByName(fileName, true);

            // Assert
            testSourcesItem.Should().NotBeNull();
            testSourcesItem.Name.Should().Be(fileName);
        }
コード例 #13
0
        public void GetFolderByName_FolderInFinalSubFolder_IsFoundByNameWithSubDirsImplicit()
        {
            // Arrange
            TestSources testSources = new TestSources();
            string      folderName  = "sub02";
            // Act
            ITestSourceItem testSourcesItem = testSources.GetFolderByName(folderName, true);

            // Assert
            testSourcesItem.Should().NotBeNull();
            testSourcesItem.Name.Should().Be(folderName);
        }
コード例 #14
0
        public void GetFolderByName_FolderInRootAndFinalSubfolder_OnlyFirstFolderFileIsFound()
        {
            // Arrange
            TestSources testSources = new TestSources();
            string      folderName  = "sub01";
            // Act
            ITestSourceItem testSourcesItem = testSources.GetFolderByName(folderName, true);

            // Assert
            testSourcesItem.Should().NotBeNull();
            testSourcesItem.Name.Should().Be(folderName);
            testSourcesItem.Parent.Name.Should().Be(GetFolderByNameTests.rootpath);
        }
コード例 #15
0
        public void GetFileByName_FileInRootAndFinalSubfolder_OnlyFirstFolderFileIsFound()
        {
            // Arrange
            TestSources testSources = new TestSources();
            string      fileName    = "TextFile01.txt";
            // Act
            ITestSourceItem testSourcesItem = testSources.GetFileByName(fileName, false);

            // Assert
            testSourcesItem.Should().NotBeNull();
            testSourcesItem.Name.Should().Be(fileName);
            testSourcesItem.Parent.Name.Should().Be(GetFileByNameTests.rootpath);
        }
コード例 #16
0
        public void ExistingFile_CanBeFound()
        {
            // arrange
            TestSources ts = new TestSources();
            var         projectDirectory = ProjectHelpers.GetProjectPath();
            var         path             = Path.Combine(projectDirectory, ts.Name);

            //act
            //assert
            ts.FullName.Should().Be(path);
            ts.FilesAndFolders.Should().NotBeEmpty();
            ts.GetItems().Should().NotBeEmpty();
        }
コード例 #17
0
        public static string ReadApiKey(string feedName)
        {
            var testSettingsFolder = TestSources.GetConfigFileRoot();
            var protocolConfigPath = Path.Combine(testSettingsFolder, ProtocolConfigFileName);

            var fullPath = NuGetEnvironment.GetFolderPath(NuGetFolderPath.UserSettingsDirectory);

            using (Stream configStream = File.OpenRead(protocolConfigPath))
            {
                var doc     = XDocument.Load(XmlReader.Create(configStream));
                var element = doc.Root.Element(feedName);

                return(element?.Element("ApiKey")?.Value);
            }
        }