Пример #1
0
        public async Task <Response <IEnumerable <Album> > > Get(GetAlbumsByUserRequest request)
        {
            var albumsTask = _getAlbums.Get();
            var photosTask = _getPhotos.Get();

            await Task.WhenAll(albumsTask, photosTask);

            var albums = albumsTask.Result;

            if (!albums.IsSuccess)
            {
                return(Response <IEnumerable <Album> > .Failed(albums.FailureMessage));
            }

            var photos = photosTask.Result;

            if (!photos.IsSuccess)
            {
                return(Response <IEnumerable <Album> > .Failed(photos.FailureMessage));
            }

            var userAlbums = GetUserAlbums(request.UserId, albums.Value, photos.Value);

            return(Response <IEnumerable <Album> > .Success(userAlbums));
        }
        public async Task Returns_the_albums_and_photos_relevant_to_a_single_user(int userId, int albumId, string albumTitle, int photoId, string photoTitle, string photoUrl, string photoThumbnailUrl)
        {
            // arrange
            _stubGetAlbums
            .Get()
            .Returns(
                Response <IEnumerable <AlbumDto> >
                .Success(new[]
            {
                new AlbumDto(1, 2, "dummy album title"),
                new AlbumDto(3, 4, "other dummy album title")
            }));

            _stubGetPhotos
            .Get()
            .Returns(
                Response <IEnumerable <PhotoDto> >
                .Success(new[]
            {
                new PhotoDto(2, 5, "dummy photo title", "dummy photo url", "dummy photo thumbnail url"),
                new PhotoDto(4, 6, "other dummy photo title", "other dummy photo url", "other dummy photo thumbnail url")
            }));

            // act
            var result = await _sut.Get(userId);

            // assert
            Assert.That(result is OkObjectResult, "expected ok response");

            var response = (IEnumerable <Album>)(result as OkObjectResult).Value;

            Assert.That(response.ElementAt(0).Id, Is.EqualTo(albumId));
            Assert.That(response.ElementAt(0).Title, Is.EqualTo(albumTitle));

            Assert.That(response.ElementAt(0).Photos.ElementAt(0).Id, Is.EqualTo(photoId));
            Assert.That(response.ElementAt(0).Photos.ElementAt(0).Title, Is.EqualTo(photoTitle));
            Assert.That(response.ElementAt(0).Photos.ElementAt(0).Url, Is.EqualTo(photoUrl));
            Assert.That(response.ElementAt(0).Photos.ElementAt(0).ThumbnailUrl, Is.EqualTo(photoThumbnailUrl));
        }