public async Task Update_Driver()
        {
            var driver = new Driver
            {
                FirstName = "João",
                LastName  = "Das Neves",
                Car       = new Car
                {
                    Brand = "Porsche",
                    Model = "911 Carrera 2016",
                    Plate = "CPW-8821"
                },
                Address = new Address
                {
                    Street  = "Alameda Santos",
                    Number  = "1235",
                    City    = "São Paulo",
                    State   = "SP",
                    ZipCode = "01419-002"
                }
            };

            var driverService = new DriverService(new DriverRepository(), new MapsServiceMock());

            var driverLast = driverService.GetAll(false, false).LastOrDefault();

            driver.Id = driverLast.Id;
            await driverService.Update(driverLast.Id, driver);

            var driverRetrived = driverService.Get(driverLast.Id);

            Assert.Equal(driverLast.Id, driverRetrived.Id);
            Assert.Equal(driver.FirstName, driverRetrived.FirstName);
        }
        public async Task Delete_Driver_Id()
        {
            var driverService = new DriverService(new DriverRepository(), new MapsServiceMock());

            var driverFirst = driverService.GetAll(false, false).FirstOrDefault();

            await driverService.Delete(driverFirst.Id);

            var driverRetrived = driverService.Get(driverFirst.Id);

            Assert.Null(driverRetrived);
        }
示例#3
0
        public async void GetAllTest()
        {
            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 driversDTO = new List <DriverDTO>()
            {
                driverDTO
            };

            var drivers = new List <Driver>()
            {
                driver
            };

            repo.Setup(_ => _.GetAllAsync()).ReturnsAsync(drivers);

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

            var actual = await driverService.GetAll();

            Assert.Equal(driversDTO, actual);
        }
        private async Task RefreshDrivers()
        {
            var driverService = new DriverService();
            var allDrivers    = await driverService.GetAll();

            while (_sampleDataSource.Items.Count() > 0)
            {
                _sampleDataSource.Items.RemoveAt(0);
            }

            foreach (var driver in allDrivers)
            {
                var sampleDataItem = new Driver(
                    driver.Id,
                    driver.FirstName,
                    driver.LastName,
                    driver.BirthDate);

                _sampleDataSource.Items.Add(sampleDataItem);
            }
        }