コード例 #1
0
        public async Task WhenICallGalleryService_WithInvalidAlbumIds_IGetErrors()
        {
            _albumService.Setup(x => x.GetUserAlbums(It.IsAny <int>())).ReturnsAsync(MockAlbums());
            _photoService.Setup(x => x.GetAlbumPhotos(It.IsAny <int>())).ThrowsAsync(new DataValidationException("test"));
            _galleryService = new GalleryService(_albumService.Object, _photoService.Object);
            GalleryUserDto gallery = await _galleryService.GetUsersGallery(1);

            Assert.AreEqual(3, gallery.Albums.Count);
            Assert.AreEqual(3, gallery.Errors.Count);
        }
コード例 #2
0
        public async Task WhenICallGalleryService_WithValidUserId_IGetAlbumsWithPhotos()
        {
            _albumService.Setup(x => x.GetUserAlbums(It.IsAny <int>())).ReturnsAsync(MockAlbums());
            _photoService.Setup(x => x.GetAlbumPhotos(It.IsAny <int>())).ReturnsAsync(MockPhotos());
            _galleryService = new GalleryService(_albumService.Object, _photoService.Object);
            GalleryUserDto gallery = await _galleryService.GetUsersGallery(1);

            _albumService.Verify(x => x.GetUserAlbums(1), Times.Once);
            _photoService.Verify(x => x.GetAlbumPhotos(It.IsAny <int>()), Times.Exactly(3));
            Assert.AreEqual(1, gallery.UserId);
            Assert.AreEqual(3, gallery.Albums.Count);
            foreach (var album in gallery.Albums)
            {
                Assert.AreEqual(4, album.Photos.Count);
            }
        }
コード例 #3
0
        public async Task <GalleryUserDto> GetUsersGallery(int userId)
        {
            GalleryUserDto gallery = new GalleryUserDto(userId);

            gallery.Albums = await _albumService.GetUserAlbums(userId);

            foreach (var album in gallery.Albums)
            {
                try
                {
                    album.Photos = await _photoService.GetAlbumPhotos(album.Id);
                }
                catch (Exception ex)
                {
                    gallery.Errors.Add($"Album Photo could not be retrieved {album?.Title}" + ex.Message);
                }
            }

            return(gallery);
        }