Exemple #1
0
        public void Given_A_Valid_Spell_YugiohCard_With_Types_Should_Map_To_SubCategoryIds_Property()
        {
            // Arrange
            var expected = new List <int> {
                18
            };

            var yugiohCard = new YugiohCard
            {
                Name = "Black Illusion Ritual",

                Description = "Amazing card!",
                CardNumber  = "41426869",
                Property    = "Ritual",
                CardType    = "Spell",
                ImageUrl    = "https://vignette.wikia.nocookie.net/yugioh/images/8/82/BlackIllusionRitual-LED2-EN-C-1E.png/revision/latest/scale-to-width-down/300?cb=20180223153750"
            };
            var cardInputModel = new CardInputModel();

            // Act
            var result = SpellCardHelper.MapSubCategoryIds(yugiohCard, cardInputModel, TestData.AllCategories(), TestData.AllSubCategories());

            // Assert
            result.SubCategoryIds.Should().BeEquivalentTo(expected);
        }
Exemple #2
0
        public void Given_A_Valid_YugiohCard_With_A_Level_Should_Map_To_CardLevel_Property()
        {
            // Arrange
            const int expected = 8;

            var yugiohCard = new YugiohCard
            {
                Name        = "Darkness Dragon",
                Description = "Amazing card!",
                CardNumber  = "543534",
                Attribute   = "Dark",
                Types       = "Effect/Ritual/Dragon",
                CardType    = "Monster",
                Level       = 8,
                ImageUrl    = "https://vignette.wikia.nocookie.net/yugioh/images/b/b4/BlueEyesWhiteDragon-LED3-EN-C-1E.png/revision/latest/scale-to-width-down/300?cb=20180928161125"
            };

            var cardInputModel       = new CardInputModel();
            var monsterCategory      = TestData.AllCategories().Single(c => c.Name.Equals(YgoCardType.Monster.ToString(), StringComparison.OrdinalIgnoreCase));
            var monsterSubCategories = TestData.AllSubCategories().Select(sc => sc).Where(sc => sc.CategoryId == monsterCategory.Id);

            // Act
            var result = MonsterCardHelper.MapMonsterCard(yugiohCard, cardInputModel, TestData.AllAttributes(), monsterSubCategories, TestData.AllTypes(), TestData.AllLinkArrows());

            // Assert
            result.CardLevel.Should().Be(expected);
        }
Exemple #3
0
        public void Given_A_Valid_A_Monster_YugiohCard_Should_Map_To_CardInputModel()
        {
            // Arrange
            var yugiohCard = new YugiohCard
            {
                Name        = "Decode Talker",
                Description = "Amazing card!",
                CardNumber  = "01861629",
                Attribute   = "Dark",
                Types       = "Cyberse / Link / Effect",
                CardType    = "Monster",
                LinkArrows  = "	Bottom-Left, Top, Bottom-Right",
                AtkDef      = "2300 / 3",
                ImageUrl    = "https://vignette.wikia.nocookie.net/yugioh/images/5/5d/DecodeTalker-YS18-EN-C-1E.png/revision/latest/scale-to-width-down/300?cb=20180712163921"
            };
            var cardInputModel       = new CardInputModel();
            var monsterCategory      = TestData.AllCategories().Single(c => c.Name.Equals(YgoCardType.Monster.ToString(), StringComparison.OrdinalIgnoreCase));
            var monsterSubCategories = TestData.AllSubCategories().Select(sc => sc).Where(sc => sc.CategoryId == monsterCategory.Id);

            // Act
            var result = MonsterCardHelper.MapMonsterCard(yugiohCard, cardInputModel, TestData.AllAttributes(), monsterSubCategories, TestData.AllTypes(), TestData.AllLinkArrows());

            // Assert
            result.Should().NotBeNull();
        }
        public static CardInputModel MapSubCategoryIds(YugiohCard yugiohCard, CardInputModel cardInputModel, ICollection <Category> categories, ICollection <SubCategory> subCategories)
        {
            cardInputModel.SubCategoryIds = new List <int>
            {
                SubCategoryMapper.SubCategoryId(categories, subCategories, YgoCardType.Trap, yugiohCard.Property)
            };

            return(cardInputModel);
        }
