Ejemplo n.º 1
0
        public async Task HttpsDontStart()
        {
            var downloadRequest = new DownloadRequest()
            {
                Threads = 2,
                Links   = new System.Collections.Generic.List <LinkSave>
                {
                    new LinkSave {
                        Filename = "file1", Link = "https://someValidLink"
                    },
                    new LinkSave {
                        Filename = "file2", Link = "http://someValidLink"
                    }
                }
            };
            var fileDownloadStatus = new FileDonwladStatus();
            var downloadService    = new DownloaderService(fileDownloadStatus
                                                           , NSubstitute.Substitute.For <Microsoft.Extensions.Configuration.IConfiguration>()
                                                           , NSubstitute.Substitute.For <Microsoft.Extensions.Logging.ILogger <DownloaderService> >());

            Assert.False(downloadService.ValidateHttpLinks(downloadRequest));

            await downloadService.Download(downloadRequest);

            Assert.Empty(fileDownloadStatus.Definitions);
        }
Ejemplo n.º 2
0
        public IActionResult Download(DownloadRequest request)
        {
            if (request.Links == null || request.Links.Count == 0)
            {
                return(new BadRequestObjectResult("no links provided"));
            }
            if (!_downloaderService.ValidateHttpLinks(request))
            {
                return(new BadRequestObjectResult("http links only"));
            }

            var duplicated = _downloaderService.GetDuplicatedFiles(request);

            if (duplicated.Count != 0)
            {
                return(new BadRequestObjectResult($"duplicated filenames to save: {duplicated.Aggregate((i, j) => i + ", " + j)}"));
            }
            _downloaderService.Download(request);
            return(Ok());
        }