Beispiel #1
0
        public async Task <ActionResult <DriverDto> > Create(CreatingDriverDto obj)
        {
            var dto    = DriverMapper.toDTO(obj);
            var driver = await _service.AddAsync(dto);

            return(CreatedAtAction(nameof(GetGetById), new { Id = driver.Id }, driver));
        }
Beispiel #2
0
        public void testSetParameters()
        {
            String        mNumber        = "12a45678b";
            String        name           = "DriverTest";
            DateTime      birthDate      = new DateTime(2000, 06, 14);
            int           cardNumber     = 12345678;
            int           NIF            = 987654321;
            int           drivingLicense = 123456789;
            DateTime      drivingLicenseExpirationDate = new DateTime(2024, 05, 01);
            List <String> DriverTypes = new List <String> {
                "Linguas", "Experiente"
            };
            DateTime EntryDateCompany     = new DateTime(2018, 07, 01);
            DateTime DepartureDateCompany = new DateTime(2019, 01, 01);

            long birthDateMiliseconds = (long)(new TimeSpan(birthDate.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks)).TotalMilliseconds;
            long drivingLicenseExpirationDateMiliseconds = (long)(new TimeSpan(drivingLicenseExpirationDate.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks)).TotalMilliseconds;
            long EntryDateCompanyMiliseconds             = (long)(new TimeSpan(EntryDateCompany.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks)).TotalMilliseconds;
            long DepartureDateCompanyMiliseconds         = (long)(new TimeSpan(DepartureDateCompany.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks)).TotalMilliseconds;

            CreatingDriverDto cdto = new CreatingDriverDto(mNumber, name, birthDateMiliseconds, cardNumber, NIF, drivingLicense, drivingLicenseExpirationDateMiliseconds, DriverTypes.ToArray(), EntryDateCompanyMiliseconds, DepartureDateCompanyMiliseconds);

            Assert.AreEqual(cdto.MechanographicNumber, mNumber);
            Assert.AreEqual(cdto.Name, name);
            Assert.AreEqual(cdto.DateBirth, birthDateMiliseconds);
            Assert.AreEqual(cdto.CitizenCardNumber, cardNumber);
            Assert.AreEqual(cdto.NIF, NIF);
            Assert.AreEqual(cdto.DrivingLicenseNumber, drivingLicense);
            Assert.AreEqual(cdto.DrivingLicenseExpirationDate, drivingLicenseExpirationDateMiliseconds);
            Assert.AreEqual(cdto.EntryDateCompany, EntryDateCompanyMiliseconds);
            Assert.AreEqual(cdto.DepartureDateCompany, DepartureDateCompanyMiliseconds);
        }
Beispiel #3
0
        public async Task Post_NormalParameters_Sucess()
        {
            CreatingDriverDto request = new CreatingDriverDto("DriverA10", "lalala", 876263907, 14352011, 227012657, 927638614, 3495566307, new string[] { "Driver:1", "Driver:2", "Driver:3" }, 1128724707, 0);

            var mock = new Mock <IDriverService>();

            mock.Setup(service => service.AddAsync(It.IsAny <DriverDto>())).Returns(Task.FromResult(DriverMapper.toDTO(request)));
            DriversController controller = new DriversController(mock.Object);

            var result = await controller.Create(request);

            mock.Verify(service => service.AddAsync(It.IsAny <DriverDto>()), Times.AtLeastOnce());
            ActionResult <DriverDto> driverDto = DriverMapper.toDTO(request);

            Assert.IsInstanceOfType(result, typeof(ActionResult <DriverDto>));
        }
Beispiel #4
0
        public async Task Post_NormalParameters_Sucess()
        {
            CreatingDriverDto creatingDriverDto = new CreatingDriverDto("DriverA10", "lalala", 876263907, 14352011, 227012657, 927638614, 3495566307000, new string[] { "Driver:1", "Driver:2", "Driver:3" }, 1128724707, 0);

            DriverDto driverDto      = DriverMapper.toDTO(creatingDriverDto);
            Driver    driver         = DriverMapper.toDomain(driverDto);
            var       mockRepository = new Mock <IDriverRepository>();

            mockRepository.Setup(repository => repository.AddAsync(It.IsAny <Driver>())).Returns(Task.FromResult(driver));

            var mockUnit = new Mock <IUnitOfWork>();

            DriverService     driverService = new DriverService(mockUnit.Object, mockRepository.Object);
            DriversController controller    = new DriversController(driverService);

            var result = await controller.Create(creatingDriverDto);

            mockRepository.Verify(repository => repository.AddAsync(It.IsAny <Driver>()), Times.AtLeastOnce());
            mockUnit.Verify(unit => unit.CommitAsync(), Times.AtLeastOnce());
            Assert.IsInstanceOfType(result, typeof(ActionResult <DriverDto>));
        }
