public void MapInspectionToInspectionDTOTest() { UserDTO userDTO = this.CreateUser(); UserMapper userMapper = new UserMapper(new RoleDAOImp()); User user = userMapper.ToEntity(userDTO); VehicleDTO vehicleDTO = new VehicleDTO(); VehicleMapper vehicleMapper = new VehicleMapper(); Vehicle vehicle = vehicleMapper.ToEntity(vehicleDTO); InspectionMapper mapper = new InspectionMapper(); Inspection inspection = new Inspection(); inspection.Date = DateTime.Now; inspection.IdLocation = new Location(Ports.FIRST_PORT); inspection.IdUser = user; inspection.Damages = new List <Damage>(); inspection.IdVehicle = vehicle; InspectionDTO inspectionDTO = mapper.ToDTO(inspection); Assert.AreEqual(inspectionDTO.Location, inspection.IdLocation.Name); Assert.AreEqual(inspectionDTO.Id, inspection.Id); Assert.AreEqual(inspectionDTO.Date, inspection.Date); Assert.AreEqual(inspectionDTO.CreatorUserName, inspection.IdUser.UserName); Assert.AreEqual(inspectionDTO.IdVehicle, inspection.IdVehicle.Vin); foreach (DamageDTO damageDTO in inspectionDTO.Damages) { Assert.IsNotNull(inspection.Damages.Find(d => d.Description == damageDTO.Description)); } }
public VehicleHistoryDTO GetHistory(string vin) { VehicleHistoryDTO historyDTO = null; List <HistoricVehicle> historicVehicles = null; List <Inspection> historicInspections = null; using (VehicleTrackingDbContext context = new VehicleTrackingDbContext()) { historicVehicles = context.HistoricVehicles .Where(hv => hv.Vin == vin) .ToList(); historicInspections = context.Inspections .Include("IdUser") .Include("IdLocation") .Include("Damages") .Include("IdVehicle") .Where(i => i.IdVehicle.Vin == vin) .ToList(); if ((historicVehicles != null && historicVehicles.Count > 0) || (historicInspections != null && historicInspections.Count > 0)) { historyDTO = new VehicleHistoryDTO(); if (historicVehicles != null && historicVehicles.Count > 0) { List <HistoricVehicleDTO> historicVehiclesDTO = new List <HistoricVehicleDTO>(); foreach (HistoricVehicle historicVehicle in historicVehicles) { HistoricVehicleDTO historicVehicleDTO = new HistoricVehicleDTO(); historicVehicleDTO.Brand = historicVehicle.Brand; historicVehicleDTO.Color = historicVehicle.Color; historicVehicleDTO.CurrentLocation = historicVehicle.CurrentLocation; historicVehicleDTO.Date = historicVehicle.Date; historicVehicleDTO.Model = historicVehicle.Model; historicVehicleDTO.Status = historicVehicle.Status; historicVehicleDTO.Type = historicVehicle.Type; historicVehicleDTO.Vin = historicVehicle.Vin; historicVehicleDTO.Year = historicVehicle.Year; historicVehiclesDTO.Add(historicVehicleDTO); } historyDTO.VehicleHistory = historicVehiclesDTO; } if (historicInspections != null && historicInspections.Count > 0) { List <InspectionDTO> historicInspectionsDTO = new List <InspectionDTO>(); InspectionMapper inspectionMapper = new InspectionMapper(); foreach (Inspection historicInspection in historicInspections) { InspectionDTO historicInspectionDTO = inspectionMapper.ToDTO(historicInspection); historicInspectionsDTO.Add(historicInspectionDTO); } historyDTO.InspectionHistory = historicInspectionsDTO; } } } return(historyDTO); }