public async Task DeletedMovieAndFolder_Should_Delete_Old_Movie()
            {
                string movieFolder  = Path.Combine(FakeRoot, "Movie (2020)");
                string oldMoviePath = Path.Combine(movieFolder, "Movie (2020).avi");

                _movieRepository.Setup(x => x.FindMoviePaths(It.IsAny <LibraryPath>()))
                .Returns(new List <string> {
                    oldMoviePath
                }.AsEnumerable().AsTask());

                string moviePath = Path.Combine(movieFolder, "Movie (2020).mkv");

                MovieFolderScanner service = GetService(
                    new FakeFileEntry(moviePath)
                {
                    LastWriteTime = DateTime.Now
                }
                    );
                var libraryPath = new LibraryPath {
                    Id = 1, Path = FakeRoot
                };

                Either <BaseError, Unit> result = await service.ScanFolder(libraryPath, FFprobePath);

                result.IsRight.Should().BeTrue();

                _movieRepository.Verify(x => x.DeleteByPath(It.IsAny <LibraryPath>(), It.IsAny <string>()), Times.Once);
                _movieRepository.Verify(x => x.DeleteByPath(libraryPath, oldMoviePath), Times.Once);
            }
Esempio n. 2
0
        public async Task DeletedMovieAndFolder_Should_Flag_File_Not_Found()
        {
            string movieFolder  = Path.Combine(FakeRoot, "Movie (2020)");
            string oldMoviePath = Path.Combine(movieFolder, "Movie (2020).avi");

            _movieRepository.Setup(x => x.FindMoviePaths(It.IsAny <LibraryPath>()))
            .Returns(new List <string> {
                oldMoviePath
            }.AsEnumerable().AsTask());

            MovieFolderScanner service = GetService(
                new FakeFolderEntry(FakeRoot)
                );
            var libraryPath = new LibraryPath
            {
                Id = 1, Path = FakeRoot, LibraryFolders = new List <LibraryFolder>()
            };

            Either <BaseError, Unit> result = await service.ScanFolder(
                libraryPath,
                FFmpegPath,
                FFprobePath,
                0,
                1,
                CancellationToken.None);

            result.IsRight.Should().BeTrue();

            _mediaItemRepository.Verify(
                x => x.FlagFileNotFound(It.IsAny <LibraryPath>(), It.IsAny <string>()),
                Times.Once);
            _mediaItemRepository.Verify(x => x.FlagFileNotFound(libraryPath, oldMoviePath), Times.Once);
        }
Esempio n. 3
0
        public async Task NewMovie_Statistics_And_FallbackMetadata_And_MovieNamePoster(
            [ValueSource(typeof(LocalFolderScanner), nameof(LocalFolderScanner.VideoFileExtensions))]
            string videoExtension,
            [ValueSource(typeof(LocalFolderScanner), nameof(LocalFolderScanner.ImageFileExtensions))]
            string imageExtension)
        {
            string moviePath = Path.Combine(
                FakeRoot,
                Path.Combine("Movie (2020)", $"Movie (2020){videoExtension}"));

            string posterPath = Path.Combine(
                Path.GetDirectoryName(moviePath) ?? string.Empty,
                $"Movie (2020)-poster.{imageExtension}");

            MovieFolderScanner service = GetService(
                new FakeFileEntry(moviePath)
            {
                LastWriteTime = DateTime.Now
            },
                new FakeFileEntry(posterPath)
            {
                LastWriteTime = DateTime.Now
            }
                );
            var libraryPath = new LibraryPath
            {
                Id = 1, Path = FakeRoot, LibraryFolders = new List <LibraryFolder>()
            };

            Either <BaseError, Unit> result = await service.ScanFolder(
                libraryPath,
                FFmpegPath,
                FFprobePath,
                0,
                1,
                CancellationToken.None);

            result.IsRight.Should().BeTrue();

            _movieRepository.Verify(x => x.GetOrAdd(It.IsAny <LibraryPath>(), It.IsAny <string>()), Times.Once);
            _movieRepository.Verify(x => x.GetOrAdd(libraryPath, moviePath), Times.Once);

            _localStatisticsProvider.Verify(
                x => x.RefreshStatistics(
                    FFmpegPath,
                    FFprobePath,
                    It.Is <Movie>(i => i.MediaVersions.Head().MediaFiles.Head().Path == moviePath)),
                Times.Once);

            _localMetadataProvider.Verify(
                x => x.RefreshFallbackMetadata(
                    It.Is <Movie>(i => i.MediaVersions.Head().MediaFiles.Head().Path == moviePath)),
                Times.Once);

            _imageCache.Verify(
                x => x.CopyArtworkToCache(posterPath, ArtworkKind.Poster),
                Times.Once);
        }
            public async Task Missing_Folder()
            {
                MovieFolderScanner service = GetService(
                    new FakeFileEntry(Path.Combine(FakeRoot, Path.Combine("Movie (2020)", "Movie (2020).mkv")))
                    );
                var libraryPath = new LibraryPath {
                    Path = BadFakeRoot
                };

                Either <BaseError, Unit> result = await service.ScanFolder(libraryPath, FFprobePath);

                result.IsLeft.Should().BeTrue();
                result.IfLeft(error => error.Should().BeOfType <MediaSourceInaccessible>());
            }
