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); }
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); }
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()); }