public void Update_ShouldUpdateAlbumSucessfully() { var user = UserCreator.Create("test"); var album = AlbumCreator.Create(false, user); var list = new List <Album>() { album, }; var editAlbumModel = new EditAlbumInputModel { Id = album.Id, OwnerId = user.Id, Description = "Updated", IsPrivate = false, Name = "Updated", }; var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>()); var albumsRepo = DeletableEntityRepositoryMock.Get <Album>(list); var services = new AlbumsService(albumsRepo.Object, photoAlbumsRepo.Object); services.UpdateAsync( album.Id, user.Id, editAlbumModel).Wait(); var item = list.First(); Assert.Equal(editAlbumModel.Description, item.Description); Assert.Equal(editAlbumModel.Name, item.Name); }
public void Update_ShouldNotUpdateAlbumSuccessfully() { var list = new List <Album>(); var model = new EditAlbumInputModel { Id = "1", OwnerId = "2", Description = "test", IsPrivate = false, Name = "test" }; var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>()); var albumsRepo = DeletableEntityRepositoryMock.Get <Album>(list); var services = new AlbumsService(albumsRepo.Object, photoAlbumsRepo.Object); Exception ex = Assert.Throws <AggregateException>(() => services.UpdateAsync("1", "2", model).Wait()); Assert.Contains("Album does not exist!", ex.Message); }
public async Task UpdateAsync(string albumId, string userId, EditAlbumInputModel model) { var album = this.albumsRespository.All().Where(x => x.Id == albumId && x.OwnerId == userId).FirstOrDefault(); if (album == null) { throw new Exception("Album does not exist!"); } album.Name = model.Name; album.Description = model.Description; album.IsPrivate = model.IsPrivate; await this.albumsRespository.SaveChangesAsync(); }
public async Task <IActionResult> Edit(string id, EditAlbumInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } try { var user = await this.userManager.GetUserAsync(this.User); await this.albumsService.UpdateAsync(id, user.Id, model); } catch (Exception ex) { this.ModelState.AddModelError(string.Empty, ex.Message); return(this.View(model)); } return(this.RedirectToAction("Show", "Album", new { Id = id })); }