Example #1
0
        public async Task Thumbnail_HappyFlowFileStreamResult_API_Test()
        {
            // Arrange
            var storage       = ArrangeStorage();
            var createAnImage = InsertSearchData();

            // Act
            // Create thumbnail in fake storage
            await new Thumbnail(storage, storage, new FakeIWebLogger()
                                ).CreateThumb(createAnImage.FilePath, createAnImage.FileHash);

            // Check if exist
            var controller = new ThumbnailController(_query, new FakeSelectorStorage(storage));

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var actionResult = controller.Thumbnail(createAnImage.FileHash, true) as FileStreamResult;

            // Thumbnail exist
            Assert.AreNotEqual(actionResult, null);
            var thumbnailAnswer = actionResult.ContentType;

            controller.Response.Headers.TryGetValue("x-filename", out var value);
            Assert.AreEqual(createAnImage.FileHash + ".jpg", value.ToString());

            Assert.AreEqual("image/jpeg", thumbnailAnswer);
            actionResult.FileStream.Dispose();             // for windows
        }
Example #2
0
        public void Thumbnail_InputBadRequest()
        {
            var storageSelector = new FakeSelectorStorage(ArrangeStorage());

            var controller   = new ThumbnailController(_query, storageSelector);;
            var actionResult = controller.Thumbnail("../") as BadRequestResult;

            Assert.AreEqual(400, actionResult.StatusCode);
        }
Example #3
0
        public void Thumbnail_NonExistingFile_API_Test()
        {
            var controller = new ThumbnailController(_query, new FakeSelectorStorage());

            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            var actionResult    = controller.Thumbnail("404filehash", false, true) as NotFoundObjectResult;
            var thumbnailAnswer = actionResult.StatusCode;

            Assert.AreEqual(404, thumbnailAnswer);
        }
Example #4
0
        public void Thumbnail_IsMissing_ButOriginalExist_butNoIsSingleItemFlag_API_Test()
        {
            // Photo exist in database but " + "isSingleItem flag is Missing
            var createAnImage = InsertSearchData();
            var storage       = ArrangeStorage();

            var controller = new ThumbnailController(_query, new FakeSelectorStorage(storage));

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var actionResult    = controller.Thumbnail(createAnImage.FileHash, false, true) as JsonResult;
            var thumbnailAnswer = actionResult.StatusCode;             // always null for some reason ?!

            Assert.AreEqual("Thumbnail is not ready yet", actionResult.Value);
        }
Example #5
0
        public void Thumbnail_GetExtraLargeSecondChoiceResult()
        {
            var storage = new FakeIStorage(new List <string> {
                "/"
            }, new List <string>
            {
                ThumbnailNameHelper.Combine("test", ThumbnailSize.ExtraLarge)
            });
            var controller = new ThumbnailController(_query, new FakeSelectorStorage(storage));

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            controller.Thumbnail("test", true, false, false);

            controller.Response.Headers.TryGetValue("x-image-size", out var value);
            Assert.AreEqual(ThumbnailSize.ExtraLarge.ToString(), value.ToString());
        }
Example #6
0
        public void Thumbnail_ShowOriginalImage_API_Test()
        {
            var createAnImage = InsertSearchData();
            var storage       = ArrangeStorage();

            var controller = new ThumbnailController(_query, new FakeSelectorStorage(storage));

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var actionResult    = controller.Thumbnail(createAnImage.FileHash, true) as FileStreamResult;
            var thumbnailAnswer = actionResult.ContentType;

            controller.Response.Headers.TryGetValue("x-filename", out var value);
            Assert.AreEqual("test.jpg", value.ToString());

            Assert.AreEqual("image/jpeg", thumbnailAnswer);

            actionResult.FileStream.Dispose();             // for windows
        }
Example #7
0
        public void Thumbnail_IgnoreRawFile()
        {
            var storageSelector = new FakeSelectorStorage(ArrangeStorage());

            var controller = new ThumbnailController(new FakeIQuery(
                                                         new List <FileIndexItem>
            {
                new FileIndexItem("/test.dng")
                {
                    FileHash = "hash1"
                }
            }), storageSelector);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            controller.Thumbnail("hash1", true);

            Assert.AreEqual(210, controller.Response.StatusCode);
        }
Example #8
0
        public async Task ApiController_FloatingDatabaseFileTest_API_Test()
        {
            var item = await _query.AddItemAsync(new FileIndexItem
            {
                ParentDirectory = "/fakeImage/",
                FileName        = "fake.jpg",
                FileHash        = "0986524678765456786543",
                Id = 788,
            });

            var storage = ArrangeStorage();

            var controller = new ThumbnailController(_query, new FakeSelectorStorage(storage));

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var actionResult    = controller.Thumbnail(item.FileHash, false, true) as NotFoundObjectResult;
            var thumbnailAnswer = actionResult.StatusCode;

            Assert.AreEqual(404, thumbnailAnswer);
            await _query.RemoveItemAsync(item);
        }
Example #9
0
        public async Task Thumbnail_CorruptImage_NoContentResult_Test()
        {
            // Arrange
            var storage         = ArrangeStorage();
            var plainTextStream = new PlainTextFileHelper().StringToStream("CorruptImage");
            await storage.WriteStreamAsync(plainTextStream, ThumbnailNameHelper.Combine(
                                               "hash-corrupt-image", ThumbnailSize.ExtraLarge));

            await _query.AddItemAsync(new FileIndexItem("/test2.jpg"){ FileHash = "hash-corrupt-image" });

            // Act
            var controller = new ThumbnailController(_query, new FakeSelectorStorage(storage));

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var actionResult = controller.Thumbnail("hash-corrupt-image",
                                                    false, true) as NoContentResult;

            Assert.AreEqual(204, actionResult.StatusCode);

            // remove files + database item
            await _query.RemoveItemAsync(await _query.GetObjectByFilePathAsync("/test2.jpg"));
        }
Example #10
0
        public async Task Thumbnail_HappyFlowDisplayJson_API_Test()
        {
            // Arrange
            var storage       = ArrangeStorage();
            var createAnImage = InsertSearchData();

            // Act
            // Create thumbnail in fake storage
            await new Thumbnail(storage, storage,
                                new FakeIWebLogger()).CreateThumb(createAnImage.FilePath, createAnImage.FileHash);

            // Check if exist
            var controller = new ThumbnailController(_query, new FakeSelectorStorage(storage));

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var actionResult = controller.Thumbnail(createAnImage.FileHash, true, true) as JsonResult;

            // Thumbnail exist
            Assert.AreNotEqual(actionResult, null);
            var thumbnailAnswer = actionResult.Value as string;

            Assert.AreEqual("OK", thumbnailAnswer);
        }