public async Task FindAsync_Success() { // arrange const string SET_NAME = "setname1"; _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 setDto = new SetDto() { Name = SET_NAME }; var rootSetList = new RootSetDto() { Set = setDto, }; _mockModelMapper.Setup(x => x.MapSet(It.IsAny <SetDto>())).Returns(new Set() { Name = SET_NAME }); using var httpTest = new HttpTest(); httpTest.RespondWithJson(rootSetList); var service = new SetService( _mockHeaderManager.Object, _mockModelMapper.Object, ApiVersion.V1, _mockRateLimit.Object); // act var result = await service.FindAsync("12345"); // assert Assert.True(result.IsSuccess); _mockRepository.VerifyAll(); }
public async Task FindAsyncTest() { var setDto = new SetDto() { Block = "block1", Booster = new object[2] { new JValue("booster1"), new JArray() { new JValue("booster2"), new JValue("booster3"), new JArray() { new JValue("booster4"), new JValue("booster5") } } }, Border = "border1", Code = "code1", Expansion = "expansion1", GathererCode = "gathererCode1", MagicCardsInfoCode = "magicCardsInfoCode1", Name = "name1", OldCode = "oldCode1", OnlineOnly = true, ReleaseDate = "2016, 1, 1" }; // Test the FindAsync method. var moqAdapter = new Mock <IMtgApiServiceAdapter>(); moqAdapter .SetupSequence(x => x.WebGetAsync <RootSetDto>(It.IsAny <Uri>())) .Throws <ArgumentNullException>() .Throws(new MtgApiException <BadRequestException>("bad request")) .Throws(new MtgApiException <ForbiddenException>("forbidden")) .Throws(new MtgApiException <InternalServerErrorException>("server error")) .Throws(new MtgApiException <NotFoundException>("not found")) .Throws(new MtgApiException <ServiceUnavailableException>("unavailable")) .Throws <Exception>() .ReturnsAsync(new RootSetDto() { Set = setDto }); var service = new SetService(moqAdapter.Object, ApiVersion.V1_0, false); var result = await service.FindAsync("code1"); Assert.False(result.IsSuccess); Assert.Equal("Value cannot be null.", result.Exception.Message); result = await service.FindAsync("code1"); Assert.False(result.IsSuccess); Assert.Equal("bad request", result.Exception.Message); result = await service.FindAsync("code1"); Assert.False(result.IsSuccess); Assert.Equal("forbidden", result.Exception.Message); result = await service.FindAsync("code1"); Assert.False(result.IsSuccess); Assert.Equal("server error", result.Exception.Message); result = await service.FindAsync("code1"); Assert.False(result.IsSuccess); Assert.Equal("not found", result.Exception.Message); result = await service.FindAsync("code1"); Assert.False(result.IsSuccess); Assert.Equal("unavailable", result.Exception.Message); result = await service.FindAsync("code1"); Assert.False(result.IsSuccess); Assert.IsType <Exception>(result.Exception); result = await service.FindAsync("code1"); Assert.True(result.IsSuccess); Assert.Null(result.Exception); Assert.NotNull(result.Value); }