public async Task <BatteryResponse> UpdateAsync(int id, Battery battery) { var existingBattery = await _batteryRepository.FindByIdAsync(id); Console.WriteLine(battery); Console.WriteLine(id); Console.WriteLine("^--Battery Update Async"); Console.WriteLine(); if (existingBattery == null) { return(new BatteryResponse("Battery not found.")); } existingBattery.id = battery.id; existingBattery.status = battery.status; try { _batteryRepository.Update(existingBattery); return(new BatteryResponse(existingBattery)); } catch (Exception ex) { // Do some logging stuff return(new BatteryResponse($"An error occurred when updating the battery: {ex.Message}")); } }
public void Repository_UpdateExisting() { var battery = _repository.GetAll().First(); var batteryId = battery.Id; var notesText = "Updated notes - integration testing"; battery.Notes = notesText; battery.IsActive = false; var result = _repository.Update(battery); Assert.True(result.Id == batteryId); Assert.True(result.Notes == notesText); Assert.True(!result.IsActive); }