コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public void GetById_ShouldReturnNullDataWhenAlbumDoesNotExists()
        {
            var user  = UserCreator.Create("test");
            var album = AlbumCreator.Create(false, user);

            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);
            var returnedAlbum = service.GetById <AlbumViewModel>(album.Id, user.Id);

            Assert.Null(returnedAlbum);
        }
コード例 #8
0
        public void GetAlbumPhotos_ShouldThrowErrorWhenAlbumDoesNotExists()
        {
            var user  = UserCreator.Create("test");
            var album = AlbumCreator.Create(false, user);

            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 <Exception>(() => service.GetAlbumPhotos <PhotoAlbumViewModel>(album.Id, user.Id));

            Assert.Contains("Album does not exist!", ex.Message);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        public void AddPhoto_ShouldThrowErrorWhenAlbumDoesNotExist()
        {
            var user  = UserCreator.Create("test");
            var photo = PhotoCreator.Create(user, false, false);
            var album = AlbumCreator.Create(false, user);
            var list  = new List <PhotoAlbum>();

            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(list);
            var albumsRepo      = DeletableEntityRepositoryMock.Get <Album>(new List <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("Album does not exist", ex.Message);
        }
コード例 #11
0
        public void GetUserAlbums_ShouldReturnAllAlbumsWhereUserIsOwner()
        {
            var user         = UserCreator.Create("test");
            var privateAlbum = AlbumCreator.Create(true, user);
            var publicAlbum  = AlbumCreator.Create(false, user);

            var listAlbums = new List <Album>()
            {
                privateAlbum, publicAlbum
            };
            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);
            var albums  = service.GetUserAlbums <AlbumViewModel>(user.Id, user.Id);

            Assert.Equal(2, albums.Count);
        }
コード例 #12
0
        public void Delete_ShouldDeleteSuccessfully()
        {
            var user  = UserCreator.Create("test");
            var album = AlbumCreator.Create(false, user);

            var listAlbums = new List <Album>()
            {
                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);

            service.DeleteAsync(album.Id, user.Id).Wait();

            Assert.Empty(listAlbums);
        }
コード例 #13
0
        public void GetById_ShouldReturnCorrectData()
        {
            var user  = UserCreator.Create("test");
            var album = AlbumCreator.Create(false, user);

            var listAlbums = new List <Album>()
            {
                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);
            var returnedAlbum = service.GetById <AlbumViewModel>(album.Id, user.Id);

            Assert.Equal(album.Id, returnedAlbum.Id);
            Assert.Equal(album.Name, returnedAlbum.Name);
            Assert.Equal(album.Description, returnedAlbum.Description);
        }
コード例 #14
0
        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);
        }