Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        public void AddVehicle(VehicleDTO vehicleDTO)
        {
            Vehicle vehicle = mapper.ToEntity(vehicleDTO);

            vehicle.Id = Guid.NewGuid();
            HistoricVehicle historicVehicle = mapVehicleToHistoricVehicle(vehicleDTO);

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                context.Vehicles.Add(vehicle);
                context.HistoricVehicles.Add(historicVehicle);
                context.SaveChanges();
            }
        }