Exemplo 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);
        }
Exemplo n.º 2
0
        public void Given_An_Invalid_DeckCardDetail_Should_Throw_ArgumentOutOfRangeException()
        {
            // Arrange
            var deckCardSearch = new DeckCardDetail();

            // Act
            Action act = () => CardMapperHelper.MapToCardOutputModel(_mapper, deckCardSearch);

            // Assert
            act.Should().Throw <ArgumentOutOfRangeException>();
        }
Exemplo n.º 3
0
        public void Given_A_Trap_DeckCardDetail_Should_Return_Monster_CardDetailOutputModel()
        {
            // Arrange

            var deckCardDetail = new DeckCardDetail
            {
                CategoryId    = 23424,
                Category      = "Trap",
                SubCategories = "Normal"
            };


            // Act
            var result = CardMapperHelper.MapToCardOutputModel(_mapper, deckCardDetail);

            // Assert
            result.Types.Should().Contain("Trap");
        }
Exemplo n.º 4
0
        public void Given_A_Monster_DeckCardDetail_Should_Return_Monster_CardDetailOutputModel()
        {
            // Arrange

            var deckCardDetail = new DeckCardDetail
            {
                CategoryId    = 23424,
                Category      = "Monster",
                SubCategories = "Normal,Fairy",
                AttributeId   = 43,
                Attribute     = "Light",
                TypeId        = 234,
                Type          = "Ritual"
            };


            // Act
            var result = CardMapperHelper.MapToCardOutputModel(_mapper, deckCardDetail);

            // Assert
            result.Types.Should().Contain("Monster");
        }