Esempio n. 1
0
        public Guid AddTransport(TransportDTO transportDTO)
        {
            Transport transport = transportMapper.ToEntity(transportDTO);

            using (VehicleTrackingDbContext context = new VehicleTrackingDbContext())
            {
                transport.IdUser  = this.GetUser(context, transport.IdUser.UserName);
                transport.Batches = this.GetBatches(context, transport.Batches);

                context.Users.Attach(transport.IdUser);
                foreach (Batch batch in transport.Batches)
                {
                    context.Batches.Attach(batch);
                }

                context.Transports.Add(transport);
                context.SaveChanges();
            }

            return(transport.Id);
        }
Esempio n. 2
0
        public void MapTransportDTOToTransportTest()
        {
            TransportMapper mapper = new TransportMapper();

            TransportDTO transport = new TransportDTO();

            transport.StartDate = DateTime.Now;
            transport.EndDate   = DateTime.Now;
            transport.Batches   = this.CreateBatchesDTO();
            transport.User      = this.CreateUserDTO();

            Transport transportEntity = mapper.ToEntity(transport);

            Assert.AreEqual(transport.Id, transportEntity.Id);
            Assert.AreEqual(transport.StartDate, transportEntity.StartDate);
            Assert.AreEqual(transport.EndDate, transportEntity.EndDate);
            Assert.AreEqual(transport.User.UserName, transportEntity.IdUser.UserName);
            foreach (BatchDTO batch in transport.Batches)
            {
                Assert.IsNotNull(transportEntity.Batches.Find(b => b.Description == batch.Description));
            }
        }