public async Task EndRideAsync() { var endRide = new EndRideDto { Charge = Charge.Value }; await PostToServiceAsync($"/api/rides/{SelectedOngoingRide.ID}", endRide); await RefreshRidesAsync(); }
public async Task EndRideInvalidID() { var startRide = new EndRideDto { Charge = 0m }; var body = new StringContent(JsonConvert.SerializeObject(startRide), Encoding.UTF8, "application/json"); var response = await Client.PostAsync($"/api/rides/{Int32.MaxValue}", body); Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); }
public async Task EndRide() { const decimal charge = 99m; var(_, _, rideID) = await DbContext.AddDummyRideAsync(); var endRide = new EndRideDto { Charge = charge }; var body = new StringContent(JsonConvert.SerializeObject(endRide), Encoding.UTF8, "application/json"); var response = await Client.PostAsync($"/api/rides/{rideID}", body); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); var newRide = JsonConvert.DeserializeObject <TaxiRide>(await response.Content.ReadAsStringAsync()); Assert.AreEqual(charge, newRide.Charge); Assert.IsTrue(newRide.End <= DateTime.Now && newRide.End >= DateTime.Now.AddSeconds(-5)); }
public async Task <IActionResult> EndRide(int id, [FromBody] EndRideDto charge) { if (charge == null) { return(BadRequest("Missing body")); } var ride = await DbContext.Rides.FirstOrDefaultAsync(t => t.ID == id); if (ride == null) { return(NotFound("Ride with specified ID not found")); } await DbContext.EndRideAsync(id, charge.Charge); ride = await DbContext.Rides.FirstOrDefaultAsync(t => t.ID == id); return(Ok(ride)); }
public Task <IActionResult> EndRide(int id, [FromBody] EndRideDto charge) { throw new NotImplementedException(); }