public void CreateVehicleHistory() { VehicleHistoryDTO history = new VehicleHistoryDTO(); List <HistoricVehicleDTO> vehicles = new List <HistoricVehicleDTO>(); HistoricVehicleDTO vehicle = new HistoricVehicleDTO(); vehicle.Brand = "Chevrolet"; vehicle.Model = "Onyx"; vehicle.Year = 2016; vehicle.Color = "Gris"; vehicle.Type = "Auto"; vehicle.Vin = "TEST1234"; vehicle.Status = StatusCode.InPort; vehicle.CurrentLocation = "Puerto 1"; vehicles.Add(vehicle); List <InspectionDTO> inspections = new List <InspectionDTO>(); InspectionDTO inspection = new InspectionDTO(); inspection.CreatorUserName = "******"; inspection.Date = DateTime.Now; inspection.Location = "Puerto 1"; inspection.IdVehicle = vehicle.Vin; inspections.Add(inspection); history.VehicleHistory = vehicles; history.InspectionHistory = inspections; Assert.AreEqual("Chevrolet", history.VehicleHistory.ElementAt(0).Brand); Assert.AreEqual("Onyx", history.VehicleHistory.ElementAt(0).Model); Assert.AreEqual(2016, history.VehicleHistory.ElementAt(0).Year); Assert.AreEqual("Gris", history.VehicleHistory.ElementAt(0).Color); Assert.AreEqual("Auto", history.VehicleHistory.ElementAt(0).Type); Assert.AreEqual("TEST1234", history.VehicleHistory.ElementAt(0).Vin); Assert.AreEqual("Puerto 1", history.VehicleHistory.ElementAt(0).CurrentLocation); Assert.AreEqual("En puerto", history.VehicleHistory.ElementAt(0).Status); Assert.AreEqual("pepe123", history.InspectionHistory.ElementAt(0).CreatorUserName); Assert.AreEqual(inspection.Date, history.InspectionHistory.ElementAt(0).Date); Assert.AreEqual("Puerto 1", history.InspectionHistory.ElementAt(0).Location); Assert.AreEqual("TEST1234", history.InspectionHistory.ElementAt(0).IdVehicle); }
public void CreateVehicleHistory() { VehicleHistoryDTO history = new VehicleHistoryDTO(); List <HistoricVehicleDTO> vehicles = new List <HistoricVehicleDTO>(); HistoricVehicleDTO vehicle = new HistoricVehicleDTO(); vehicle.Brand = "Chevrolet"; vehicle.Model = "Onyx"; vehicle.Year = 2016; vehicle.Color = "Gris"; vehicle.Type = "Auto"; vehicle.Vin = "TEST1234"; vehicle.Status = StatusCode.InPort; vehicle.CurrentLocation = "Puerto 1"; vehicles.Add(vehicle); List <InspectionDTO> inspections = new List <InspectionDTO>(); InspectionDTO inspection = new InspectionDTO(); inspection.CreatorUserName = "******"; inspection.Date = DateTime.Now; inspection.Location = "Puerto 1"; inspection.IdVehicle = vehicle.Vin; inspections.Add(inspection); history.VehicleHistory = vehicles; history.InspectionHistory = inspections; var mockHistoryDAO = new Mock <HistoryDAO>(); mockHistoryDAO.Setup(h => h.GetHistory("TEST1234")).Returns(history); HistoryServiceImp service = new HistoryServiceImp(mockHistoryDAO.Object); Assert.IsNotNull(service.GetHistory("TEST1234")); }
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); }