Ejemplo n.º 1
0
        public void SaveImageLocally_CanSaveOneImage(string imageName, int mediaId)
        {
            var recipeId        = 52;
            var receivedImgPath = Path.Combine(this.mediasPath, receivedDataDirectory, imageName);
            // STEP1 - Create Media to load with image path
            var media = new Media {
                MediaPath = receivedImgPath, Id = mediaId, Title = "Some media", Recipe_Id = recipeId
            };

            using (var helper = new MediaLogicHelper(this._configuration.Object, this._loggerMock.Object))
            {
                // STEP2 - Load Image from disk
                // loading image as MediaDTO (to get img bytes)
                var mediaDtos = helper.LocateAndLoadMedias(new List <Media>()
                {
                    media
                });
                // STEP3 - Save it again
                ServiceResponse savingResult;
                var             medias = helper.SaveImagesLocally(mediaDtos, out savingResult);

                // VERIFY
                Assert.IsTrue(savingResult.Success);
                string userRecipePath;
                var    savedImgPath = MediaLogicHelper.GenerateSingleMediaPath(helper.UserMediasPath, recipeId, mediaId, out userRecipePath);
                // check file exists
                Assert.IsTrue(File.Exists(savedImgPath));
                Assert.AreEqual(medias.First(m => m.Id == media.Id).MediaPath, savedImgPath);
                long savedImageSize = new FileInfo(savedImgPath).Length;
                // verify size is under 800kb
                Assert.IsTrue(savedImageSize <= this.MAX_IMAGESIZE);
            }
        }
Ejemplo n.º 2
0
        public void SaveImageLocally_CanSaveMultipleImages()
        {
            var recipeId       = 53;
            var receivedImages = new List <(string File, int MediaId)> {
                ("foodMarket.jpg", 1), ("foodColor.jpeg", 2), ("foodMarketPng.png", 3)
            };

            // STEP1 - Create list of Media to load with image path
            var medias = new List <Media>();

            foreach (var i in receivedImages)
            {
                var receivedImgPath = Path.Combine(this.mediasPath, receivedDataDirectory, i.File);
                medias.Add(new Media {
                    MediaPath = receivedImgPath, Id = i.MediaId, Title = "Some media", Recipe_Id = recipeId
                });
            }
            using (var helper = new MediaLogicHelper(this._configuration.Object, this._loggerMock.Object))
            {
                // STEP2 - Load all Images from disk
                // loading all images as MediaDTO (to get img bytes)
                var mediaDtos = helper.LocateAndLoadMedias(medias);

                // STEP3 - Save it again
                ServiceResponse savingResult;
                var             resultMedias = helper.SaveImagesLocally(mediaDtos, out savingResult);
                Assert.IsTrue(savingResult.Success);

                // VERIFY
                string userRecipePath; // not needed so we override
                foreach (var i in receivedImages)
                {
                    var savedImgPath = MediaLogicHelper.GenerateSingleMediaPath(helper.UserMediasPath, recipeId, i.MediaId, out userRecipePath);
                    // check file exists
                    Assert.IsTrue(File.Exists(savedImgPath));
                    Assert.AreEqual(resultMedias.First(m => m.Id == i.MediaId).MediaPath, savedImgPath);

                    long savedImageSize = new FileInfo(savedImgPath).Length;
                    // verify size is under 800kb
                    Assert.Less(savedImageSize, this.MAX_IMAGESIZE);
                }
            }
        }