public void TestDownloadImage_dishImageDataShouldReturnImage() { //Arrange ImageData imageData = new ImageData(); Dish dishWithImages = new Dish(); MongoGridFSFileInfo uploadedFile; using (var fs = new FileStream(fileName, FileMode.Open)) { uploadedFile = dishWithImages.UploadImageToDish(m_Testdb.GridFS, fs, fileName); } //act //Example for controller - File(fileStream, ("image/jpg") Stream fileStream = GetImageStream(dishWithImages.Image, m_Testdb.GridFS); //assert Assert.IsTrue(fileStream.CanRead); Assert.IsTrue(fileStream.Length > 0); }
public void TestDownloadImage_should_existInStorage() { //Arrange ImageData imageData = new ImageData(); Dish dishWithImages = new Dish(); MongoGridFSFileInfo uploadedFile; using (var fs = new FileStream(fileName, FileMode.Open)) { uploadedFile = dishWithImages.UploadImageToDish(m_Testdb.GridFS, fs, fileName); } //act var file = m_Testdb.GridFS.FindOne(Query.EQ("_id", dishWithImages.Image.Id)); //assert Assert.IsTrue(file.Exists); }
private Stream GetImageStream(ImageData imageData) { using (Restaurants rests = new Restaurants()) { var file = rests.DB.GridFS.FindOne(Query.EQ("_id", imageData.Id)); return file.OpenRead(); } }
private Stream GetImageStream(ImageData imageData, MongoGridFS mongoGridFS) { var file = mongoGridFS.FindOne(Query.EQ("_id", imageData.Id)); return file.OpenRead(); }
public void TestUploadImage_should_beSavedDishImageIdShouldHaveSameId() { //Arrange ImageData imageData = new ImageData(); Dish dishWithImages = new Dish(); MongoGridFSFileInfo uploadedFile; using (var fs = new FileStream(fileName, FileMode.Open)) { //act uploadedFile = dishWithImages.UploadImageToDish(m_Testdb.GridFS, fs, fileName); } //assert Assert.IsNotNull(dishWithImages.Image); Assert.AreEqual(uploadedFile.Id, dishWithImages.Image.Id); }
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); }
public static ImageData ConvertToImageData(MongoGridFSFileInfo gridFsInfo) { ImageData returnValue = new ImageData(); returnValue.Id = gridFsInfo.Id; returnValue.ImageFileName = gridFsInfo.Name; returnValue.CreatedAt = gridFsInfo.UploadDate; returnValue.ImageContentType = gridFsInfo.ContentType; return returnValue; }
// Not emplemented yet public ImageData GetImageDataById(string id) { ImageData returnValue = new ImageData(); using (Restaurants rests = new Restaurants()) { throw new NotImplementedException(); } }