public void GetAlbumPhotos_ShouldReturnAllPhotosWhenUserIsOwner() { var user = UserCreator.Create("test"); var publicPhoto = PhotoCreator.Create(user, false, false); var privatePhoto = PhotoCreator.Create(user, true, false); var album = AlbumCreator.Create(false, user); var listAlbums = new List <Album>() { album }; var listPhotoAlbums = new List <PhotoAlbum>() { PhotoAlbumCreator.Create(publicPhoto, album), PhotoAlbumCreator.Create(privatePhoto, album), }; var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(listPhotoAlbums); var albumsRepo = DeletableEntityRepositoryMock.Get <Album>(listAlbums); var service = new AlbumsService(albumsRepo.Object, photoAlbumsRepo.Object); var photos = service.GetAlbumPhotos <PhotoAlbumViewModel>(album.Id, user.Id); Assert.Equal(2, photos.Count); }
public void AddPhoto_ShouldThrowErrorWhenPhotoAlreadyInTheAlbum() { var user = UserCreator.Create("test"); var photo = PhotoCreator.Create(user, false, false); var album = AlbumCreator.Create(false, user); var mapping = PhotoAlbumCreator.Create(photo, album); var list = new List <PhotoAlbum>() { mapping }; var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(list); var albumsRepo = DeletableEntityRepositoryMock.Get <Album>(new List <Album>() { album }); var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>() { photo }); var service = new PhotoAlbumService(photosRepo.Object, albumsRepo.Object, photoAlbumsRepo.Object); Exception ex = Assert.Throws <AggregateException>(() => service.AddPhotoAsync(album.Id, photo.Id, user.Id).Wait()); Assert.Contains("Photo is already added to the album", ex.Message); }
public void GetAllByPhotoId_ShouldReturnCorrectNumber() { var user = UserCreator.Create("test"); var album1 = AlbumCreator.Create(false, user); var album2 = AlbumCreator.Create(false, user); var album3 = AlbumCreator.Create(false, user); var photo = PhotoCreator.Create(user, false, false); var mapping1 = PhotoAlbumCreator.Create(photo, album1); var mapping2 = PhotoAlbumCreator.Create(photo, album2); var mapping3 = PhotoAlbumCreator.Create(photo, album3); var albumsRepo = DeletableEntityRepositoryMock.Get <Album>(new List <Album>() { album1, album2, album3 }); var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>() { photo }); var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>() { mapping1, mapping2, mapping3 }); var service = new PhotoAlbumService(photosRepo.Object, albumsRepo.Object, photoAlbumsRepo.Object); var result = service.GetAllByPhotoId <PhotoAlbumViewModel>(photo.Id); Assert.Equal(3, result.Count); }
public void GetAllUsedAlbums_ShouldReturnCorrectNumber() { var user = UserCreator.Create("test"); var album1 = AlbumCreator.Create(false, user); var album2 = AlbumCreator.Create(false, user); var album3 = AlbumCreator.Create(false, user); var photo = PhotoCreator.Create(user, false, false); var mapping = PhotoAlbumCreator.Create(photo, album1); var albumsRepo = DeletableEntityRepositoryMock.Get <Album>(new List <Album>() { album1, album2, album3 }); var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>() { photo }); var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>() { mapping }); var service = new PhotoAlbumService(photosRepo.Object, albumsRepo.Object, photoAlbumsRepo.Object); var result = service.GetAllUsedAlbums <AlbumViewModel>(photo.Id, user.Id); Assert.Single(result); }
public void RemovPhoto_ShouldRemoveSuccessfully() { var user = UserCreator.Create("test"); var photo = PhotoCreator.Create(user, false, false); var album = AlbumCreator.Create(false, user); var mapping = PhotoAlbumCreator.Create(photo, album); var list = new List <PhotoAlbum>() { mapping }; var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(list); var albumsRepo = DeletableEntityRepositoryMock.Get <Album>(new List <Album>() { album }); var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>() { photo }); var service = new PhotoAlbumService(photosRepo.Object, albumsRepo.Object, photoAlbumsRepo.Object); service.RemovePhotoAsync(album.Id, photo.Id, user.Id).Wait(); Assert.Empty(list); }
public void Delete_ShouldNotDeleteWhenAlbumIsDoesNotExists() { var user = UserCreator.Create("test"); var album = AlbumCreator.Create(false, user); var photo = PhotoCreator.Create(user, false, false); var photoAlbum = PhotoAlbumCreator.Create(photo, album); var listAlbums = new List <Album>(); var listPhotoAlbums = new List <PhotoAlbum>(); var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(listPhotoAlbums); var albumsRepo = DeletableEntityRepositoryMock.Get <Album>(listAlbums); var service = new AlbumsService(albumsRepo.Object, photoAlbumsRepo.Object); Exception ex = Assert.Throws <AggregateException>(() => service.DeleteAsync(album.Id, user.Id).Wait()); Assert.Contains("Album does not exist!", ex.Message); }
public void Delete_ShoudNotDeleteWhenThereArePhotosAssociatedWithAlbum() { var user = UserCreator.Create("test"); var album = AlbumCreator.Create(false, user); var photo = PhotoCreator.Create(user, false, false); var photoAlbum = PhotoAlbumCreator.Create(photo, album); var listAlbums = new List <Album>() { album }; var listPhotoAlbums = new List <PhotoAlbum>() { photoAlbum }; var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(listPhotoAlbums); var albumsRepo = DeletableEntityRepositoryMock.Get <Album>(listAlbums); var services = new AlbumsService(albumsRepo.Object, photoAlbumsRepo.Object); Exception ex = Assert.Throws <AggregateException>(() => services.DeleteAsync(album.Id, user.Id).Wait()); Assert.Contains("Album contains photos!", ex.Message); }