public async Task CreateAlbumShouldCreateNewWallPost()
        {
            var post        = new Post();
            var postService = new Mock <IWallPostsService>();

            postService
            .Setup(r
                   => r.CreateAsync
                       (It.IsAny <string>(), It.IsAny <PostType>(), It.IsAny <int?>(), It.IsAny <string>()))
            .Callback <string, PostType, int?, string>((c, t, a, o) =>
            {
                post.UserId         = c;
                post.PostType       = t;
                post.AssignedEntity = a;
                post.Content        = o;
            });

            var service = new PhotoAlbumsService(
                this.albumRepository,
                this.pictureRepository,
                postService.Object,
                this.postRepository,
                this.cloudinaryService);

            await service.CreateAlbum("aaa", "bbb", null, "ccc");

            Assert.Equal("ccc", post.UserId);
            Assert.Equal(PostType.NewPicture, post.PostType);
            Assert.Null(post.Content);
        }
        public async Task CreateAlbumShouldCreateAlbum()
        {
            var albums = new List <Album>();

            var repository = new Mock <IDeletableEntityRepository <Album> >();

            repository
            .Setup(r => r.AddAsync(It.IsAny <Album>()))
            .Callback((Album a) => albums.Add(a));

            var cloudService = new Mock <ICloudinaryService>();

            cloudService.Setup(c => c.AddPhotoInAlbum(It.IsAny <int>(), It.IsAny <IFormFile>()));

            var service = new PhotoAlbumsService(
                repository.Object,
                this.pictureRepository,
                this.postsService,
                this.postRepository,
                cloudService.Object);

            await service.CreateAlbum("aaa", "bbb", null, "ccc");

            Assert.Single(albums);
            Assert.Equal("aaa", albums[0].Title);
            Assert.Equal("bbb", albums[0].Description);
            Assert.Equal("ccc", albums[0].UserId);
            Assert.IsAssignableFrom <ICollection <Picture> >(albums[0].Pictures);
        }
        public async Task GetByIdShouldReturnTheCorrectAlbum()
        {
            await this.PopulateAlbums();

            var service = new PhotoAlbumsService(
                this.albumRepository,
                this.pictureRepository,
                this.postsService,
                this.postRepository,
                this.cloudinaryService);

            var album = service.GetById <TestAlbumViewModel>(3);

            Assert.Equal("ccc", album.Title);
        }
        public async Task GetAllShouldReturnAllAlbums()
        {
            await this.PopulateAlbums();

            var service = new PhotoAlbumsService(
                this.albumRepository,
                this.pictureRepository,
                this.postsService,
                this.postRepository,
                this.cloudinaryService);

            List <TestAlbumViewModel> models = service.GetAll <TestAlbumViewModel>().ToList();

            Assert.Equal(3, models.Count);
        }
        public async Task DeleteAlbumShouldDeleteCorrectListAndCorrespondingPost()
        {
            await this.PopulateAlbums();

            await this.PopulatePosts();

            var service = new PhotoAlbumsService(
                this.albumRepository,
                this.pictureRepository,
                this.postsService,
                this.postRepository,
                this.cloudinaryService);

            await service.DeleteAlbum(3);

            var album = this.albumRepository.All().FirstOrDefault(a => a.Title == "ccc");
            var post  = this.postRepository.All().FirstOrDefault(p => p.Id == 3);

            Assert.Null(album);
            Assert.Null(post);
        }
        public async Task GetAllDeletedShouldReturnOnlyDeletedAlbums()
        {
            await this.PopulateAlbums();

            var album = this.albumRepository.All().FirstOrDefault(a => a.Id == 1);

            this.albumRepository.Delete(album);
            await this.albumRepository.SaveChangesAsync();

            var service = new PhotoAlbumsService(
                this.albumRepository,
                this.pictureRepository,
                this.postsService,
                this.postRepository,
                this.cloudinaryService);

            var resultList = service
                             .GetAllDeleted <TestAlbumViewModel>().ToList();

            Assert.Single(resultList);
            Assert.Equal("aaa", resultList[0].Title);
        }
        public async Task UnDeleteShouldUnDeleteCorrectAlbum()
        {
            await this.PopulateAlbums();

            var album = this.albumRepository.All().FirstOrDefault(a => a.Id == 2);

            this.albumRepository.Delete(album);
            await this.albumRepository.SaveChangesAsync();

            var service = new PhotoAlbumsService(
                this.albumRepository,
                this.pictureRepository,
                this.postsService,
                this.postRepository,
                this.cloudinaryService);

            await service.UnDelete(2);

            var result = this.albumRepository.All().FirstOrDefault(a => a.Id == 2);

            Assert.False(result.IsDeleted);
            Assert.Equal("bbb", result.Title);
        }