public void ShouldReturnExceptionWhenErrorOcurrs() { //Arrage IEnumerable <StarShip> starShip = new List <StarShip>(); AllStarShipsResponse result = new AllStarShipsResponse() { next = "", Result = starShip }; _starWarsRepositoryHelper.Setup(x => x.GetAllStarShipsAsync("1")).Throws(new Exception()); StarWarsRepository repository = new StarWarsRepository(_starWarsRepositoryHelper.Object); //Act AsyncTestDelegate act = () => repository.GetAllStarShips(); //Assert Assert.That(act, Throws.TypeOf <Exception>()); }
public async Task ShouldReturnStarShipListObject() { //Arrage IEnumerable <StarShip> starShip = new List <StarShip>(); AllStarShipsResponse result = new AllStarShipsResponse() { next = "", Result = starShip }; _starWarsRepositoryHelper.Setup(x => x.GetAllStarShipsAsync("1")).Returns(Task.FromResult(result)); StarWarsRepository repository = new StarWarsRepository(_starWarsRepositoryHelper.Object); //Act var starShips = await repository.GetAllStarShips(); //Assert Assert.IsInstanceOf <IEnumerable <StarShip> >(starShips); }
/// <summary> /// Method in char of retreive data from SWAPI /// </summary> /// <returns0>List of StarShips</returns> public async Task <IEnumerable <StarShip> > GetAllStarShips() { List <StarShip> result; int pageNumber = 1; try { string next = ""; result = new List <StarShip>(); do { AllStarShipsResponse allStarShipsResponse = await _starWarsRepositoryHelper.GetAllStarShipsAsync(pageNumber.ToString()); result.AddRange(allStarShipsResponse.Result); next = allStarShipsResponse.next; pageNumber++; } while (!string.IsNullOrEmpty(next)); } catch (Exception ex) { throw ex; } return(result); }