Exemplo n.º 1
0
        public async Task <ActionResult <DriverDTO> > Create(CreatingDriverDTO dto)
        {
            try
            {
                List <string> listDriverTypes = new List <string>();

                foreach (var driverType in dto.driverTypes)
                {
                    var driverTypeId = await driverTypeService.GetDriverTypeByID(driverType);

                    listDriverTypes.Add(driverTypeId.code);
                }

                CreatingLicenseDTO licenseDTO = new CreatingLicenseDTO(dto.numberDriverLicense, dto.dateDriverLicense);

                CreatingCitizenCardDTO cardDTO = new CreatingCitizenCardDTO(dto.driverName, dto.birthDate, dto.citizenCardNumber, dto.driverNIF);

                var driver = await driverService.AddDriver(dto, licenseDTO, cardDTO);

                return(CreatedAtAction(
                           nameof(GetById),
                           new { id = driver.Id },
                           driver
                           ));
            }
            catch (BusinessRuleValidationException ex)
            {
                return(BadRequest(new { Message = ex.Message }));
            }
        }
Exemplo n.º 2
0
        public async void create()
        {
            var driverServiceMock     = new Mock <IDriverService>();
            var driverTypeServiceMock = new Mock <IDriverTypeService>();

            string mecanographicNumber = "D-103";
            string driverName          = "Driver Teste";
            string birthDate           = "12/12/1971";
            long   citizenCardNumber   = 11144477;
            long   driverNIF           = 159951159;
            string entranceDate        = "27/01/1978";
            string departureDate       = "31/05/2020";
            string numberDriverLicense = "P-1111111 1";
            string dateDriverLicense   = "12/10/2020";

            var driverType = new DriverTypeId("driverType1");

            List <DriverTypeId> listDriverTypes = new List <DriverTypeId>()
            {
                driverType
            };

            var driver = new Driver(mecanographicNumber, driverName, birthDate, citizenCardNumber, driverNIF, entranceDate, departureDate, numberDriverLicense, dateDriverLicense, listDriverTypes);

            CitizenCardDTO citizenCardDTO = new CitizenCardDTO(driver.citizenCard.Id.AsGuid(), driverName, birthDate, citizenCardNumber, driverNIF);

            LicenseDTO licenseDTO = new LicenseDTO(driver.driverLicense.Id.AsGuid(), numberDriverLicense, dateDriverLicense);

            List <string> driverTypeDTOs = new List <string>()
            {
                driverType.id
            };


            var driverDTO = new DriverDTO(driver.Id.AsGuid(), mecanographicNumber, citizenCardDTO, entranceDate, departureDate, licenseDTO, driverTypeDTOs);

            var driverTypeDTO = new DriverTypeDTO("driverType1", "Teste");

            var creatingDriverDTO = new CreatingDriverDTO(mecanographicNumber, driverName, birthDate, citizenCardNumber, driverNIF, entranceDate, departureDate, numberDriverLicense, dateDriverLicense, driverTypeDTOs);

            var creatingCitizenCardDTO = new CreatingCitizenCardDTO(driverName, birthDate, citizenCardNumber, driverNIF);

            var creatingLicenseDTO = new CreatingLicenseDTO(numberDriverLicense, dateDriverLicense);

            driverTypeServiceMock.Setup(_ => _.GetDriverTypeByID("driverType1")).ReturnsAsync(driverTypeDTO);

            driverServiceMock.Setup(_ => _.AddDriver(creatingDriverDTO, creatingLicenseDTO, creatingCitizenCardDTO)).ReturnsAsync(driverDTO);

            var controller = new DriverController(driverServiceMock.Object, driverTypeServiceMock.Object);

            var actual = await controller.Create(creatingDriverDTO);

            Assert.NotNull(actual);
            Assert.NotNull(actual.Result);
        }
Exemplo n.º 3
0
        public async void AddDriver()
        {
            var repo = new Mock <IDriverRepository>();
            var uow  = new Mock <IUnitOfWork>();

            string mecanographicNumber = "D-103";
            string driverName          = "Driver Teste";
            string birthDate           = "12/12/1971";
            long   citizenCardNumber   = 11144477;
            long   driverNIF           = 159951159;
            string entranceDate        = "27/01/1978";
            string departureDate       = "31/05/2020";
            string numberDriverLicense = "P-1111111 1";
            string dateDriverLicense   = "12/10/2020";

            var driverType = new DriverTypeId("driverType1");

            List <DriverTypeId> listDriverTypes = new List <DriverTypeId>();

            listDriverTypes.Add(driverType);

            var driver = new Driver(mecanographicNumber, driverName, birthDate, citizenCardNumber, driverNIF, entranceDate, departureDate, numberDriverLicense, dateDriverLicense, listDriverTypes);

            CitizenCardDTO citizenCardDTO = new CitizenCardDTO(driver.citizenCard.Id.AsGuid(), driverName, birthDate, citizenCardNumber, driverNIF);

            LicenseDTO licenseDTO = new LicenseDTO(driver.driverLicense.Id.AsGuid(), numberDriverLicense, dateDriverLicense);

            List <string> driverTypeDTOs = new List <string>()
            {
                driverType.id
            };

            var driverDTO = new DriverDTO(driver.Id.AsGuid(), mecanographicNumber, citizenCardDTO, entranceDate, departureDate, licenseDTO, driverTypeDTOs);

            var creatingDriverDTO = new CreatingDriverDTO(mecanographicNumber, driverName, birthDate, citizenCardNumber, driverNIF, entranceDate, departureDate, numberDriverLicense, dateDriverLicense, driverTypeDTOs);

            var creatingCitizenCardDTO = new CreatingCitizenCardDTO(driverName, birthDate, citizenCardNumber, driverNIF);

            var creatingLicenseDTO = new CreatingLicenseDTO(numberDriverLicense, dateDriverLicense);

            repo.Setup(_ => _.AddAsync(driver)).ReturnsAsync(driver);

            var service = new DriverService(repo.Object, uow.Object);

            var actual = await service.AddDriver(creatingDriverDTO, creatingLicenseDTO, creatingCitizenCardDTO);

            Assert.Equal(driverDTO, actual);
        }
Exemplo n.º 4
0
        public async Task <DriverDTO> AddDriver(CreatingDriverDTO dto, CreatingLicenseDTO licenseDTO, CreatingCitizenCardDTO cardDTO)
        {
            List <DriverTypeId> driverTypes = new List <DriverTypeId>();

            foreach (var driverTypeId in dto.driverTypes)
            {
                driverTypes.Add(new DriverTypeId(driverTypeId));
            }

            var driver = new Driver(
                dto.mecanographicNumber,
                dto.driverName,
                dto.birthDate,
                dto.citizenCardNumber,
                dto.driverNIF,
                dto.entranceDate,
                dto.departureDate,
                dto.numberDriverLicense,
                dto.dateDriverLicense,
                driverTypes
                );

            var savedDriver = await this._repo.AddAsync(driver);

            await this._unitOfWork.CommitAsync();


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

            foreach (var savedDriverType in driver.driverTypes)
            {
                listSavedDriverTypes.Add(savedDriverType.ToString());
            }



            DriverDTO driverDTO = this._mapper.DomainToDTO(savedDriver, listSavedDriverTypes);

            return(driverDTO);
        }