Beispiel #5
0
        public async Task <string> Create()
        {
//------------------------------------------------------------------  SETUP  ----------------------------------------------------------------
            XmlDocument doc = new XmlDocument();

            doc.Load("/home/g67Admin/projeto_integrador_grupo67/mdv/Files/demo-lapr5.glx");

            XmlNodeList driverElements = doc.GetElementsByTagName("Driver");
            XmlNodeList tripsElements  = doc.GetElementsByTagName("Trip");

            List <string> driverTypesList = new List <string>();

            string [] driverTypes;

            List <int> passingTimesList = new List <int>();

            int [] passingTimes;

//------------------------------------------------------------------  DRIVERS ----------------------------------------------------------------
            foreach (XmlNode xmlNodeDriver in driverElements)
            {
                var mecNum    = xmlNodeDriver.Attributes["MechanographicNumber"];
                var name      = xmlNodeDriver.Attributes["Name"];
                var dateBirth = xmlNodeDriver.Attributes["DateBirth"];
                var ccNum     = xmlNodeDriver.Attributes["CitizenCardNumber"];
                var nif       = xmlNodeDriver.Attributes["NIF"];
                var license   = xmlNodeDriver.Attributes["DrivingLicenseNumber"];
                var expDate   = xmlNodeDriver.Attributes["DrivingLicenseExpirationDate"];
                var entryDate = xmlNodeDriver.Attributes["EntryDateCompany"];

                foreach (XmlNode xmlNodeInner in xmlNodeDriver.ChildNodes[0].ChildNodes)
                {
                    driverTypesList.Add(xmlNodeInner.Attributes["key"].Value);
                }
                driverTypes = driverTypesList.ToArray();

                if (mecNum != null && name != null && dateBirth != null && ccNum != null && nif != null && license != null && expDate != null && entryDate != null)
                {
                    long birthConverted     = Convert.ToInt64(dateBirth.Value);
                    long expDateConverted   = Convert.ToInt64(expDate.Value);
                    long entryDateConverted = Convert.ToInt64(entryDate.Value);
                    int  ccConverted        = Convert.ToInt32(ccNum.Value);
                    int  nifConverted       = Convert.ToInt32(nif.Value);
                    int  licenseConverted   = Convert.ToInt32(license.Value);

                    CreatingDriverDto obj        = new CreatingDriverDto(mecNum.Value, name.Value, birthConverted, ccConverted, nifConverted, licenseConverted, expDateConverted, driverTypes, entryDateConverted, 0);
                    DriversController driverCont = new DriversController(_serviceDriver);

                    await driverCont.Create(obj);

                    driverTypesList = new List <string>();
                    driverTypes     = driverTypesList.ToArray();
                }
                else
                {
                    Console.WriteLine("Error on Drivers");
                }
            }
//------------------------------------------------------------------   TRIPS  ----------------------------------------------------------------
            foreach (XmlNode xmlNodeTrip in tripsElements)
            {
                var key  = xmlNodeTrip.Attributes["key"];
                var line = xmlNodeTrip.Attributes["Line"];
                var path = xmlNodeTrip.Attributes["Path"];

                foreach (XmlNode xmlNodeInnerPT in xmlNodeTrip.ChildNodes[0].ChildNodes)
                {
                    int convertedPassingTime = Convert.ToInt32(xmlNodeInnerPT.Attributes["Time"].Value);
                    passingTimesList.Add(convertedPassingTime);
                }
                passingTimes = passingTimesList.ToArray();
                Array.Reverse(passingTimes);

                if (key != null && line != null && path != null)
                {
                    CreatingTripDto obj      = new CreatingTripDto(key.Value, line.Value, path.Value, passingTimes);
                    TripsController tripCont = new TripsController(_serviceTrip);

                    await tripCont.Create(obj);

                    passingTimesList = new List <int>();
                    passingTimes     = passingTimesList.ToArray();
                }
                else
                {
                    Console.WriteLine("Error on Trips");
                }
            }

            return(null);
        }