From c91fb70a05b7f0a1cfeef1b7c8bcfba38b8f2f17 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 11 Nov 2021 18:41:43 -0600 Subject: [PATCH] add id and multiverseid query parameters --- .../Service/CardServiceTests.cs | 103 +++++++++++++++++- .../Service/CardQueryParameter.cs | 12 ++ 2 files changed, 112 insertions(+), 3 deletions(-) diff --git a/src/MtgApiManager.Lib.Test/Service/CardServiceTests.cs b/src/MtgApiManager.Lib.Test/Service/CardServiceTests.cs index 09c0ff0..3df71d7 100644 --- a/src/MtgApiManager.Lib.Test/Service/CardServiceTests.cs +++ b/src/MtgApiManager.Lib.Test/Service/CardServiceTests.cs @@ -119,16 +119,16 @@ public async Task AllAsync_Success() [Fact] public async Task AllAsync_NoMock_EqualPageSize() { - const int pageSize = 50; + const int PAGE_SIZE = 50; var serviceProvider = new MtgServiceProvider(); var service = serviceProvider.GetCardService(); var result = await service .Where(x => x.Page, 1) - .Where(x => x.PageSize, pageSize) + .Where(x => x.PageSize, PAGE_SIZE) .AllAsync(); - Assert.Equal(pageSize, result.PagingInfo.PageSize); + Assert.Equal(PAGE_SIZE, result.PagingInfo.PageSize); } [Fact] @@ -535,6 +535,87 @@ public async Task Where_AddsQueryParameters_Success() .WithQueryParams("name", "language"); } + + [Fact] + public async Task Where_AddsIdParameter_Success() + { + const string MULTIPLE_IDS = + "896a92b1-ed29-5daf-bf89-2502224f8f11|516dd7a4-fad8-5eed-bcdb-c05088762303"; + + const string ID_PARAM = "id"; + + _mockRateLimit.Setup(x => x.IsTurnedOn).Returns(false); + + _mockHeaderManager.Setup(x => x.Update(It.IsAny>())); + _mockHeaderManager.Setup(x => x.Get(ResponseHeader.TotalCount)).Returns(2000); + _mockHeaderManager.Setup(x => x.Get(ResponseHeader.PageSize)).Returns(1000); + + var rootCardList = new RootCardListDto() + { + Cards = new List { new CardDto() }, + }; + + using var httpTest = new HttpTest(); + httpTest.RespondWithJson(rootCardList); + + _mockModelMapper.Setup(x => x.MapCard(It.IsAny())).Returns(new Card()); + + var service = new CardService( + _mockHeaderManager.Object, + _mockModelMapper.Object, + ApiVersion.V1, + _mockRateLimit.Object); + + // act + await service + .Where(x => x.Id, MULTIPLE_IDS) + .AllAsync(); + + // assert + httpTest + .ShouldHaveCalled("https://api.magicthegathering.io/v1/cards*") + .WithQueryParams(ID_PARAM); + } + + [Fact] + public async Task Where_AddMultiverseIdParameter_Success() + { + const string MULTIPLE_MULTIS = "3|4"; + const string MULTI_PARAM = "multiverseid"; + + _mockRateLimit.Setup(x => x.IsTurnedOn).Returns(false); + + _mockHeaderManager.Setup(x => x.Update(It.IsAny>())); + _mockHeaderManager.Setup(x => x.Get(ResponseHeader.TotalCount)).Returns(2000); + _mockHeaderManager.Setup(x => x.Get(ResponseHeader.PageSize)).Returns(1000); + + var rootCardList = new RootCardListDto() + { + Cards = new List { new CardDto() }, + }; + + using var httpTest = new HttpTest(); + httpTest.RespondWithJson(rootCardList); + + _mockModelMapper.Setup(x => x.MapCard(It.IsAny())).Returns(new Card()); + + var service = new CardService( + _mockHeaderManager.Object, + _mockModelMapper.Object, + ApiVersion.V1, + _mockRateLimit.Object); + + // act + await service + .Where(x => x.MultiverseId, MULTIPLE_MULTIS) + .AllAsync(); + + // assert + httpTest + .ShouldHaveCalled("https://api.magicthegathering.io/v1/cards*") + .WithQueryParams(MULTI_PARAM); + } + [Fact] public void Where_DefaultValue_Throws() { @@ -564,5 +645,21 @@ public void Where_NullProperty_Throws() // assert Assert.Throws(() => service.Where(_ => null, NAME)); } + + [Fact] + public async Task Where_AddMultiverseIdNoMock_Success() + { + const string MULTIPLE_MULTIS = "3|4|5|6"; + + var serviceProvider = new MtgServiceProvider(); + var service = serviceProvider.GetCardService(); + + var result = await service + .Where(x => x.MultiverseId, MULTIPLE_MULTIS) + .AllAsync(); + + Assert.True(result.IsSuccess); + Assert.Equal(4, result.Value.Count); + } } } \ No newline at end of file diff --git a/src/MtgApiManager.Lib/Service/CardQueryParameter.cs b/src/MtgApiManager.Lib/Service/CardQueryParameter.cs index aebde7c..c186af3 100644 --- a/src/MtgApiManager.Lib/Service/CardQueryParameter.cs +++ b/src/MtgApiManager.Lib/Service/CardQueryParameter.cs @@ -49,6 +49,12 @@ public class CardQueryParameter : IQueryParameter [JsonPropertyName("gameFormat")] public string GameFormat { get; set; } + /// + /// Gets or sets the identifier of the card. + /// + [JsonPropertyName("id")] + public string Id { get; set; } + /// /// Gets or sets the language the card is printed in. Use this parameter when searching by foreignName. /// @@ -73,6 +79,12 @@ public class CardQueryParameter : IQueryParameter [JsonPropertyName("loyalty")] public string Loyalty { get; set; } + /// + /// Gets the multiverse identifier of the card on Wizard’s Gatherer web page. Cards from sets that do not exist on Gatherer will NOT have a multiverse identifier. Sets not on Gatherer are: ATH, ITP, DKM, RQS, DPA and all sets with a 4 letter code that starts with a lowercase 'p’. + /// + [JsonPropertyName("multiverseid")] + public string MultiverseId { get; set; } + /// /// Gets or sets the card name. For split, double-faced and flip cards, just the name of one side of the card. Basically each ‘sub-card’ has its own record. ///