public void Delete_Photo() { Photo photo = new Photo { DateTime = DateTime.Now, Name = "testPhoto", FileFormat = FileFormat.gif, Path = "My/path/to/file", Id = AddNewGuid() }; AlbumDetailModel album = new AlbumDetailModel() { DateTime = DateTime.Now, Description = "Description", Id = TestGuidList.ElementAt(0), Name = "TmpAlbum1", Photos = new List <PhotoListModel> { mapper.EntityToListModel(photo) } }; photo.Album = mapper.DetailModelToEntity(album); albumRepo.Insert(album); photoRepo.Insert(mapper.EntityToDetailModel(photo), album.Id); photoRepo.Delete(photo.Id); Assert.Null(photoRepo.GetById(photo.Id)); Assert.NotNull(albumRepo.GetById(album.Id)); }
private static bool CleanupAlbum(CloudQueueMessage msg) { Trace.TraceInformation("CleanupAlbum called with {0}", msg.AsString); var parts = msg.AsString.Split('|'); if (parts.Length != 2) { Trace.TraceError("Unexpected input to the album cleanup queue: {0}", msg.AsString); return(false); } // interpret the message var owner = parts[0]; var album = parts[1]; var repository = new PhotoRepository(); var photos = repository.GetPhotosByAlbum(owner, album); // this will trigger another message to the queue for more scale! foreach (var photo in photos) { repository.Delete(photo); } return(true); }
public ActionResult Delete(int?id, int AlbumID) { string filePath = string.Empty; if (id != null && User.Identity.IsAuthenticated) { int photoID = (int)id; var photoToRemove = repo.ByID(photoID); //int AlbumID = (int)photoToRemove.AlbumID; if (photoToRemove != null) { filePath = Request.MapPath(photoToRemove.Path); FileInfo file = new FileInfo(filePath); repo.Delete(photoToRemove.ID); if (file.Exists) { file.Delete(); } } return(Json(Url.Action("ViewAlbum", "Album", new { id = AlbumID }))); } //return new RedirectResult(Url.Action("ViewAlbum", "Album", new { id = AlbumID })); return(Json(Request.UrlReferrer.ToString())); }
public void DeleteByNullValue() { // Arrange PhotoRepository photoRepository = new PhotoRepository(dbContext); // Act // Assert Assert.ThrowsException <ArgumentNullException>(() => photoRepository.Delete(entityToDelete: null)); }
public void DeleteByNullKey_Exception() { // Arrange PhotoRepository photoRepository = new PhotoRepository(dbContext); object wrongId = null; // Act // Assert Assert.ThrowsException <ArgumentNullException>(() => photoRepository.Delete(wrongId)); }
public void DeleteByWrongKey_Exception() { // Arrange PhotoRepository photoRepository = new PhotoRepository(dbContext); Guid wrongId = default(Guid); // Act // Assert Assert.ThrowsException <InvalidOperationException>(() => photoRepository.Delete(wrongId)); }
private void DeletePhoto(DeletePhotoMessage message) { var result = MessageBox.Show("Naozaj chcete vymazať túto fotku ?", "Vymazanie fotky", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.No) { return; } _photoRepository.Delete(message.PhotoId); var photo = Photos.FirstOrDefault(r => r.Id == message.PhotoId); if (photo != null) { Photos.Remove(photo); } }
public IHttpActionResult Delete(int photoId) { try { var request = Context.AuthenticatedRequest; var repository = new PhotoRepository(); var siteId = request.GetPostInt("siteId"); if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, Utils.PluginId)) { return(Unauthorized()); } repository.Delete(photoId); return(Ok(new {})); } catch (Exception ex) { return(InternalServerError(ex)); } }
public void DeleteByValue() { // Arrange PhotoRepository photoRepository = new PhotoRepository(dbContext); Photo photoToDelete = dbContext.Photos.First(); // Act List <CommentLike> deletedCommentLikes = dbContext.CommentLike .AsEnumerable().Where(cl => photoToDelete.Comments.Contains(cl.Comment)).ToList(); photoRepository.Delete(photoToDelete); dbContext.SaveChanges(); // Assert CollectionAssert.DoesNotContain(dbContext.Photos.ToArray(), photoToDelete); // Checks if all photo's likes are deleted. Assert.IsFalse(dbContext.PhotoLike.AsEnumerable().Any(pl => pl.Photo == null || pl.Photo.Id == photoToDelete.Id)); // Checks if all photo's comments are deleted. Assert.IsFalse(dbContext.Comments.AsEnumerable().Any(c => c.Photo == null || c.Photo.Id == photoToDelete.Id)); // Checks if all photo's comments' likes are deleted. CollectionAssert.IsNotSubsetOf(deletedCommentLikes, dbContext.CommentLike.ToList()); }
public async Task DeletePhoto() { // Arrange var options = new DbContextOptionsBuilder <MyAlbumDbContext>() .UseInMemoryDatabase(databaseName: "PhotoRepository_DeletePhoto_MyAlbumDatabase") .Options; using (var context = new MyAlbumDbContext(options)) { IEnumerable <Photo> seedPhotos = SeedPhotos(context); UnitOfWork unitOfWork = new UnitOfWork(context); PhotoRepository photoRepository = new PhotoRepository(context); int count = seedPhotos.Count(); foreach (var photo in seedPhotos) { // Act photoRepository.Delete(photo); await unitOfWork.CompleteAsync(); // Assert Assert.Equal(--count, context.Photos.Count()); } } }
private static void Service_ContentDeleteCompleted(object sender, ContentEventArgs e) { var repository = new PhotoRepository(); repository.Delete(e.SiteId, e.ChannelId, e.ContentId); }
public bool DeletePhoto(Photo photo) { return(_photoRepository.Delete(photo)); }
public static void DeletePhoto(PhotoData photo) { PhotoRepository photoRep = new PhotoRepository(); photoRep.Delete(photo.Id); }
public ActionResult DeletePhotos(int albumId, int[] selectedObjects) { //TODO access control PhotoRepository photos = new PhotoRepository(); if (selectedObjects != null) { foreach (int id in selectedObjects) { PhotoModel photo = photos.GetById(id); if (photo.Album.Id == albumId) photos.Delete(photo); } } return RedirectToAction("ManageAlbum", new { id = albumId }); }
public ActionResult Delete(Guid id) { PhotoRepository.Delete(id); return(null); }