Ejemplo n.º 1
0
        public async Task <DeckDetailOutputModel> Handle(DeckByIdQuery request, CancellationToken cancellationToken)
        {
            var deckResult = await _deckService.GetDeckById(request.DeckId);

            if (deckResult != null)
            {
                var response = DeckDetailOutputModel.From(deckResult);

                if (!string.IsNullOrWhiteSpace(response.YoutubeUrl))
                {
                    response.VideoId = YoutubeHelpers.ExtractVideoId(response.YoutubeUrl);
                }

                // we duplicate card based on quantity property, also maintain order
                var mainList  = deckResult.MainDeck.SelectMany(c => Enumerable.Repeat(c, c.Quantity)).OrderBy(c => c.SortOrder).ToList();
                var extraList = deckResult.ExtraDeck.SelectMany(c => Enumerable.Repeat(c, c.Quantity)).OrderBy(c => c.SortOrder).ToList();
                var sideList  = deckResult.SideDeck.SelectMany(c => Enumerable.Repeat(c, c.Quantity)).OrderBy(c => c.SortOrder).ToList();

                // we map to cardoutputmodel
                response.MainDeck  = mainList.Select(card => CardMapperHelper.MapToCardOutputModel(_mapper, card)).ToList();
                response.ExtraDeck = extraList.Select(card => CardMapperHelper.MapToCardOutputModel(_mapper, card)).ToList();
                response.SideDeck  = sideList.Select(card => CardMapperHelper.MapToCardOutputModel(_mapper, card)).ToList();

                return(response);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public void Given_A_YoutubeUrl_Extract_VideoId_(string youtubeVideoUrl, string expectVideoId)
        {
            // Arrange

            // Act
            var result = YoutubeHelpers.ExtractVideoId(youtubeVideoUrl);

            // Assert
            result.Should().BeEquivalentTo(expectVideoId);
        }