public void GetVehiclePositionsTest() { VehicleDetails vehicleDetails = new VehicleDetails() { Temperature = 1, Humidity = 1 }; Vehicle vehicle = Services.AddVehicle(vehicleDetails); Assert.IsNotNull(vehicle); VehiclePosDetails vehiclePosDetails = new VehiclePosDetails() { VehicleId = vehicle.Id, Longitude = 50, Latitude = 100 }; VehiclePos vehiclePos1 = PosServices.AddVehiclePosition(vehiclePosDetails); Assert.IsNotNull(vehiclePos1); vehiclePosDetails = new VehiclePosDetails() { VehicleId = vehicle.Id, Longitude = 500, Latitude = 1000 }; VehiclePos vehiclePos2 = PosServices.AddVehiclePosition(vehiclePosDetails); Assert.IsNotNull(vehiclePos2); List <VehiclePos> vehiclePositions = PosServices.GetVehiclePositions(vehicle.Id); Assert.IsNotNull(vehiclePositions); Assert.IsTrue(vehiclePositions.Contains(vehiclePos1)); Assert.IsTrue(vehiclePositions.Contains(vehiclePos2)); }
public void UpdateVehiclePositionTest() { VehicleDetails vehicleDetails = new VehicleDetails() { Temperature = 1, Humidity = 1 }; Vehicle vehicle = Services.AddVehicle(vehicleDetails); Assert.IsNotNull(vehicle); VehiclePosDetails vehiclePosDetails = new VehiclePosDetails() { VehicleId = vehicle.Id, Longitude = 50, Latitude = 100 }; VehiclePos vehiclePosAdded = PosServices.AddVehiclePosition(vehiclePosDetails); Assert.IsNotNull(vehiclePosAdded); vehiclePosDetails = new VehiclePosDetails() { VehicleId = vehicle.Id, Longitude = 500, Latitude = 1000 }; VehiclePos vehiclePosUpdated = PosServices.AddVehiclePosition(vehiclePosDetails); Assert.IsNotNull(vehiclePosUpdated); Assert.AreEqual(vehiclePosUpdated.Id, vehicle.Id); Assert.AreEqual(vehiclePosUpdated.Longitude, 500); Assert.AreEqual(vehiclePosUpdated.Latitude, 1000); }
public void DeleteVehiclePositionTest() { VehicleDetails vehicleDetails = new VehicleDetails() { Temperature = 1, Humidity = 1 }; Vehicle vehicle = Services.AddVehicle(vehicleDetails); Assert.IsNotNull(vehicle); VehiclePosDetails vehiclePosDetails = new VehiclePosDetails() { VehicleId = vehicle.Id, Longitude = 50, Latitude = 100 }; VehiclePos vehiclePosAdded = PosServices.AddVehiclePosition(vehiclePosDetails); Assert.IsNotNull(vehiclePosAdded); int deletedVehiclePosId = PosServices.DeleteVehiclePosition(vehiclePosAdded.Id); Assert.AreEqual(deletedVehiclePosId, vehiclePosAdded.Id); VehiclePos vehiclePos = PosServices.GetVehiclePosition(vehiclePosAdded.Id); Assert.IsNull(vehiclePos); }
public void createVehiclePosDetailsTest() { VehiclePosDetails vehiclePosDetails = new VehiclePosDetails() { Longitude = 7, Latitude = 9 }; Assert.AreEqual(vehiclePosDetails.Longitude, 7); Assert.AreEqual(vehiclePosDetails.Latitude, 9); }
public ActionResult <VehiclePos> UpdateVehiclePos(int id, VehiclePosDetails updateVehicle) { var vehicleToUpdate = vehiclePosServices.GetVehiclePosition(id); if (vehicleToUpdate == null) { return(NotFound($"Vehicle with id {id} was not found.")); } var updatedVehicle = vehiclePosServices.UpdateVehiclePosition(updateVehicle, id); return(Ok(updatedVehicle)); }
public VehiclePos UpdateVehiclePosition(VehiclePosDetails vehiclePosDetails, int id) { VehiclePos vehiclePos = dbContext.VehiclePositions.Find(id); if (vehiclePos != null) { vehiclePos.VehicleId = vehiclePosDetails.VehicleId; vehiclePos.Longitude = vehiclePosDetails.Longitude; vehiclePos.Latitude = vehiclePosDetails.Latitude; vehiclePos.Time = DateTime.Now; } dbContext.SaveChanges(); return(vehiclePos); }
public VehiclePos AddVehiclePosition(VehiclePosDetails vehiclePosDetails) { VehiclePos vehiclePos = new VehiclePos() { VehicleId = vehiclePosDetails.VehicleId, Longitude = vehiclePosDetails.Longitude, Latitude = vehiclePosDetails.Latitude, Time = DateTime.Now }; VehiclePos addedVehiclePos = dbContext.VehiclePositions.Add(vehiclePos).Entity; dbContext.SaveChanges(); return(addedVehiclePos); }
public void UpdateVehiclePositionTest2() { VehicleDetails vehicleDetails = new VehicleDetails() { Temperature = 1, Humidity = 1 }; Vehicle vehicle = Services.AddVehicle(vehicleDetails); Assert.IsNotNull(vehicle); VehiclePosDetails vehiclePosDetails = new VehiclePosDetails() { VehicleId = vehicle.Id, Longitude = 50, Latitude = 100 }; VehiclePos vehiclePos = PosServices.UpdateVehiclePosition(vehiclePosDetails, -1); Assert.IsNull(vehiclePos); }
public VehiclePosControllerTest() { addVehicle = new Mock <VehiclePosDetails>(); _addVehicle = new VehiclePosDetails() { Longitude = 20, Latitude = 15 }; vehicle = new Mock <VehiclePosDetails>(); vehicles = new List <VehiclePosDetails> { vehicle.Object }; updateVehicle = new Mock <VehiclePosDetails>(); _updateVehicle = new VehiclePosDetails() { Longitude = 30, Latitude = 40 }; vehicleService = new Mock <VehiclePosServices>(); }
public ActionResult <VehiclePos> AddVehiclePos([FromBody] VehiclePosDetails addVehicle) { var createdVehicle = vehiclePosServices.AddVehiclePosition(addVehicle); return(Ok(createdVehicle)); }