Exemple #5
0
        public async Task <int> AddAccountCard(string accountId, CardInputModel input)
        {
            var card = _externalAccountService.Create(accountId, new ExternalAccountCreateOptions()
            {
                ExternalAccount = input.ExternalAccount
            });

            return(await PullCard(card));
        }
Exemple #6
0
        public static CardInputModel MapCardImageUrl(YugiohCard yugiohCard, CardInputModel cardInputModel)
        {
            if (yugiohCard.ImageUrl != null)
            {
                cardInputModel.ImageUrl = new Uri(yugiohCard.ImageUrl);
            }

            return(cardInputModel);
        }
        public IActionResult CreateCard(string deckId)
        {
            var viewModel = new CardInputModel
            {
                DeckId = deckId,
            };

            return(this.View("CreateCard", viewModel));
        }
Exemple #8
0
        public async Task <int> AddCustomerCard(string customerId, CardInputModel input)
        {
            var card = _cardService.Create(customerId, new CardCreateOptions()
            {
                Source   = input.ExternalAccount,
                Validate = true
            });

            return(await PullCard(card));
        }
        public void Given_A_Null_CardType_Validation_Should_Fail()
        {
            // Arrange
            var cardInputModel = new CardInputModel();

            // Act
            Action act = () => _sut.ShouldHaveValidationErrorFor(c => c.CardType, cardInputModel);

            // Assert
            act.Invoke();
        }
Exemple #10
0
        public static CardInputModel MapBasicCardInformation(YugiohCard yugiohCard, CardInputModel cardInputModel)
        {
            cardInputModel.CardType =
                (YgoCardType?)(Enum.TryParse(typeof(YgoCardType), yugiohCard.CardType, true, out var cardType)
                    ? cardType
                    : null);
            cardInputModel.CardNumber  = long.TryParse(yugiohCard.CardNumber, out var cardNumber) ? cardNumber : (long?)null;
            cardInputModel.Name        = yugiohCard.Name;
            cardInputModel.Description = yugiohCard.Description;

            return(cardInputModel);
        }
        public void Given_An_Invalid_Def_Validation_Should_Fail(int def)
        {
            // Arrange
            var inputModel = new CardInputModel {
                CardType = YgoCardType.Monster, Def = def
            };

            // Act
            Action act = () => _sut.ShouldHaveValidationErrorFor(c => c.Def, inputModel);

            // Assert
            act.Invoke();
        }
        public void Given_An_Invalid_CardLevel_Validation_Should_Fail(int cardLevel)
        {
            // Arrange
            var inputModel = new CardInputModel {
                CardType = YgoCardType.Monster, CardLevel = cardLevel
            };

            // Act
            Action act = () => _sut.ShouldHaveValidationErrorFor(c => c.CardLevel, inputModel);

            // Assert
            act.Invoke();
        }
        public void Given_An_Invalid_SubCategoryIds_Validation_Should_Fail()
        {
            // Arrange
            var inputModel = new CardInputModel {
                CardType = YgoCardType.Monster
            };

            // Act
            Action act = () => _sut.ShouldHaveValidationErrorFor(c => c.SubCategoryIds, inputModel);

            // Assert
            act.Invoke();
        }
        public void Given_An_Invalid_CardName_Validation_Should_Fail(string name)
        {
            // Arrange
            var inputModel = new CardInputModel {
                CardType = YgoCardType.Monster, Name = name
            };

            // Act
            Action act = () => _sut.ShouldHaveValidationErrorFor(c => c.Name, inputModel);

            // Assert
            act.Invoke();
        }
        public void Given_An_Invalid_Ark_Validation_Should_Fail(int atk)
        {
            // Arrange
            var inputModel = new CardInputModel {
                CardType = YgoCardType.Monster, Atk = atk
            };

            // Act
            Action act = () => _sut.ShouldHaveValidationErrorFor(c => c.Atk, inputModel);

            // Assert
            act.Invoke();
        }
        public void Given_A_Valid_SpellOrTrap_CardType_Should_Map_CardType_To_Correct_YgoCardType(string cardType, YgoCardType expected)
        {
            // Arrange
            var yugiohCard = new YugiohCard
            {
                Property = "Normal",
                CardType = cardType
            };
            var cardInputModel = new CardInputModel();

            // Act
            var result = CardHelper.MapBasicCardInformation(yugiohCard, cardInputModel);

            // Assert
            result.CardType.Should().Be(expected);
        }
