コード例 #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 GetUserFavoritePhotos_ShouldReturnFavoritePhotos()
        {
            var user    = UserCreator.Create("test");
            var visitor = UserCreator.Create("visitor");
            var photo1  = PhotoCreator.Create(user, false, false);
            var photo2  = PhotoCreator.Create(user, false, false);
            var photo3  = PhotoCreator.Create(visitor, false, false);

            var favorites = new List <PhotoFavorite>()
            {
                PhotoFavoriteCreator.Create(photo1, visitor),
                PhotoFavoriteCreator.Create(photo2, visitor),
                PhotoFavoriteCreator.Create(photo3, user),
            };

            var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>()
            {
                photo1, photo2, photo3
            });
            var favoritesRepo = EfRepositoryMock.Get <PhotoFavorite>(favorites);

            var service          = new FavoritesService(favoritesRepo.Object, photosRepo.Object);
            var userFavorites    = service.GetUserFavoritePhotos <PhotoViewModel>(user.Id);
            var visitorFavorites = service.GetUserFavoritePhotos <PhotoViewModel>(visitor.Id);

            Assert.Single(userFavorites);
            Assert.Equal(2, visitorFavorites.Count);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #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 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);
        }
コード例 #7
0
        public void Add_ShouldThrowErrorWhenPhotoDoesNotExist()
        {
            var user         = UserCreator.Create("test");
            var photo        = PhotoCreator.Create(user, false, true);
            var photosRepo   = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>());
            var commentsRepo = EfRepositoryMock.Get <Comment>(new List <Comment>());

            var service = new CommentService(photosRepo.Object, commentsRepo.Object);

            Exception ex = Assert.Throws <AggregateException>(() => service.AddAsync(photo.Id, user.Id, "comment").Wait());

            Assert.Contains("Photo does not exists!", ex.Message);
        }
コード例 #8
0
        public void Toggle_ShouldThrowErrorWhenPhotoDoesNotExists()
        {
            var user      = UserCreator.Create("test");
            var photo     = PhotoCreator.Create(user, false, false);
            var favorites = new List <PhotoFavorite>();

            var photosRepo    = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>());
            var favoritesRepo = EfRepositoryMock.Get <PhotoFavorite>(favorites);

            var       service = new FavoritesService(favoritesRepo.Object, photosRepo.Object);
            Exception ex      = Assert.Throws <AggregateException>(() => service.ToggleAsync(photo.Id, user.Id).Wait());

            Assert.Contains("Photo does not exist", ex.Message);
        }
コード例 #9
0
        public void Add_ShouldAddSucessfully()
        {
            var user       = UserCreator.Create("test");
            var photo      = PhotoCreator.Create(user, false, true);
            var comments   = new List <Comment>();
            var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>()
            {
                photo
            });
            var commentsRepo = EfRepositoryMock.Get <Comment>(comments);

            var service = new CommentService(photosRepo.Object, commentsRepo.Object);

            service.AddAsync(photo.Id, user.Id, "comment").Wait();
            Assert.Single(comments);
        }
コード例 #10
0
        public void Delete_ShouldThrowExceptionWhenPhotoDoesNotExists()
        {
            var user  = UserCreator.Create("test");
            var photo = PhotoCreator.Create(user, false, false);

            var list            = new List <Photo>();
            var photosRepo      = DeletableEntityRepositoryMock.Get <Photo>(list);
            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>());
            var storageService  = PhotoStorageServiceMock.Get();
            var metadataService = PhotoMetadataServiceMock.Get();

            var       service = new PhotoService(photosRepo.Object, storageService.Object, metadataService.Object, photoAlbumsRepo.Object);
            Exception ex      = Assert.Throws <AggregateException>(() => service.DeletePhotoAsync(photo.Id, user.Id).Wait());

            Assert.Contains("Such photo does not exists", ex.Message);
        }
コード例 #11
0
        public void Toggle_ShouldNotMakeFavoriteWhenUserOwnsThePhoto()
        {
            var user      = UserCreator.Create("test");
            var photo     = PhotoCreator.Create(user, false, false);
            var favorites = new List <PhotoFavorite>();

            var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>()
            {
                photo
            });
            var favoritesRepo = EfRepositoryMock.Get <PhotoFavorite>(favorites);

            var service = new FavoritesService(favoritesRepo.Object, photosRepo.Object);

            service.ToggleAsync(photo.Id, user.Id).Wait();

            Assert.Empty(favorites);
        }
コード例 #12
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);
        }
