public ActionResult UploadImages(HttpPostedFileBase[] files, string Group) { MediaRepo mediaRepo = new MediaRepo(); //Ensure model state is valid if (ModelState.IsValid) { //iterating through multiple file collection foreach (HttpPostedFileBase file in files) { Medium medium = new Medium(); //Checking file is available to save. if (file != null) { var InputFileName = Path.GetFileName(file.FileName); var ServerSavePath = Path.Combine(Server.MapPath("~/images/PicGallery/") + InputFileName); medium.ContentLocation = "../images/PicGallery/" + InputFileName; medium.MediaName = InputFileName; medium.DateCreated = DateTime.Now; medium.groupId = Convert.ToInt32(Group); medium.CreatedBy = 1; // User.Identity.GetUserId(); mediaRepo.addIamge(medium); //Save file to server folder file.SaveAs(ServerSavePath); //assigning file uploaded status to ViewBag for showing message to user. ViewBag.UploadStatus = files.Count().ToString() + " files uploaded successfully."; } } } return(View()); }
public void DeleteMedia_Successful() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); //ARRANGE var media = new MediaTO { Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; var media2 = new MediaTO { Name = "C# pour les nulls", Type = MediaType.Book, Path = "C:/Book/Code" }; var media3 = new MediaTO { Name = "The IT Crowd", Type = MediaType.Serie, Path = "C:/Films/Series" }; var result = mediaRepo.CreateMedia(media); var result2 = mediaRepo.CreateMedia(media2); var result3 = mediaRepo.CreateMedia(media3); context.SaveChanges(); //ACT var test = mediaRepo.DeleteMedia(result); context.SaveChanges(); //ASSERT Assert.AreEqual(2, context.Medias.Count()); } }
public void ModifyMedia_ProvidingNull_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); Assert.ThrowsException<ArgumentNullException>(() => mediaRepo.ModifyMedia(null)); } }
public void DeleteMedia_ProvidingNull_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); Assert.ThrowsException <KeyNotFoundException>(() => mediaRepo.DeleteMedia(null)); } }
public void ModifyMedia_ProvidingNonExistingId_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); var media = new MediaTO {Id=1450, Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; Assert.ThrowsException<KeyNotFoundException>(() => mediaRepo.ModifyMedia(media)); } }
public void GetAllMedia_NoMediaInDb_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); Assert.ThrowsException <ArgumentNullException>(() => mediaRepo.GetAllMedias()); } }
public void GetMediaById_ProvidingNonExistingId_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); //ASSERT Assert.ThrowsException <ArgumentNullException>(() => mediaRepo.GetById(14)); } }
public void DeleteMedia_ProvidingNonExistingMedia_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); var media = new MediaTO { Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; Assert.ThrowsException <ArgumentException>(() => mediaRepo.DeleteMedia(media)); } }
public void GetMediaById_ProvidingNoId_ThrowException() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); //ARRANGE var media = new MediaTO { Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; //ASSERT Assert.ThrowsException <ArgumentException>(() => mediaRepo.GetById(media.Id)); } }
public void CreateMedia_AddExistingMedia_DoNotInsertTwiceInDb() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); var media = new MediaTO { Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; var addedMedia = mediaRepo.CreateMedia(media); context.SaveChanges(); mediaRepo.CreateMedia(addedMedia); context.SaveChanges(); Assert.AreEqual(1, context.Medias.Count()); } }
public void CreateMedia_Successful() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); //ACT var media = new MediaTO { Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; var result = mediaRepo.CreateMedia(media); context.SaveChanges(); //ASSERT Assert.IsNotNull(result); Assert.AreEqual("Cendrillon", result.Name); Assert.AreEqual(1, result.Id); } }
public void ModifyMedia_Successful() { var connection = Effort.DbConnectionFactory.CreateTransient(); using (var context = new MediaLibraryContext(connection)) { IRepo mediaRepo = new MediaRepo(context); //ARRANGE var media = new MediaTO { Name = "Cendrillon", Type = MediaType.Film, Path = "C:/Films/Animation" }; var result = mediaRepo.CreateMedia(media); context.SaveChanges(); //ACT result.Name = "Cendrillon Remaster"; var test = mediaRepo.ModifyMedia(result); context.SaveChanges(); //ASSERT Assert.AreEqual("Cendrillon Remaster", test.Name); } }
public MediaController() { mediaRepo = new MediaRepo(new MediaLibraryContext()); }