public void StartTestTestFailure(int httpCode, DownloadItemActionError error) { service.Setup(x => x.StartDownload(It.IsAny <DownloadItem>(), out error)).Returns(false); var controller = new DownloadItemController(logger.Object, service.Object, authorizationService.Object, repository.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = TestHelper.ItemOwner.MapToClaimPrincipal() } } }; var response = controller.Start(It.IsAny <string>()); Assert.AreEqual(httpCode, response.StatusCode); }
/// <inheritdoc /> /// <summary> /// Starts a download /// </summary> /// <param name="item"></param> /// <param name="error"></param> /// <returns></returns> public bool StartDownload(DownloadItem item, out DownloadItemActionError error) { error = DownloadItemActionError.DownloadabilityFailure; var downloadMethod = ResolveDownloadMethod(item.FileUrl); if (downloadMethod == null) { logger.LogWarning("URL not handled: " + item.FileUrl); error = DownloadItemActionError.UrlNotHandled; return(false); } try { downloadMethod.Start(item); item.DownloadedSize = 0; item.StartedAt = DateTime.Now; item.Archived = false; item.State = DownloadState.Downloading; repository.Add(item); _ = dispatcher.Broadcast(new ItemStarted(item)); } catch (FileNotDownloadableException ex) { logger.LogWarning(ex.Message); error = DownloadItemActionError.DownloadabilityFailure; return(false); } catch (StartDownloadException ex) { logger.LogWarning(ex.Message); error = DownloadItemActionError.StartDownloadFailure; return(false); } return(true); }