public void GetVehicles_Success_Test() { // Arrange R_Vehicle vehicle = SampleVehicle(1); IList <R_Vehicle> list = new List <R_Vehicle>(); list.Add(vehicle); // create mock for repository var mock = new Mock <IVehicleRepository>(); mock.Setup(s => s.GetVehicles()).Returns(list); // service VehicleService vehicleService = new VehicleService(); VehicleService.Repository = mock.Object; // Act var resultList = vehicleService.GetVehicles(); VehicleDTO result = resultList.FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.VehicleId); }
public VehicleDTO(R_Vehicle vehicle) { VehicleId = vehicle.VehicleId; Make = vehicle.Make; Model = vehicle.Model; Owner = vehicle.Owner; OwnerId = vehicle.OwnerId; NucleoId = vehicle.NucleoId; VehicleTypeId = vehicle.VehicleTypeId; EnergySourceId = vehicle.EnergySourceId; AverageSpeed = vehicle.AverageSpeed; HorsePower = vehicle.HorsePower; FuelConsumption = vehicle.FuelConsumption; FuelAutonomyDistance = vehicle.FuelAutonomyDistance; RechargeTime = vehicle.RechargeTime; LicensePlate = vehicle.LicensePlate; Color = vehicle.Color; NumberSeats = vehicle.NumberSeats; CargoVolumeCapacity = vehicle.CargoVolumeCapacity; Active = vehicle.Active; IsDeleted = vehicle.IsDeleted; CreateBy = vehicle.CreateBy; CreateOn = vehicle.CreateOn; UpdateBy = vehicle.UpdateBy; UpdateOn = vehicle.UpdateOn; }
public void UpdateVehicle(R_Vehicle t) { //Requires.NotNull(t); //Requires.PropertyNotNegative(t, "VehicleId"); t.Update(); }
public static R_Vehicle ConvertDTOtoEntity(VehicleDTO dto) { R_Vehicle vehicle = new R_Vehicle(); vehicle.VehicleId = dto.VehicleId; vehicle.Make = dto.Make; vehicle.Model = dto.Model; vehicle.Owner = dto.Owner; vehicle.OwnerId = dto.OwnerId; vehicle.NucleoId = dto.NucleoId; vehicle.VehicleTypeId = dto.VehicleTypeId; vehicle.EnergySourceId = dto.EnergySourceId; vehicle.AverageSpeed = dto.AverageSpeed; vehicle.HorsePower = dto.HorsePower; vehicle.FuelConsumption = dto.FuelConsumption; vehicle.FuelAutonomyDistance = dto.FuelAutonomyDistance; vehicle.RechargeTime = dto.RechargeTime; vehicle.LicensePlate = dto.LicensePlate; vehicle.Color = dto.Color; vehicle.NumberSeats = dto.NumberSeats; vehicle.CargoVolumeCapacity = dto.CargoVolumeCapacity; vehicle.Active = dto.Active; vehicle.IsDeleted = dto.IsDeleted; vehicle.CreateBy = dto.CreateBy; vehicle.CreateOn = dto.CreateOn; vehicle.UpdateBy = dto.UpdateBy; vehicle.UpdateOn = dto.UpdateOn; return(vehicle); }
public VehicleDTO GetVehicle(int vehicleId) { try { //Requires.NotNegative("vehicleId", vehicleId); log.Debug("vehicleId: " + vehicleId + " "); // get R_Vehicle t = Repository.GetVehicle(vehicleId); VehicleDTO dto = new VehicleDTO(t); log.Debug(VehicleDTO.FormatVehicleDTO(dto)); return(dto); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public int AddVehicle(VehicleDTO dto) { int id = 0; try { log.Debug(VehicleDTO.FormatVehicleDTO(dto)); R_Vehicle t = VehicleDTO.ConvertDTOtoEntity(dto); // add id = Repository.AddVehicle(t); dto.VehicleId = id; log.Debug("result: 'success', id: " + id); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } return(id); }
public R_Vehicle GetVehicle(int vehicleId) { //Requires.NotNegative("vehicleId", vehicleId); R_Vehicle t = R_Vehicle.SingleOrDefault(vehicleId); return(t); }
// example data public static R_Vehicle SampleVehicle(int id = 1) { R_Vehicle vehicle = new R_Vehicle(); // int vehicle.VehicleId = id; // string vehicle.Make = "MakeTestValue"; // string vehicle.Model = "ModelTestValue"; // string vehicle.Owner = "OwnerTestValue"; // int? vehicle.OwnerId = 1; // int? vehicle.NucleoId = 1; // int vehicle.VehicleTypeId = 1; // int vehicle.EnergySourceId = 1; // int? vehicle.AverageSpeed = 1; // int? vehicle.HorsePower = 1; // double? vehicle.FuelConsumption = 1; // double? vehicle.FuelAutonomyDistance = 1; // int? vehicle.RechargeTime = 1; // string vehicle.LicensePlate = "LicensePlateTestValue"; // string vehicle.Color = "ColorTestValue"; // int? vehicle.NumberSeats = 1; // int? vehicle.CargoVolumeCapacity = 1; // bool vehicle.Active = false; // bool vehicle.IsDeleted = false; // int? vehicle.CreateBy = 1; // System.DateTime? vehicle.CreateOn = new System.DateTime(); // int? vehicle.UpdateBy = 1; // System.DateTime? vehicle.UpdateOn = new System.DateTime(); return(vehicle); }
public IEnumerable <R_Vehicle> GetVehicleListAdvancedSearch( string make , string model , string owner , int?ownerId , int?nucleoId , int?vehicleTypeId , int?energySourceId , int?averageSpeed , int?horsePower , double?fuelConsumption , double?fuelAutonomyDistance , int?rechargeTime , string licensePlate , string color , int?numberSeats , int?cargoVolumeCapacity , bool?active ) { IEnumerable <R_Vehicle> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_Vehicle") .Where("IsDeleted = 0" + (make != null ? " and Make like '%" + make + "%'" : "") + (model != null ? " and Model like '%" + model + "%'" : "") + (owner != null ? " and Owner like '%" + owner + "%'" : "") + (ownerId != null ? " and OwnerId like '%" + ownerId + "%'" : "") + (nucleoId != null ? " and NucleoId like '%" + nucleoId + "%'" : "") + (vehicleTypeId != null ? " and VehicleTypeId = " + vehicleTypeId : "") + (energySourceId != null ? " and EnergySourceId = " + energySourceId : "") + (averageSpeed != null ? " and AverageSpeed like '%" + averageSpeed + "%'" : "") + (horsePower != null ? " and HorsePower like '%" + horsePower + "%'" : "") + (fuelConsumption != null ? " and FuelConsumption like '%" + fuelConsumption + "%'" : "") + (fuelAutonomyDistance != null ? " and FuelAutonomyDistance like '%" + fuelAutonomyDistance + "%'" : "") + (rechargeTime != null ? " and RechargeTime like '%" + rechargeTime + "%'" : "") + (licensePlate != null ? " and LicensePlate like '%" + licensePlate + "%'" : "") + (color != null ? " and Color like '%" + color + "%'" : "") + (numberSeats != null ? " and NumberSeats like '%" + numberSeats + "%'" : "") + (cargoVolumeCapacity != null ? " and CargoVolumeCapacity like '%" + cargoVolumeCapacity + "%'" : "") + (active != null ? " and Active = " + (active == true ? "1" : "0") : "") ) ; results = R_Vehicle.Query(sql); return(results); }
public IEnumerable <R_Vehicle> GetVehicles() { IEnumerable <R_Vehicle> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_Vehicle") .Where("IsDeleted = 0") ; results = R_Vehicle.Query(sql); return(results); }
public IList <R_Vehicle> GetVehicles(string searchTerm, int pageIndex, int pageSize) { IList <R_Vehicle> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_Vehicle") .Where("IsDeleted = 0") .Where( "Make like '%" + searchTerm + "%'" + " or " + "Model like '%" + searchTerm + "%'" + " or " + "Owner like '%" + searchTerm + "%'" + " or " + "LicensePlate like '%" + searchTerm + "%'" + " or " + "Color like '%" + searchTerm + "%'" ) ; results = R_Vehicle.Fetch(pageIndex, pageSize, sql); return(results); }
public void DeleteVehicle(VehicleDTO dto) { try { log.Debug(VehicleDTO.FormatVehicleDTO(dto)); R_Vehicle t = VehicleDTO.ConvertDTOtoEntity(dto); // delete Repository.DeleteVehicle(t); dto.IsDeleted = t.IsDeleted; log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public void GetVehicle_Success_Test() { // Arrange int id = 1; R_Vehicle vehicle = SampleVehicle(id); // create mock for repository var mock = new Mock <IVehicleRepository>(); mock.Setup(s => s.GetVehicle(Moq.It.IsAny <int>())).Returns(vehicle); // service VehicleService vehicleService = new VehicleService(); VehicleService.Repository = mock.Object; // Act VehicleDTO result = vehicleService.GetVehicle(id); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.VehicleId); }
public void UpdateVehicle(VehicleDTO dto) { try { //Requires.NotNull(t); //Requires.PropertyNotNegative(t, "VehicleId"); log.Debug(VehicleDTO.FormatVehicleDTO(dto)); R_Vehicle t = VehicleDTO.ConvertDTOtoEntity(dto); // update Repository.UpdateVehicle(t); log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public void DeleteVehicle(R_Vehicle t) { t.IsDeleted = true; t.Update(); }
public int AddVehicle(R_Vehicle t) { int id = (int)t.Insert(); return(id); }