public void Handle(UtorrentCommandLineParameters parameters)
        {
            var badParts =
                (_appSettings.AllKeys.Where(key => key.StartsWith("RemoveSpuriousFilenameParts::"))
                 .Select(key => _appSettings[key])).ToList();

            if (badParts.Count == 0)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(parameters.DirectoryWhereFilesAreSaved))
            {
                var dest = badParts.Aggregate(parameters.DirectoryWhereFilesAreSaved,
                                              (current, badPart) => current.Replace(badPart, string.Empty));

                _fileSystem.Directory.Move(parameters.DirectoryWhereFilesAreSaved, dest);

                parameters.DirectoryWhereFilesAreSaved = dest;
            }

            if (!string.IsNullOrWhiteSpace(parameters.NameOfDownloadedFileForSingleFileTorrents))
            {
                var dest = badParts.Aggregate(parameters.NameOfDownloadedFileForSingleFileTorrents,
                                              (current, badPart) => current.Replace(badPart, string.Empty));

                _fileSystem.File.Move(parameters.NameOfDownloadedFileForSingleFileTorrents, dest);

                parameters.NameOfDownloadedFileForSingleFileTorrents = dest;
            }
        }
        public void Handle_NoConfiguration_NothingHappens()
        {
            var @params = new UtorrentCommandLineParameters {
                DirectoryWhereFilesAreSaved = "c:\\something\\torrent"
            };

            _rsfp.Handle(@params);
        }
 public TypeOfDownload(UtorrentCommandLineParameters cliParams)
 {
     if (!string.IsNullOrWhiteSpace(cliParams.DirectoryWhereFilesAreSaved))
     {
         Location    = cliParams.DirectoryWhereFilesAreSaved;
         IsDirectory = true;
     }
     else
     {
         Location = cliParams.NameOfDownloadedFileForSingleFileTorrents ?? string.Empty;
     }
 }
        public void SetUp()
        {
            _args       = new[] { "-a", "%A" };
            _parameters = new Mock <IParsableArguments <UtorrentCommandLineParameters> >();
            _handlers   = new List <IActOnCompletedTorrents>();
            _logger     = new Mock <ILog>();

            _parsedParameters = new UtorrentCommandLineParameters();
            _parameters.Setup(x => x.Parse(_args)).Returns(_parsedParameters);

            _action = new TorrentDownloadedAction(_parameters.Object, _handlers, _logger.Object);
        }
Beispiel #5
0
        public void Handle_WhenDirectoryIsPatternedLikeATvShow_(string tvShowFormat, string expectedLocation)
        {
            var originalDir = "c:\\something\\" + tvShowFormat;
            var @params     = new UtorrentCommandLineParameters
            {
                DirectoryWhereFilesAreSaved = originalDir
            };

            _dasts.Handle(@params);

            _mockDirectory.Verify(x => x.Move(originalDir, expectedLocation));
        }
        public void Handle_BadPartInConfiguration_DirectoryReferenceUpdated()
        {
            var @params = new UtorrentCommandLineParameters {
                DirectoryWhereFilesAreSaved = "c:\\something\\[Some Prefix]torrent"
            };
            var settings = new NameValueCollection {
                { "RemoveSpuriousFilenameParts::SomePrefix", "[Some Prefix]" }
            };

            SetupAppSettings(settings);

            _rsfp.Handle(@params);

            Assert.That(@params.DirectoryWhereFilesAreSaved, Is.EqualTo("c:\\something\\torrent"));
        }
        public void Handle_BadPartInConfiguration_FileReferenceUpdated()
        {
            var @params = new UtorrentCommandLineParameters {
                NameOfDownloadedFileForSingleFileTorrents = "c:\\something\\[Some Prefix]torrent.jpg"
            };
            var settings = new NameValueCollection {
                { "RemoveSpuriousFilenameParts::SomePrefix", "[Some Prefix]" }
            };

            SetupAppSettings(settings);

            _rsfp.Handle(@params);

            Assert.That(@params.NameOfDownloadedFileForSingleFileTorrents, Is.EqualTo("c:\\something\\torrent.jpg"));
        }
        public void Handle_BadPartInConfiguration_BadPartRemovedWithARenameInDirectories()
        {
            const string originalPath = "c:\\something\\[Some Prefix]torrent";
            var          @params      = new UtorrentCommandLineParameters {
                DirectoryWhereFilesAreSaved = originalPath
            };
            var settings = new NameValueCollection {
                { "RemoveSpuriousFilenameParts::SomePrefix", "[Some Prefix]" }
            };

            SetupAppSettings(settings);

            _rsfp.Handle(@params);

            _mockDirectory.Verify(x => x.Move(originalPath, "c:\\something\\torrent"));
        }
        public void Handle_BadPartInConfiguration_BadPartRemovedWithARenameInFiles()
        {
            const string originalPath = "c:\\something\\[Some Prefix]torrent.jpg";
            var          @params      = new UtorrentCommandLineParameters {
                NameOfDownloadedFileForSingleFileTorrents = originalPath
            };
            var settings = new NameValueCollection {
                { "RemoveSpuriousFilenameParts::SomePrefix", "[Some Prefix]" }
            };

            SetupAppSettings(settings);

            _rsfp.Handle(@params);

            _mockFile.Verify(x => x.Move(originalPath, "c:\\something\\torrent.jpg"));
        }
        public void Handle(UtorrentCommandLineParameters parameters)
        {
            var tvShowRegex = new Regex("(.*)S([0-9]{1,2})E([0-9]{1,2}).*");

            var kindOfDownload = parameters.KindOfDownload;

            if (!tvShowRegex.IsMatch(kindOfDownload.Location))
            {
                return;
            }

            Debug.WriteLine("Is TV show");
            Debug.WriteLine("IsDirectory: " + kindOfDownload.IsDirectory);

            var captures = tvShowRegex.Matches(kindOfDownload.Location);

            var show    = captures[0].Groups[1].Captures[0].Value;
            var season  = captures[0].Groups[2].Captures[0].Value;
            var episode = captures[0].Groups[3].Captures[0].Value;

            var path          = Path.GetDirectoryName(kindOfDownload.Location);
            var justTheEndBit = kindOfDownload.Location.Replace(path, string.Empty);
        }
 public void SetUp()
 {
     _cliInterpreter = new UtorrentCommandLineParameters();
 }
 public void Handle(UtorrentCommandLineParameters parameters)
 {
     Called = true;
 }