Ejemplo n.º 1
0
        public void TestSaveImage_RestaurantImageDataShouldBeSavedInFile()
        {
            //Arrange
            var newFileName = @"C:\Users\Vadik\Dropbox\Work\Downloaded_AlGauchoIcon.jpg";
            ImageData imageData = new ImageData();
            //Dish dishWithImages = new Dish();
            RestaurantBasicData restaurantWithImage = new RestaurantBasicData();

            MongoGridFSFileInfo uploadedFile;
            using (var fs = new FileStream(fileName, FileMode.Open))
            {
                uploadedFile = restaurantWithImage.UploadImageToRestaurant(m_Testdb.GridFS, fs, fileName, fileContentType);
            }

            //act
            //save image to file
            var file = m_Testdb.GridFS.FindOne(Query.EQ("_id", restaurantWithImage.Image.Id));

            using (var stream = file.OpenRead())
            {
                var bytes = new byte[stream.Length];
                stream.Read(bytes, 0, (int)stream.Length);
                using (var newFs = new FileStream(newFileName, FileMode.Create))
                {
                    newFs.Write(bytes, 0, bytes.Length);
                }
            }
            //open source and saved files
            var source = new FileStream(fileName, FileMode.Open);
            var savedFile = new FileStream(newFileName, FileMode.Open);

            //assert
            Assert.AreEqual(source.Length, savedFile.Length);
        }
Ejemplo n.º 2
0
        public bool UploadImageToRestaurant(RestaurantBasicData rest, string imageUrl)
        {
            //resize picture 100 * 100
            //save to profile
            //on output implement logic of presentation  - if we have image let's display it
            //copy all images that we have on links to gridFS
            //Upload images from backoffice.

            log.DebugFormat("[UploadImageToRestaurant] RestaurantBasicData.Id={0}, imageUrl={1}.", rest.Id, imageUrl);

            try
            {
                using (Restaurants rests = new Restaurants())
                {
                    var imageStream = ImageServices.urlToStream(imageUrl);
                    string imageName = Path.GetFileName(imageUrl);
                    string contentType = getUrlContentType(imageUrl);
                    rest.UploadImageToRestaurant(rests.DB.GridFS, imageStream, imageName, contentType);
                }
                m_backofficeServiceLayer.UpdateRestaurant(rest);
                return true;
            }
            catch (Exception e)
            {
                log.DebugFormat("[UploadImageToRestaurant] Exception={0}.", e.ToString());
                return false;
            }
        }