public async Task GetTransferTargetsCallsGetHandlerAndReturnsListOfBidViewModelAsync() { //Arrange var accessToken = "ABC"; var initial = new List <BidViewModel> { new BidViewModel { Status = "Pending", BidPrice = 1300, Pending = true, TimeRemaining = 123, TradeId = "123" }, new BidViewModel { Status = "Pending", BidPrice = 1300, Pending = true, TimeRemaining = -1, TradeId = "123" } }; var expected = new List <BidViewModel> { new BidViewModel { Status = "Pending", BidPrice = 1300, Pending = true, TimeRemaining = 123, TradeId = "123" }, new BidViewModel { Status = "Pending", BidPrice = 1300, Pending = false, TimeRemaining = -1, TradeId = "123" } }; A.CallTo(() => _getRequestHandler.GetTransferTargets(accessToken)) .Returns(initial); A.CallTo(() => _modelBuilder.PopulateDefaultFieldsOfBidViews(initial)) .Returns(expected); //Act var actual = await _ApiGateway.GetTransferTargets(accessToken); //Assert A.CallTo(() => _getRequestHandler.GetTransferTargets(accessToken)).MustHaveHappenedOnceExactly(); A.CallTo(() => _modelBuilder.PopulateDefaultFieldsOfBidViews(initial)).MustHaveHappenedOnceExactly(); actual.Should().BeEquivalentTo(expected); }
public async Task <List <BidViewModel> > GetTransferTargets(string accessToken) { try { var targetsList = await _getRequestHandler.GetTransferTargets(accessToken); if (targetsList.Count == 0) { throw new Exception(); } var players = _modelBuilder.PopulateDefaultFieldsOfBidViews(targetsList); return(players); } catch (Exception) { return(new List <BidViewModel> { new BidViewModel { Status = "Expired", Pending = false, } }); } }
public async Task GetTransferTargetsGetsUrlMakesRequestThenReturnsListBidViewModel() { //Arrange var accessToken = "ABC"; var expectedPlayers = new List <BidViewModel> { new BidViewModel { Status = "Pending", BidPrice = 1400, Pending = true, TimeRemaining = 123, TradeId = "12234" } }; var expected = new auctionSearchModel { AuctionInfo = expectedPlayers }; A.CallTo(() => _urlBuilder.GetTransferTargetsUrl()).Returns("TargetsUrl"); A.CallTo(() => _getRequestMaker.MakeGetRequest("TargetsUrl", accessToken)) .Returns(JsonConvert.SerializeObject(expected)); //Act var actual = await _getRequestHandler.GetTransferTargets(accessToken); //Assert actual.Should().BeEquivalentTo(expectedPlayers); A.CallTo(() => _getRequestMaker.MakeGetRequest("TargetsUrl", accessToken)).MustHaveHappenedOnceExactly(); }