Exemple #17
0
        public void Add(CardInputModel input, string userId)
        {
            var card = new Card()
            {
                Name        = input.Name,
                ImageUrl    = input.ImageUrl,
                Keyword     = input.Keyword,
                Attack      = int.Parse(input.Attack),
                Health      = int.Parse(input.Health),
                Description = input.Description,
            };

            this.db.Cards.Add(card);
            this.db.SaveChanges();
            this.AddToCollection(card.Id, userId);
        }
        public void Given_A_Valid_Monster_CardType_Should_Map_CardType_To_Correct_YgoCardType(string cardType, YgoCardType expected)
        {
            // Arrange
            var yugiohCard = new YugiohCard
            {
                Attribute = "Dark",
                Types     = "Effect/Ritual",
                CardType  = cardType
            };
            var cardInputModel = new CardInputModel();

            // Act
            var result = CardHelper.MapBasicCardInformation(yugiohCard, cardInputModel);

            // Assert
            result.CardType.Should().Be(expected);
        }
        public async Task <IActionResult> CreateCard(CardInputModel inputModel, string submitType)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            await this.cardsService.CreateCard(inputModel.FrontSide, inputModel.BackSide, inputModel.DeckId);

            if (submitType == "another")
            {
                return(this.RedirectToAction("CreateCard", new { inputModel.DeckId }));
            }
            else
            {
                return(this.RedirectToAction("MyDecks", "Decks"));
            }
        }
        public static CardInputModel MapMonsterCard(YugiohCard yugiohCard, CardInputModel cardInputModel, ICollection <Attribute> attributes, IEnumerable <SubCategory> monsterSubCategories, ICollection <Type> types, ICollection <LinkArrow> linkArrows)
        {
            cardInputModel.AttributeId    = MonsterAttributeId(yugiohCard, attributes);
            cardInputModel.SubCategoryIds = MonsterSubCategoryIds(yugiohCard, monsterSubCategories);
            cardInputModel.TypeIds        = MonsterTypeIds(yugiohCard, types);

            if (yugiohCard.LinkArrows != null)
            {
                cardInputModel.LinkArrowIds = MonsterLinkArrowIds(yugiohCard, linkArrows);
            }

            if (yugiohCard.Level.HasValue)
            {
                cardInputModel.CardLevel = yugiohCard.Level;
            }

            if (yugiohCard.Rank.HasValue)
            {
                cardInputModel.CardRank = yugiohCard.Rank;
            }

            if (!string.IsNullOrWhiteSpace(yugiohCard.AtkDef))
            {
                var atk = Atk(yugiohCard);
                var def = DefOrLink(yugiohCard);

                int.TryParse(atk, out var cardAtk);
                int.TryParse(def, out var cardDef);

                cardInputModel.Atk = cardAtk;
                cardInputModel.Def = cardDef;
            }

            if (!string.IsNullOrWhiteSpace(yugiohCard.AtkLink))
            {
                var atk = AtkLink(yugiohCard);

                int.TryParse(atk, out var cardAtk);

                cardInputModel.Atk = cardAtk;
            }

            return(cardInputModel);
        }
        public HttpResponse Add(CardInputModel inputModel)
        {
            if (!this.IsUserSignedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (string.IsNullOrWhiteSpace(inputModel.Name) || inputModel.Name.Length < CardNameMinLength || inputModel.Name.Length > CardNameMaxLength)
            {
                return(this.Error($"Name should be between {CardNameMinLength} and {CardNameMaxLength} characters long!"));
            }

            if (string.IsNullOrWhiteSpace(inputModel.Image))
            {
                return(this.Error("The image is required!"));
            }

            if (string.IsNullOrWhiteSpace(inputModel.Keyword))
            {
                return(this.Error("Keyword is required!"));
            }

            if (inputModel.Attack < CardAttackMinValue)
            {
                return(this.Error("Attack should be non-negative integer!"));
            }

            if (inputModel.Health < CardHealthMinValue)
            {
                return(this.Error("Health should be non-negative integer!"));
            }

            if (string.IsNullOrWhiteSpace(inputModel.Description) || inputModel.Description.Length > CardDescriptionMaxLength)
            {
                return(this.Error($"Description is required and its length should be at most {CardDescriptionMaxLength} characters!"));
            }

            var userId = this.GetUserId();

            this.cardsService.Create(inputModel, userId);

            return(this.Redirect("/Cards/All"));
        }
Exemple #22
0
        public HttpResponse Add(CardInputModel input)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (input.Name.Length < 5 || input.Name.Length > 15)
            {
                throw new Exception("Name should be between 5 and 15!");
            }
            if (input.ImageUrl == null)
            {
                throw new Exception("Image url should not be null!");
            }
            if (input.Keyword == null)
            {
                throw new Exception("Keyword should not be null!");
            }
            if (input.Attack < 0)
            {
                throw new Exception("Attack cannot be negative");
            }

            if (input.Health < 0)
            {
                throw new Exception("Health cannot be negative");
            }

            if (input.Description.Length > 200)
            {
                throw new Exception("Description length should be equal or below 200 characters");
            }

            if (input.Description == null)
            {
                throw new Exception("Description cannot be null!");
            }
            this.cardsService.AddCard(input.Name, input.ImageUrl, input.Keyword, input.Attack, input.Health, input.Description);


            return(this.Redirect("/Cards/All"));
        }
