public void Given_A_Valid_A_Link_Monster_YugiohCard_With_Types_Should_Map_To_SubCategoryIds_Property() { // Arrange var expected = new List <int> { 2, 14 }; 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", 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 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.MonsterSubCategoryIds(yugiohCard, monsterSubCategories); // Assert result.Should().BeEquivalentTo(expected); }
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); }
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); }
private async Task <CardInputModel> MapToCardInputModel(YugiohCard yugiohCard, CardInputModel cardInputModel, ICollection <Category> categories, ICollection <SubCategory> subCategories) { CardHelper.MapBasicCardInformation(yugiohCard, cardInputModel); CardHelper.MapCardImageUrl(yugiohCard, cardInputModel); if (cardInputModel.CardType.Equals(YgoCardType.Spell)) { SpellCardHelper.MapSubCategoryIds(yugiohCard, cardInputModel, categories, subCategories); } else if (cardInputModel.CardType.Equals(YgoCardType.Trap)) { TrapCardHelper.MapSubCategoryIds(yugiohCard, cardInputModel, categories, subCategories); } else { ICollection <Type> types = await _typeService.AllTypes(); ICollection <Attribute> attributes = await _attributeService.AllAttributes(); ICollection <LinkArrow> linkArrows = await _linkArrowService.AllLinkArrows(); var monsterCategory = categories.Single(c => c.Name.Equals(YgoCardType.Monster.ToString(), StringComparison.OrdinalIgnoreCase)); var monsterSubCategories = subCategories.Select(sc => sc).Where(sc => sc.CategoryId == monsterCategory.Id); MonsterCardHelper.MapMonsterCard(yugiohCard, cardInputModel, attributes, monsterSubCategories, types, linkArrows); } return(cardInputModel); }
public void Given_A_Valid_Monster_Type_YugiohCard_Should_Return_AddCommand() { // Arrange var yugiohCard = new YugiohCard { Name = "Darkness Dragon", Description = "Amazing card!", CardNumber = "543534", Attribute = "Dark", Types = "Effect/Ritual/Dragon", CardType = "Monster", Rank = 3, AtkLink = "2300 / 3", 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 cardToUpdate = new Card { Id = 23424 }; // Act var result = _sut.MapToUpdateCommand(yugiohCard, cardToUpdate); // Assert result.Should().NotBeNull(); }
public void Given_A_Valid_A_Link_Monster_YugiohCard_With_Types_Should_Map_To_TypeIds_Property() { // Arrange var expected = new List <int> { 5 }; 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", 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" }; // Act var result = MonsterCardHelper.MonsterTypeIds(yugiohCard, TestData.AllTypes()); // Assert result.Should().BeEquivalentTo(expected); }
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(); }
private static List <int> MonsterSubCategoryIds(YugiohCard yugiohCard, IEnumerable <SubCategory> monsterSubCategories) { return(monsterSubCategories .Where(msb => yugiohCard.MonsterSubCategoriesAndTypes.Any(ysc => ysc.Equals(msb.Name, StringComparison.OrdinalIgnoreCase))) .Select(ssc => (int)ssc.Id) .ToList()); }
private static List <int> MonsterLinkArrowIds(YugiohCard yugiohCard, ICollection <LinkArrow> linkArrows) { return(linkArrows .Where(mla => yugiohCard.MonsterLinkArrows.Any(ymla => ymla.Equals(mla.Name, StringComparison.OrdinalIgnoreCase))) .Select(la => (int)la.Id) .ToList()); }
private static List <int> MonsterTypeIds(YugiohCard yugiohCard, ICollection <Type> types) { return(types .Where(mt => yugiohCard.MonsterSubCategoriesAndTypes.Any(yt => yt.Equals(mt.Name, StringComparison.OrdinalIgnoreCase))) .Select(smt => (int)smt.Id) .ToList()); }
public async Task <Card> AddOrUpdate(YugiohCard yugiohCard) { var card = await _cardService.CardByName(yugiohCard.Name); return(card == null ? await _cardService.Add(await _commandMapper.MapToAddCommand(yugiohCard)) : await _cardService.Update(await _commandMapper.MapToUpdateCommand(yugiohCard, card))); }
public static CardInputModel MapCardImageUrl(YugiohCard yugiohCard, CardInputModel cardInputModel) { if (yugiohCard.ImageUrl != null) { cardInputModel.ImageUrl = new Uri(yugiohCard.ImageUrl); } return(cardInputModel); }
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); }
private static int MonsterAttributeId(YugiohCard yugiohCard, ICollection <Attribute> attributes) { return (( from a in attributes where a.Name.Equals(yugiohCard.Attribute, StringComparison.OrdinalIgnoreCase) select a.Id ) .Single()); }
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 async Task <UpdateCardCommand> MapToUpdateCommand(YugiohCard yugiohCard, Card cardToUpdate) { ICollection <Category> categories = await _categoryService.AllCategories(); ICollection <SubCategory> subCategories = await _subCategoryService.AllSubCategories(); var command = new UpdateCardCommand { Card = await MapToCardInputModel(yugiohCard, new CardInputModel(), categories, subCategories, cardToUpdate) }; return(command); }
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); }
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 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 void Given_A_Valid_Trap_Type_YugiohCard_Should_Return_AddCommand() { // Arrange 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" }; // Act var result = _sut.MapToAddCommand(yugiohCard); // Assert result.Should().NotBeNull(); }
public void Given_A_Valid_Spell_Type_YugiohCard_Should_Return_AddCommand() { // Arrange 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" }; // Act var result = _sut.MapToAddCommand(yugiohCard); // Assert result.Should().NotBeNull(); }
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 YugiohCard GetYugiohCard(HtmlDocument htmlDocument) { var yugiohCard = new YugiohCard(); yugiohCard.ImageUrl = _cardHtmlDocument.ImageUrl(htmlDocument); yugiohCard.Name = _cardHtmlDocument.Name(htmlDocument); yugiohCard.Description = _cardHtmlDocument.Description(htmlDocument); yugiohCard.CardNumber = _cardHtmlDocument.CardNumber(htmlDocument); yugiohCard.CardType = _cardHtmlDocument.CardType(htmlDocument); yugiohCard.Property = _cardHtmlDocument.Property(htmlDocument); yugiohCard.Attribute = _cardHtmlDocument.Attribute(htmlDocument); yugiohCard.Level = _cardHtmlDocument.Level(htmlDocument); yugiohCard.Rank = _cardHtmlDocument.Rank(htmlDocument); yugiohCard.AtkDef = _cardHtmlDocument.AtkDef(htmlDocument); yugiohCard.AtkLink = _cardHtmlDocument.AtkLink(htmlDocument); yugiohCard.Types = _cardHtmlDocument.Types(htmlDocument); yugiohCard.Materials = _cardHtmlDocument.Materials(htmlDocument); yugiohCard.CardEffectTypes = _cardHtmlDocument.CardEffectTypes(htmlDocument); yugiohCard.PendulumScale = _cardHtmlDocument.PendulumScale(htmlDocument); return(yugiohCard); }
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); }
public void Given_A_Valid_A_Monster_YugiohCard_With_An_Atk_Should_Extract_Atk_Value() { // Arrange const string expected = "2300"; 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" }; // Act var result = MonsterCardHelper.Atk(yugiohCard); // Assert result.Should().Be(expected); }
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 async Task <AddCardCommand> MapToAddCommand(YugiohCard yugiohCard) { ICollection <Category> categories = await _categoryService.GetAll(); ICollection <SubCategory> subCategories = await _subCategoryService.GetAll(); var command = new AddCardCommand(); command.CardType = yugiohCard.CardType; command.CardNumber = yugiohCard.CardNumber; command.Name = yugiohCard.Name; command.Description = yugiohCard.Description; if (yugiohCard.ImageUrl != null) { command.ImageUrl = new Uri(yugiohCard.ImageUrl); } if (command.CardType.Equals(YgoCardType.Spell.ToString(), StringComparison.OrdinalIgnoreCase)) { command.SubCategoryIds = new List <int> { SubCategoryId(categories, subCategories, YgoCardType.Spell, yugiohCard.Property) }; } else if (command.CardType.Equals(YgoCardType.Trap.ToString(), StringComparison.OrdinalIgnoreCase)) { command.SubCategoryIds = new List <int> { SubCategoryId(categories, subCategories, YgoCardType.Trap, yugiohCard.Property) }; } else { ICollection <Type> types = await _typeService.GetAll(); ICollection <Attribute> attributes = await _attributeService.GetAll(); ICollection <LinkArrow> linkArrows = await _linkArrowService.GetAll(); var monsterCategory = categories.Single(c => c.Name.Equals(YgoCardType.Monster.ToString(), StringComparison.OrdinalIgnoreCase)); var monsterSubCategories = subCategories.Select(sc => sc).Where(sc => sc.CategoryId == monsterCategory.Id); command.AttributeId = MonsterAttributeId(yugiohCard, attributes); command.SubCategoryIds = MonsterSubCategoryIds(yugiohCard, monsterSubCategories); command.TypeIds = MonsterTypeIds(yugiohCard, types); if (yugiohCard.LinkArrows != null) { command.LinkArrowIds = MonsterLinkArrowIds(yugiohCard, linkArrows); } if (yugiohCard.Level.HasValue) { command.CardLevel = yugiohCard.Level; } if (yugiohCard.Rank.HasValue) { command.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); command.Atk = cardAtk; command.Def = cardDef; } if (!string.IsNullOrWhiteSpace(yugiohCard.AtkLink)) { var atk = Atk(yugiohCard); int.TryParse(atk, out var cardAtk); command.Atk = cardAtk; } } return(command); }
private static string DefOrLink(YugiohCard yugiohCard) { return(yugiohCard.AtkDef?.Split('/').Last()); }
private static string Atk(YugiohCard yugiohCard) { return(yugiohCard.AtkDef?.Split('/').First()); }
private async Task <CardInputModel> MapToCardInputModel(YugiohCard yugiohCard, CardInputModel cardInputModel, ICollection <Category> categories, ICollection <SubCategory> subCategories, Card cardToUpdate) { cardInputModel.Id = cardToUpdate.Id; return(await MapToCardInputModel(yugiohCard, cardInputModel, categories, subCategories)); }