Esempio n. 5
0
        public async Task NewMovie_Statistics_And_SidecarMetadata_MovieNameNfo(
            [ValueSource(typeof(LocalFolderScanner), nameof(LocalFolderScanner.VideoFileExtensions))]
            string videoExtension)
        {
            string moviePath = Path.Combine(
                FakeRoot,
                Path.Combine("Movie (2020)", $"Movie (2020){videoExtension}"));

            string metadataPath = Path.ChangeExtension(moviePath, "nfo");

            MovieFolderScanner service = GetService(
                new FakeFileEntry(moviePath)
            {
                LastWriteTime = DateTime.Now
            },
                new FakeFileEntry(metadataPath)
                );
            var libraryPath = new LibraryPath
            {
                Id = 1, Path = FakeRoot, LibraryFolders = new List <LibraryFolder>()
            };

            Either <BaseError, Unit> result = await service.ScanFolder(
                libraryPath,
                FFmpegPath,
                FFprobePath,
                0,
                1,
                CancellationToken.None);

            result.IsRight.Should().BeTrue();

            _movieRepository.Verify(x => x.GetOrAdd(It.IsAny <LibraryPath>(), It.IsAny <string>()), Times.Once);
            _movieRepository.Verify(x => x.GetOrAdd(libraryPath, moviePath), Times.Once);

            _localStatisticsProvider.Verify(
                x => x.RefreshStatistics(
                    FFmpegPath,
                    FFprobePath,
                    It.Is <Movie>(i => i.MediaVersions.Head().MediaFiles.Head().Path == moviePath)),
                Times.Once);

            _localMetadataProvider.Verify(
                x => x.RefreshSidecarMetadata(
                    It.Is <Movie>(i => i.MediaVersions.Head().MediaFiles.Head().Path == moviePath),
                    metadataPath),
                Times.Once);
        }
            public async Task Should_Ignore_Extra_Folders(
                [ValueSource(typeof(LocalFolderScanner), nameof(LocalFolderScanner.VideoFileExtensions))]
                string videoExtension,
                [ValueSource(typeof(LocalFolderScanner), nameof(LocalFolderScanner.ExtraDirectories))]
                string extraFolder)
            {
                string moviePath = Path.Combine(
                    FakeRoot,
                    Path.Combine("Movie (2020)", $"Movie (2020){videoExtension}"));

                MovieFolderScanner service = GetService(
                    new FakeFileEntry(moviePath)
                {
                    LastWriteTime = DateTime.Now
                },
                    new FakeFileEntry(
                        Path.Combine(
                            Path.GetDirectoryName(moviePath) ?? string.Empty,
                            Path.Combine(extraFolder, $"Movie (2020){videoExtension}")))
                    );
                var libraryPath = new LibraryPath {
                    Id = 1, Path = FakeRoot
                };

                Either <BaseError, Unit> result = await service.ScanFolder(libraryPath, FFprobePath);

                result.IsRight.Should().BeTrue();

                _movieRepository.Verify(x => x.GetOrAdd(It.IsAny <LibraryPath>(), It.IsAny <string>()), Times.Once);
                _movieRepository.Verify(x => x.GetOrAdd(libraryPath, moviePath), Times.Once);

                _localStatisticsProvider.Verify(
                    x => x.RefreshStatistics(
                        FFprobePath,
                        It.Is <Movie>(i => i.MediaVersions.Head().MediaFiles.Head().Path == moviePath)),
                    Times.Once);

                _localMetadataProvider.Verify(
                    x => x.RefreshFallbackMetadata(
                        It.Is <Movie>(i => i.MediaVersions.Head().MediaFiles.Head().Path == moviePath)),
                    Times.Once);
            }
Esempio n. 7
0
        public async Task RenamedMovie_Should_Delete_Old_Movie()
        {
            // TODO: handle this case more elegantly
            // ideally, detect that the movie was renamed and still delete the old one (or update the path?)

            string movieFolder  = Path.Combine(FakeRoot, "Movie (2020)");
            string oldMoviePath = Path.Combine(movieFolder, "Movie (2020).avi");

            _movieRepository.Setup(x => x.FindMoviePaths(It.IsAny <LibraryPath>()))
            .Returns(new List <string> {
                oldMoviePath
            }.AsEnumerable().AsTask());

            string moviePath = Path.Combine(movieFolder, "Movie (2020).mkv");

            MovieFolderScanner service = GetService(
                new FakeFileEntry(moviePath)
            {
                LastWriteTime = DateTime.Now
            }
                );
            var libraryPath = new LibraryPath
            {
                Id = 1, Path = FakeRoot, LibraryFolders = new List <LibraryFolder>()
            };

            Either <BaseError, Unit> result = await service.ScanFolder(
                libraryPath,
                FFmpegPath,
                FFprobePath,
                0,
                1,
                CancellationToken.None);

            result.IsRight.Should().BeTrue();

            _mediaItemRepository.Verify(
                x => x.FlagFileNotFound(It.IsAny <LibraryPath>(), It.IsAny <string>()),
                Times.Once);
            _mediaItemRepository.Verify(x => x.FlagFileNotFound(libraryPath, oldMoviePath), Times.Once);
        }