public void ArchiveTestCaseNotFound() { repository.Setup(x => x.Find(It.IsAny <string>())).Returns((DownloadItem)null); var controller = new DownloadItemController(logger.Object, service.Object, authorizationService.Object, repository.Object); var response = controller.Archive(It.IsAny <string>()); Assert.AreEqual(404, response.StatusCode); }
public void ArchiveTestCaseUnauthorized() { var item = new DownloadItem(); service .Setup(x => x.ArchiveDownload(item)); repository.Setup(x => x.Find(It.IsAny <string>())).Returns(item); authorizationService .Setup( x => x.AuthorizeAsync( It.IsAny <ClaimsPrincipal>(), It.IsAny <DownloadItem>(), DownloadItemPolicies.ArchivePolicy)) .Returns(Task.FromResult(AuthorizationResult.Failed())); var controller = new DownloadItemController(logger.Object, service.Object, authorizationService.Object, repository.Object); Assert.Throws <InvalidOperationException>(() => controller.Archive(It.IsAny <string>())); }
public void ArchiveTestCaseOk() { var item = new DownloadItem(); service .Setup(x => x.ArchiveDownload(item)); repository.Setup(x => x.Find(It.IsAny <string>())).Returns(item); authorizationService .Setup( x => x.AuthorizeAsync( It.IsAny <ClaimsPrincipal>(), It.IsAny <DownloadItem>(), DownloadItemPolicies.ArchivePolicy)) .Returns(Task.FromResult(AuthorizationResult.Success())); var controller = new DownloadItemController(logger.Object, service.Object, authorizationService.Object, repository.Object); var response = controller.Archive(It.IsAny <string>()); service.Verify(x => x.ArchiveDownload(item), Times.Once); Assert.AreEqual(200, response.StatusCode); }