public async Task GetVehicleAsync_WithVehicleIdExists_ReturnVehicleResponse() { // Arrange var vehicleId = 1; var vehicle = new Vehicle { Id = Guid.NewGuid(), VehicleId = 1, Number = "A-001", Model = "Honda City", Description = "Blue Color" }; vehiclesRepository .GetVehicleByVehicleIdAsync(Arg.Any <int>()) .Returns(Task.FromResult(vehicle)); // Act var response = await vehiclesService.GetVehicleAsync(vehicleId); // Assert Assert.NotNull(response); Assert.IsType <VehicleResponse>(response); Assert.Equal(1, response.VehicleId); Assert.Equal("A-001", response.Number); Assert.Equal("Honda City", response.Model); Assert.Equal("Blue Color", response.Description); }
public async Task <VehicleResponse> GetVehicleAsync(int vehicleId) { var vehicle = await vehiclesRepository.GetVehicleByVehicleIdAsync(vehicleId); if (vehicle == null) { return(null); } return(MapVehicleResponse(vehicle)); }
public async Task <LocationResponse> AddLocationAsync(LocationRequest request) { var vehicle = await vehiclesRepository.GetVehicleByVehicleIdAsync(request.VehicleId); if (vehicle == null) { return(null); } var location = new Location { VehicleId = vehicle.VehicleId, Latitude = request.Latitude, Longitude = request.Longitude, UpdateDate = DateTime.UtcNow }; await locationsRepository.AddLocationAsync(location); return(MapLocationResponse(location)); }
public async Task AddLocationAsync_WithLocationRequest_ReturnLocationResponse() { var locationRequest = new LocationRequest { VehicleId = 1, Latitude = 13.788571, Longitude = 100.538034 }; var vehicle = new Vehicle { Id = Guid.NewGuid(), VehicleId = 1, Number = "A-001", Model = "Honda City", Description = "Blue Color" }; var location = new Location { Id = Guid.NewGuid(), VehicleId = 1, Latitude = 13.788571, Longitude = 100.538034, UpdateDate = new DateTime(2020, 3, 2) }; vehiclesRepository.GetVehicleByVehicleIdAsync(Arg.Any <int>()).Returns(Task.FromResult(vehicle)); locationsRepository.AddLocationAsync(Arg.Any <Location>()).Returns(Task.FromResult(location)); // Act var response = await locationsService.AddLocationAsync(locationRequest); // Assert Assert.NotNull(response); Assert.IsType <LocationResponse>(response); Assert.Equal(1, response.VehicleId); Assert.Equal(13.788571, response.Latitude); Assert.Equal(100.538034, response.Longitude); }