示例#1
0
        public void ValidateNoDuplicated()
        {
            var downloadRequest = new DownloadRequest()
            {
                Threads = 2,
                Links   = new System.Collections.Generic.List <LinkSave>
                {
                    new LinkSave {
                        Filename = "file1", Link = ""
                    },
                    new LinkSave {
                        Filename = "file2", Link = ""
                    },
                    new LinkSave {
                        Filename = "file3", Link = ""
                    },
                }
            };
            var downloadService = new DownloaderService(new FileDonwladStatus()
                                                        , NSubstitute.Substitute.For <Microsoft.Extensions.Configuration.IConfiguration>()
                                                        , NSubstitute.Substitute.For <Microsoft.Extensions.Logging.ILogger <DownloaderService> >());
            var duplicated = downloadService.GetDuplicatedFiles(downloadRequest);

            Assert.Empty(duplicated);
        }
示例#2
0
        public void ValidateEmptyLinks()
        {
            var downloadRequest = new DownloadRequest()
            {
                Threads = 2,
                Links   = null
            };
            var downloadService = new DownloaderService(new FileDonwladStatus()
                                                        , NSubstitute.Substitute.For <Microsoft.Extensions.Configuration.IConfiguration>()
                                                        , NSubstitute.Substitute.For <Microsoft.Extensions.Logging.ILogger <DownloaderService> >());
            var duplicated = downloadService.GetDuplicatedFiles(downloadRequest);

            Assert.Empty(duplicated);
        }
示例#3
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());
        }