Exemple #23
0
        public HttpResponse Add(CardInputModel model)
        {
            if (!this.User.IsAuthenticated)
            {
                return(this.Unauthorized());
            }

            var errors = this.validator.ValidateCard(model);

            if (errors.Any())
            {
                return(this.Error(errors));
            }

            this.cardService
            .Add(model.Name, model.Keyword, model.Image, model.Attack, model.Health, model.Description);

            return(this.Redirect("/"));
        }
        public void Given_A_Valid_YugiohCard_With_An_ImageUrl_Should_Map_To_CardInputModel_ImageUrl_Property()
        {
            // Arrange
            const string expected = "https://vignette.wikia.nocookie.net/yugioh/images/b/b4/BlueEyesWhiteDragon-LED3-EN-C-1E.png/revision/latest/scale-to-width-down/300?cb=20180928161125";

            var yugiohCard = new YugiohCard
            {
                Attribute = "Dark",
                Types     = "Effect/Ritual",
                CardType  = "Monster",
                ImageUrl  = "https://vignette.wikia.nocookie.net/yugioh/images/b/b4/BlueEyesWhiteDragon-LED3-EN-C-1E.png/revision/latest/scale-to-width-down/300?cb=20180928161125"
            };
            var cardInputModel = new CardInputModel();

            // Act
            var result = CardHelper.MapCardImageUrl(yugiohCard, cardInputModel);

            // Assert
            result.ImageUrl.AbsoluteUri.Should().BeEquivalentTo(expected);
        }
        public void Create(CardInputModel inputModel, string userId)
        {
            var card = new Card
            {
                Name        = inputModel.Name,
                ImageUrl    = inputModel.Image,
                Keyword     = inputModel.Keyword,
                Attack      = inputModel.Attack,
                Health      = inputModel.Health,
                Description = inputModel.Description,
            };

            var userCard = new UserCard
            {
                Card   = card,
                UserId = userId,
            };

            this.db.Cards.Add(card);
            this.db.UserCards.Add(userCard);
            this.db.SaveChanges();
        }
        public void Given_A_Valid_YugiohCard_With_A_Name_Should_Map_To_CardInputModel_Name_Property()
        {
            // Arrange
            const string expected = "Darkness Dragon";

            var yugiohCard = new YugiohCard
            {
                Name       = "Darkness Dragon",
                CardNumber = "543534",
                Attribute  = "Dark",
                Types      = "Effect/Ritual",
                CardType   = "Monster",
                ImageUrl   = "https://vignette.wikia.nocookie.net/yugioh/images/b/b4/BlueEyesWhiteDragon-LED3-EN-C-1E.png/revision/latest/scale-to-width-down/300?cb=20180928161125"
            };
            var cardInputModel = new CardInputModel();

            // Act
            var result = CardHelper.MapBasicCardInformation(yugiohCard, cardInputModel);

            // Assert
            result.Name.Should().Be(expected);
        }
