public PagedResult <CustomerBetVM> CustomerBets(BetTableSortBy sortBy, bool isAscending) { var service = new CustomerBetService(new HttpClient()); var customers = service.GetCustomers(); var bets = service.GetBets(); var result = customers .Join(bets, cust => cust.Id, bet => bet.CustomerId, (cust, bet) => new CustomerBetVM() { CustomerName = cust.Name, RaceNumber = bet.RaceId, ReturnStake = bet.ReturnStake, Won = bet.Won }) .OrderBy(sortBy.ToString(), isAscending).ToList(); return(new PagedResult <CustomerBetVM> { Data = result, TotalCount = result.Count() }); }
public void WhenGettingAllBetsTheyShouldBeReturned() { // Arrange var bets = new[] { new Bet { CustomerId = 1, RaceId = 1, HorseId = 2, ReturnStake = 100.0m, Won = true }, new Bet { CustomerId = 2, RaceId = 1, HorseId = 5, ReturnStake = 200.0m, Won = false }, new Bet { CustomerId = 3, RaceId = 1, HorseId = 3, ReturnStake = 400.0m, Won = true }, new Bet { CustomerId = 4, RaceId = 1, HorseId = 2, ReturnStake = 100.0m, Won = false }, new Bet { CustomerId = 5, RaceId = 1, HorseId = 1, ReturnStake = 500.0m, Won = false }, new Bet { CustomerId = 6, RaceId = 1, HorseId = 5, ReturnStake = 2100.0m, Won = true }, new Bet { CustomerId = 7, RaceId = 1, HorseId = 2, ReturnStake = 100.0m, Won = false }, }; var fakehandler = new TestDelegatingHandler <Bet[]>(bets); var fakeServer = new HttpServer(new HttpConfiguration(), fakehandler); var service = new CustomerBetService(new HttpClient(fakeServer)); // Act var result = service.GetBets(); // Assert Assert.AreEqual(7, result.Count); }