Skip to content

Commit

Permalink
Merge pull request #69 from billybimbob/master
Browse files Browse the repository at this point in the history
Add id and multiverseid query parameters
  • Loading branch information
jregnier authored Nov 13, 2021
2 parents ddbb846 + c91fb70 commit 23b4ae0
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 3 deletions.
103 changes: 100 additions & 3 deletions src/MtgApiManager.Lib.Test/Service/CardServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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<IReadOnlyNameValueList<string>>()));
_mockHeaderManager.Setup(x => x.Get<int>(ResponseHeader.TotalCount)).Returns(2000);
_mockHeaderManager.Setup(x => x.Get<int>(ResponseHeader.PageSize)).Returns(1000);

var rootCardList = new RootCardListDto()
{
Cards = new List<CardDto> { new CardDto() },
};

using var httpTest = new HttpTest();
httpTest.RespondWithJson(rootCardList);

_mockModelMapper.Setup(x => x.MapCard(It.IsAny<CardDto>())).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<IReadOnlyNameValueList<string>>()));
_mockHeaderManager.Setup(x => x.Get<int>(ResponseHeader.TotalCount)).Returns(2000);
_mockHeaderManager.Setup(x => x.Get<int>(ResponseHeader.PageSize)).Returns(1000);

var rootCardList = new RootCardListDto()
{
Cards = new List<CardDto> { new CardDto() },
};

using var httpTest = new HttpTest();
httpTest.RespondWithJson(rootCardList);

_mockModelMapper.Setup(x => x.MapCard(It.IsAny<CardDto>())).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()
{
Expand Down Expand Up @@ -564,5 +645,21 @@ public void Where_NullProperty_Throws()
// assert
Assert.Throws<ArgumentNullException>(() => 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);
}
}
}
12 changes: 12 additions & 0 deletions src/MtgApiManager.Lib/Service/CardQueryParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public class CardQueryParameter : IQueryParameter
[JsonPropertyName("gameFormat")]
public string GameFormat { get; set; }

/// <summary>
/// Gets or sets the identifier of the card.
/// </summary>
[JsonPropertyName("id")]
public string Id { get; set; }

/// <summary>
/// Gets or sets the language the card is printed in. Use this parameter when searching by foreignName.
/// </summary>
Expand All @@ -73,6 +79,12 @@ public class CardQueryParameter : IQueryParameter
[JsonPropertyName("loyalty")]
public string Loyalty { get; set; }

/// <summary>
/// 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’.
/// </summary>
[JsonPropertyName("multiverseid")]
public string MultiverseId { get; set; }

/// <summary>
/// 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.
/// </summary>
Expand Down

0 comments on commit 23b4ae0

Please sign in to comment.