public void WhenGetsANonOkResponseShouldThrowsAnException() { _responseHandler.AddResponse(FIND_ROUTES_URL, new HttpResponseMessage(HttpStatusCode.BadRequest)); _responseHandler.AddResponse(FIND_STOPS_URL, new HttpResponseMessage(HttpStatusCode.BadRequest)); _responseHandler.AddResponse(FIND_DEPARTURES_URL, new HttpResponseMessage(HttpStatusCode.BadRequest)); var client = new HttpClient (_responseHandler); var repository = new RouteRepository (client); Assert.Throws<Exception> (async () => await repository.FindRoutesByStopNameAsync (string.Empty)); Assert.Throws<Exception> (async () => await repository.FindStopsByRouteIdAsync (0)); Assert.Throws<Exception> (async () => await repository.FindDeparturesByRouteIdAsync (0)); }
public async void GivenTwoStopFromServiceThenReturnsTheseStopsWithTheirData() { var responseContent = new StringBuilder () .Append ("{ \"rows\": [") .Append ("{ \"id\": 1, \"name\": \"TICEN\", \"sequence\": 1, \"route_id\": 35 },") .Append ("{ \"id\": 2, \"name\": \"RUA ANTÔNIO PEREIRA OLIVEIRA NETO\", \"sequence\": 2, \"route_id\": 35 }") .Append ("], \"rowsAffected\": 0 }") .ToString (); var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent (responseContent); _responseHandler.AddResponse(FIND_STOPS_URL, response); var client = new HttpClient (_responseHandler); var repository = new RouteRepository (client); var stops = await repository.FindStopsByRouteIdAsync (0); Assert.AreEqual (2, stops.Count); Assert.AreEqual ("TICEN", stops [0].Name); Assert.AreEqual (1, stops [0].Sequence); Assert.AreEqual ("RUA ANTÔNIO PEREIRA OLIVEIRA NETO", stops [1].Name); Assert.AreEqual (2, stops [1].Sequence); }