コード例 #1
0
        public async Task <ActionResult <TripDto> > Create(CreatingTripDto obj)
        {
            var dto  = TripMapper.toDTO(obj);
            var trip = await _service.AddAsync(dto);

            return(CreatedAtAction(nameof(GetGetById), new { Id = trip.Id }, trip));
        }
コード例 #2
0
        public void testSetParameters()
        {
            string key  = "keyTrip1";
            string line = "lineTest1";
            string path = "pathTest1";

            int[] passingTimes = { 1, 2, 3, 4, 5 };

            CreatingTripDto ctdto = new CreatingTripDto(key, line, path, passingTimes);

            Assert.AreEqual(ctdto.Key, key);
            Assert.AreEqual(ctdto.Line, line);
            Assert.AreEqual(ctdto.Path, path);
            Assert.AreEqual(ctdto.PassingTimes, passingTimes);
        }
コード例 #3
0
        public async Task Post_AllParameters_Success()
        {
            CreatingTripDto request = new CreatingTripDto("asdsds", "asfdsa", "dcxvxc", new int[] { 1, 2, 3, 4, 5 });

            var mock = new Mock <ITripService>();

            mock.Setup(service => service.AddAsync(It.IsAny <TripDto>())).Returns(Task.FromResult(TripMapper.toDTO(request)));
            TripsController controller = new TripsController(mock.Object);

            var result = await controller.Create(request);

            mock.Verify(service => service.AddAsync(It.IsAny <TripDto>()), Times.AtLeastOnce());
            ActionResult <TripDto> tripDto = TripMapper.toDTO(request);

            Assert.IsInstanceOfType(result, typeof(ActionResult <TripDto>));
        }
コード例 #4
0
        public async Task Post_NormalParameters_Sucess()
        {
            CreatingTripDto creatingTripDto = new CreatingTripDto("asdsds", "asfdsa", "dcxvxc", new int[] { 1, 2, 3, 4, 5 });

            TripDto tripDto        = TripMapper.toDTO(creatingTripDto);
            Trip    trip           = TripMapper.toDomain(tripDto);
            var     mockRepository = new Mock <ITripRepository>();

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

            var mockUnit = new Mock <IUnitOfWork>();

            TripService     TripService = new TripService(mockUnit.Object, mockRepository.Object);
            TripsController controller  = new TripsController(TripService);

            var result = await controller.Create(creatingTripDto);

            mockRepository.Verify(repository => repository.AddAsync(It.IsAny <Trip>()), Times.AtLeastOnce());
            mockUnit.Verify(unit => unit.CommitAsync(), Times.AtLeastOnce());
            Assert.IsInstanceOfType(result, typeof(ActionResult <TripDto>));
        }
コード例 #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);
        }