Exemple #27
0
        public HttpResponse Add(CardInputModel input)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (input.Name.Length < 5 || input.Name.Length > 15 || string.IsNullOrEmpty(input.Name))
            {
                return(this.View());
            }

            if (string.IsNullOrEmpty(input.ImageUrl) || string.IsNullOrEmpty(input.Keyword))
            {
                return(this.View());
            }

            if (string.IsNullOrEmpty(input.Attack) || int.Parse(input.Attack) < 0)
            {
                return(this.View());
            }

            if (string.IsNullOrEmpty(input.Health) || int.Parse(input.Health) < 0)
            {
                return(this.View());
            }

            if (input.Description.Length > 200 || string.IsNullOrEmpty(input.Description))
            {
                return(this.View());
            }

            this.cardsService.Add(input, this.User);

            return(this.Redirect("/"));
        }
Exemple #28
0
        public void Given_A_Valid_Trap_YugiohCard_With_Types_Should_Map_To_SubCategoryIds_Property()
        {
            // Arrange
            var expected = new List <int> {
                22
            };

            var yugiohCard = new YugiohCard
            {
                Name        = "Call of the Haunted",
                Description = "Amazing card!",
                CardNumber  = "97077563",
                Property    = "Continuous",
                CardType    = "Trap",
                ImageUrl    = "https://vignette.wikia.nocookie.net/yugioh/images/4/47/CalloftheHaunted-YS18-EN-C-1E.png/revision/latest/scale-to-width-down/300?cb=20180712163539"
            };
            var cardInputModel = new CardInputModel();

            // Act
            var result = TrapCardHelper.MapSubCategoryIds(yugiohCard, cardInputModel, TestData.AllCategories(), TestData.AllSubCategories());

            // Assert
            result.SubCategoryIds.Should().BeEquivalentTo(expected);
        }
        public ICollection <string> ValidateCard(CardInputModel model)
        {
            var errors = new List <string>();

            if (string.IsNullOrWhiteSpace(model.Name) || model.Name.Length < CardMinName || model.Name.Length > CardMaxName)
            {
                errors.Add($"Name '{model.Name}' is not valid. It must be between {CardMinName} and {CardMaxName} characters long.");
            }

            if (model.Attack < DefaultMinLength)
            {
                errors.Add($"Attack cannot be negative!");
            }

            if (model.Health < DefaultMinLength)
            {
                errors.Add($"Health cannot be negative!");
            }

            if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > CardMaxDescription)
            {
                errors.Add($"Name '{model.Description}' is not valid. It must be less than {CardMaxDescription} characters long.");
            }

            if (string.IsNullOrWhiteSpace(model.Image))
            {
                errors.Add($"Image is required");
            }

            if (string.IsNullOrWhiteSpace(model.Keyword))
            {
                errors.Add($"Keyword is required");
            }

            return(errors);
        }
        public async Task <IActionResult> CreateCard([FromRoute] Guid organizationId, [FromBody] CardInputModel input)
        {
            var account = await _buyerService.GetBuyerAccount(_customer);

            if (account == null)
            {
                return(BadRequest("buyer account is not setup in stripe"));
            }

            var results = await _cardService.AddCustomerCard(account.Id, input);

            return(Ok(results));
        }