public async Task DownloadPhotoCorrupt() { // Arrange var selectorStorage = new FakeSelectorStorage(ArrangeStorage()); var item = await _query.AddItemAsync(new FileIndexItem { FileName = "corrupt.jpg", ParentDirectory = "/", FileHash = "hash" }); // Act var controller = new DownloadPhotoController(_query, selectorStorage, new FakeIWebLogger()) { ControllerContext = { HttpContext = new DefaultHttpContext() } }; var actionResult = await controller.DownloadPhoto("/corrupt.jpg") as JsonResult; Assert.AreNotEqual(null, actionResult); Assert.AreEqual(500, controller.Response.StatusCode); await _query.RemoveItemAsync(item); }
public async Task DownloadPhoto_isThumbnailTrue_ReturnAThumb_ReturnFileStream_Test() { // Arrange var fileIndexItem = InsertSearchData(); var selectorStorage = new FakeSelectorStorage(ArrangeStorage()); // Act var controller = new DownloadPhotoController(_query, selectorStorage, new FakeIWebLogger()); controller.ControllerContext.HttpContext = new DefaultHttpContext(); // Run once var actionResult1 = await controller.DownloadPhoto(fileIndexItem.FilePath) as FileStreamResult; actionResult1.FileStream.Dispose(); // Run twice var actionResult2 = await controller.DownloadPhoto(fileIndexItem.FilePath) as FileStreamResult; Assert.AreNotEqual(null, actionResult2); actionResult2.FileStream.Dispose(); }
public async Task DownloadPhoto_NotFound() { // Arrange var selectorStorage = new FakeSelectorStorage(ArrangeStorage()); // Act var controller = new DownloadPhotoController(_query, selectorStorage, new FakeIWebLogger()) { ControllerContext = { HttpContext = new DefaultHttpContext() } }; var actionResult = await controller.DownloadPhoto("/not-found.jpg") as NotFoundObjectResult; Assert.AreNotEqual(null, actionResult); Assert.AreEqual(404, actionResult.StatusCode); }
public async Task ApiController_DownloadPhoto_SourceImageIsMissing_Test() { // Arrange var fileIndexItem = InsertSearchData(); // so the item does not exist on disk var storage = ArrangeStorage(); var selectorStorage = new FakeSelectorStorage(); // Act var controller = new DownloadPhotoController(_query, selectorStorage, new FakeIWebLogger()); var actionResult = await controller.DownloadPhoto(fileIndexItem.FilePath) as NotFoundObjectResult; Assert.AreNotEqual(null, actionResult); Assert.AreEqual(404, actionResult.StatusCode); Assert.AreEqual("source image missing /test.jpg", actionResult.Value); }
public async Task DownloadPhoto_Thumb_base_folder_not_found_Test() { // Arrange var fileIndexItem = InsertSearchData(); var storage = new FakeIStorage(null, new List <string> { "/test.jpg" }, new List <byte[]> { FakeCreateAn.CreateAnImage.Bytes }); var selectorStorage = new FakeSelectorStorage(storage); // Act var controller = new DownloadPhotoController(_query, selectorStorage, new FakeIWebLogger()); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var actionResult = await controller.DownloadPhoto(fileIndexItem.FilePath) as NotFoundObjectResult; Assert.AreNotEqual(null, actionResult); Assert.AreEqual(404, actionResult.StatusCode); Assert.AreEqual("ThumbnailTempFolder not found", actionResult.Value); }