public void MapBatchToBatchDTOTest() { BatchMapper mapper = new BatchMapper(); Batch batch = new Batch(); batch.IdUser = this.CreateUser(); batch.Description = "Primer Lote"; batch.Name = "Lote1"; batch.Vehicles = new List <Vehicle>(); Vehicle vehicle = new Vehicle(); vehicle.Vin = "TEST1234"; batch.Vehicles.Add(vehicle); BatchDTO batchDTO = mapper.ToDTO(batch); Assert.AreEqual(batch.Id, batchDTO.Id); Assert.AreEqual(batch.IdUser.UserName, batchDTO.CreatorUserName); Assert.AreEqual(batch.Description, batchDTO.Description); Assert.AreEqual(batch.Name, batchDTO.Name); foreach (Vehicle ve in batch.Vehicles) { Assert.IsTrue(batchDTO.Vehicles.Contains(ve.Vin)); } }
// Get All basic tables // DEFAULT CRUD public IEnumerable <BatchMapper> GetBatches() { var content = db.Batches.ToList(); if (content.Count() == 0) { return(null); } else { List <BatchMapper> batches = new List <BatchMapper>(); foreach (var item in content) { BatchMapper batch = new BatchMapper { BatchId = item.batchId, StartDate = item.startDate ?? default(DateTime), EndDate = item.endDate ?? default(DateTime), Name = item.name }; batches.Add(batch); } return(batches); } }
// Get One basic table // DEFAULT CRUD public BatchMapper GetBatch(int batchId) { var content = db.Batches.FirstOrDefault(j => j.batchId == batchId); if (content == null) { return(null); } else { BatchMapper batch = new BatchMapper { BatchId = content.batchId, StartDate = content.startDate ?? default(DateTime), EndDate = content.endDate ?? default(DateTime), Name = content.name }; return(batch); } }
public void MapBatchDTOToBatchTest() { BatchMapper mapper = new BatchMapper(); BatchDTO batch = new BatchDTO(); batch.CreatorUserName = "******"; batch.Description = "Primer Lote"; batch.Name = "Lote1"; batch.Vehicles = new List <string>(); batch.Vehicles.Add("TEST1234"); batch.CreatorUserName = "******"; Batch batchEntity = mapper.ToEntity(batch); Assert.AreEqual(batch.Id, batchEntity.Id); Assert.AreEqual(batch.CreatorUserName, batchEntity.IdUser.UserName); Assert.AreEqual(batch.Description, batchEntity.Description); Assert.AreEqual(batch.Name, batchEntity.Name); Vehicle vehicle = batchEntity.Vehicles.Find(v => v.Vin == "TEST1234"); Assert.IsNotNull(vehicle); }
public Transport ToEntity(TransportDTO transportDTO) { UserMapper userMapper = new UserMapper(new RoleDAOImp()); BatchMapper batchMapper = new BatchMapper(); Transport transport = new Transport(); transport.Id = transportDTO.Id; transport.StartDate = transportDTO.StartDate; transport.EndDate = transportDTO.EndDate; transport.IdUser = userMapper.ToEntity(transportDTO.User); List <Batch> batches = new List <Batch>(); foreach (BatchDTO batchDTO in transportDTO.Batches) { Batch batch = batchMapper.ToEntity(batchDTO); batches.Add(batch); } transport.Batches = batches; return(transport); }
public TransportDTO ToDTO(Transport transport) { UserMapper userMapper = new UserMapper(new RoleDAOImp()); BatchMapper batchMapper = new BatchMapper(); TransportDTO transportDTO = new TransportDTO(); transportDTO.Id = transport.Id; transportDTO.StartDate = transport.StartDate; transportDTO.EndDate = transport.EndDate; transportDTO.User = userMapper.ToDTO(transport.IdUser); List <BatchDTO> batchesDTO = new List <BatchDTO>(); foreach (Batch batch in transport.Batches) { BatchDTO batchDTO = batchMapper.ToDTO(batch); batchesDTO.Add(batchDTO); } transportDTO.Batches = batchesDTO; return(transportDTO); }
public BatchDAOImp() { batchMapper = new BatchMapper(); }