public void CalculationOfFileSizeShouldReturnASize() { if (_scannerService.GetResponse("https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/Grave_eend_maasmuur.jpg/1200px-Grave_eend_maasmuur.jpg")) { var length = _scannerService.GetFileSize(); Assert.Equal(356296, length); } }
public IActionResult Scan(URLItem item) { // Get url from user string stringUrl = item.Url; bool isUri = Uri.IsWellFormedUriString(stringUrl, UriKind.RelativeOrAbsolute); if (!isUri) { return(BadRequest("URL is invalid")); } // Throw an error if there is no response for this URL if (!_scannerService.GetResponse(stringUrl)) { throw new Exception("Something is wrong with file"); } if (_scannerService.GetFileSize() > 209715200) { return(BadRequest("File size is too big, should be below 200 MB")); } // Write the response to the user item.Result = _virusScanService.GetVirusScanResult(); item.Sha1 = _scannerService.GetCheckSum(); _context.URLItems.Add(item); _context.SaveChanges(); return(CreatedAtRoute("GetURL", new { id = item.Id, result = item.Result, sha1 = item.Sha1 }, item)); }