コード例 #13
0
        public void GetAllByUserId_ShouldReturnAllPhotosWhenUserIsOwner()
        {
            var user         = UserCreator.Create("test");
            var privatePhoto = PhotoCreator.Create(user, true, false);
            var publicPhoto  = PhotoCreator.Create(user, false, false);

            var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>()
            {
                privatePhoto, publicPhoto
            });
            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>());
            var storageService  = PhotoStorageServiceMock.Get();
            var metadataService = PhotoMetadataServiceMock.Get();

            var service = new PhotoService(photosRepo.Object, storageService.Object, metadataService.Object, photoAlbumsRepo.Object);
            var result  = service.GetAllByUserId <PhotoViewModel>(user.Id, user.Id);

            Assert.Equal(2, result.Count);
        }
コード例 #14
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);
        }
コード例 #15
0
        public void Toggle_ShouldMakeFavoriteWhenMappingDoesNotExist()
        {
            var user        = UserCreator.Create("test");
            var visitorUser = UserCreator.Create("visitor");
            var photo       = PhotoCreator.Create(user, false, false);
            var favorites   = new List <PhotoFavorite>();

            var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>()
            {
                photo
            });
            var favoritesRepo = EfRepositoryMock.Get <PhotoFavorite>(favorites);

            var service = new FavoritesService(favoritesRepo.Object, photosRepo.Object);

            service.ToggleAsync(photo.Id, visitorUser.Id).Wait();

            Assert.Single(favorites);
        }
コード例 #16
0
        public void Delete_ShouldDeletePhotoSuccessfully()
        {
            var user  = UserCreator.Create("test");
            var photo = PhotoCreator.Create(user, false, false);

            var list = new List <Photo>()
            {
                photo
            };
            var photosRepo      = DeletableEntityRepositoryMock.Get <Photo>(list);
            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>());
            var storageService  = PhotoStorageServiceMock.Get();
            var metadataService = PhotoMetadataServiceMock.Get();

            var service = new PhotoService(photosRepo.Object, storageService.Object, metadataService.Object, photoAlbumsRepo.Object);

            service.DeletePhotoAsync(photo.Id, user.Id).Wait();

            Assert.Empty(list);
        }
コード例 #17
0
        public void GetLatestPublic_ShouldReturnOnlyPublicPhotos()
        {
            var user   = UserCreator.Create("test");
            var photos = new List <Photo>()
            {
                PhotoCreator.Create(user, false, false),
                PhotoCreator.Create(user, true, false),
                PhotoCreator.Create(user, false, false),
                PhotoCreator.Create(user, true, false),
            };

            var photosRepo      = DeletableEntityRepositoryMock.Get <Photo>(photos);
            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>());
            var storageService  = PhotoStorageServiceMock.Get();
            var metadataService = PhotoMetadataServiceMock.Get();

            var service = new PhotoService(photosRepo.Object, storageService.Object, metadataService.Object, photoAlbumsRepo.Object);
            var result  = service.GetLatestPublic <PhotoViewModel>();

            Assert.Equal(2, result.Count);
        }
コード例 #18
0
        public void UserHasFavoritePhoto_ShouldFalseWhenPhotoIsNotFavoriteToTheUser()
        {
            var user        = UserCreator.Create("test");
            var visitorUser = UserCreator.Create("visitor");
            var photo       = PhotoCreator.Create(user, false, false);
            var favorites   = new List <PhotoFavorite>()
            {
                PhotoFavoriteCreator.Create(photo, visitorUser)
            };

            var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>()
            {
                photo
            });
            var favoritesRepo = EfRepositoryMock.Get <PhotoFavorite>(favorites);

            var service = new FavoritesService(favoritesRepo.Object, photosRepo.Object);
            var actual  = service.UserHasFavoritePhoto(photo.Id, user.Id);

            Assert.False(actual);
        }
コード例 #19
0
        public void GetById_ShouldNotReturnPrivatePhotoWhenUserIsNotOwner()
        {
            var user         = UserCreator.Create("test");
            var visitor      = UserCreator.Create("visitor");
            var privatePhoto = PhotoCreator.Create(user, true, false);
            var publicPhoto  = PhotoCreator.Create(user, false, false);

            var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>()
            {
                privatePhoto, publicPhoto
            });
            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>());
            var storageService  = PhotoStorageServiceMock.Get();
            var metadataService = PhotoMetadataServiceMock.Get();

            var service            = new PhotoService(photosRepo.Object, storageService.Object, metadataService.Object, photoAlbumsRepo.Object);
            var privatePhotoResult = service.GetById <PhotoViewModel>(privatePhoto.Id, visitor.Id);
            var publicPhotoResult  = service.GetById <PhotoViewModel>(publicPhoto.Id, visitor.Id);

            Assert.Null(privatePhotoResult);
            Assert.NotNull(publicPhotoResult);
        }
コード例 #20
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);
        }