private async Task RunWorker(TState state, int requestsPerBlock, int numBlocks)
        {
            var completedBlockWriter = this.completedBlocks.Writer;

            while (numBlocks > 0)
            {
                var workBlock = new WorkBlock();
                workBlock.StartTimestamp = Stopwatch.GetTimestamp();
                while (workBlock.Completed < requestsPerBlock)
                {
                    try
                    {
                        await this.issueRequest(state).ConfigureAwait(false);

                        ++workBlock.Successes;
                    }
                    catch
                    {
                        ++workBlock.Failures;
                    }
                }

                workBlock.EndTimestamp = Stopwatch.GetTimestamp();
                await completedBlockWriter.WriteAsync(workBlock);

                --numBlocks;
            }
        }
Beispiel #2
0
        public void createValidDriverDuty()
        {
            string driverDutyCode = "dDutycode1";
            var    tripList       = new List <Trip>();


            string lineID            = "Line:1";
            string pathID            = "Path:1";
            string tripDepartureTime = "20:12:10";

            var trip = new Trip(lineID, pathID, tripDepartureTime);

            tripList.Add(trip);
            var workBlock1 = new WorkBlock("9:0:0", "10:0:0", tripList);
            var workBlock2 = new WorkBlock("10:0:0", "13:0:0", tripList);
            var workBlock3 = new WorkBlock("14:0:0", "18:0:0", tripList);

            var workBlockList = new List <WorkBlock> {
                workBlock1, workBlock2, workBlock3
            };

            var driverDuty = new DriverDuty(driverDutyCode, workBlockList);

            Assert.True(driverDuty.GetType().Equals(new DriverDuty().GetType()));
        }
Beispiel #3
0
        public void createDriverDutyWithMoreThan4Straight()
        {
            string driverDutyCode = "dDutycode1";

            var tripList = new List <Trip>();


            string lineID            = "Line:1";
            string pathID            = "Path:1";
            string tripDepartureTime = "20:12:10";

            var trip = new Trip(lineID, pathID, tripDepartureTime);

            tripList.Add(trip);
            var workBlock1 = new WorkBlock("9:0:0", "10:0:0", tripList);
            var workBlock2 = new WorkBlock("10:0:0", "13:0:0", tripList);
            var workBlock3 = new WorkBlock("13:0:0", "17:0:0", tripList);

            var workBlockList = new List <WorkBlock> {
                workBlock1, workBlock2, workBlock3
            };


            Assert.Throws <BusinessRuleValidationException>(() => new DriverDuty(driverDutyCode, workBlockList));
        }
Beispiel #4
0
        public async void GetById()
        {
            var service = new Mock <IDriverDutyService>();

            string driverDutyCode = "dDutycode1";
            var    tripList       = new List <Trip>();


            string lineID            = "Line:1";
            string pathID            = "Path:1";
            string tripDepartureTime = "20:12:10";

            var trip = new Trip(lineID, pathID, tripDepartureTime);

            tripList.Add(trip);

            var workBlock1 = new WorkBlock("9:0:0", "10:0:0", tripList);
            var workBlock2 = new WorkBlock("10:0:0", "13:0:0", tripList);
            var workBlock3 = new WorkBlock("14:0:0", "18:0:0", tripList);

            var workBlockList = new List <WorkBlock> {
                workBlock1, workBlock2, workBlock3
            };

            var driverDuty = new DriverDuty(driverDutyCode, workBlockList);

            var tripDTO  = new TripDTO(trip.Id.AsGuid(), new LineId(lineID), new PathId(pathID), tripDepartureTime);
            var tripsDTO = new List <TripDTO>()
            {
                tripDTO
            };


            var listWorkBlocksString = new List <String>()
            {
                workBlock1.Id.Value, workBlock2.Id.Value, workBlock3.Id.Value
            };

            var workBlockDTO1 = new WorkBlockDTO(workBlock1.Id.AsGuid(), workBlock1.startingTime.time, workBlock1.endingTime.time, tripsDTO);
            var workBlockDTO2 = new WorkBlockDTO(workBlock2.Id.AsGuid(), workBlock2.startingTime.time, workBlock2.endingTime.time, tripsDTO);
            var workBlockDTO3 = new WorkBlockDTO(workBlock3.Id.AsGuid(), workBlock3.startingTime.time, workBlock3.endingTime.time, tripsDTO);

            var listWorkBlockDTO = new List <WorkBlockDTO>()
            {
                workBlockDTO1, workBlockDTO2, workBlockDTO3
            };

            var driverDutyDTO = new DriverDutyDTO(driverDuty.Id.AsGuid(), driverDutyCode, listWorkBlockDTO);

            service.Setup(_ => _.GetById(driverDuty.Id)).ReturnsAsync(driverDutyDTO);

            var controller = new DriverDutyController(service.Object);


            var actual = await controller.GetById(driverDuty.Id.AsGuid());

            Assert.Equal(driverDutyDTO, actual.Value);
        }
Beispiel #5
0
        public int getDurationOfWorkIndividualy(WorkBlock workBlock)
        {
            var initialHours = workBlock.startingTime.time.Split(':');
            var finalHours = workBlock.endingTime.time.Split(':');

            var duration = calculateHours(initialHours, finalHours);

            return duration;
        }
Beispiel #6
0
        public string JoinQueue(string workType, Delegate work, params object[] args)
        {
            var w = new WorkBlock(workType, work, args);

            lock (_MQLockObj)
                MQ.Add(w);
            StartWorking(workType);
            return(w.BlockKey);
        }
Beispiel #7
0
        public void DTOtoDomain()
        {
            var mapper = new DriverDutyMapper();

            string driverDutyCode = "dDutycode1";
            var    tripList       = new List <Trip>();


            string lineID            = "Line:1";
            string pathID            = "Path:1";
            string tripDepartureTime = "20:12:10";

            var trip = new Trip(lineID, pathID, tripDepartureTime);

            tripList.Add(trip);
            var workBlock1 = new WorkBlock("9:0:0", "10:0:0", tripList);
            var workBlock2 = new WorkBlock("10:0:0", "13:0:0", tripList);
            var workBlock3 = new WorkBlock("14:0:0", "18:0:0", tripList);

            var workBlockList = new List <WorkBlock> {
                workBlock1, workBlock2, workBlock3
            };

            var tripDTO  = new TripDTO(trip.Id.AsGuid(), new LineId(lineID), new PathId(pathID), tripDepartureTime);
            var tripsDTO = new List <TripDTO>()
            {
                tripDTO
            };


            var listWorkBlocksString = new List <String>()
            {
                workBlock1.Id.Value, workBlock2.Id.Value, workBlock3.Id.Value
            };

            var workBlockDTO1 = new WorkBlockDTO(workBlock1.Id.AsGuid(), workBlock1.startingTime.time, workBlock1.endingTime.time, tripsDTO);
            var workBlockDTO2 = new WorkBlockDTO(workBlock2.Id.AsGuid(), workBlock2.startingTime.time, workBlock2.endingTime.time, tripsDTO);
            var workBlockDTO3 = new WorkBlockDTO(workBlock3.Id.AsGuid(), workBlock3.startingTime.time, workBlock3.endingTime.time, tripsDTO);

            var listWorkBlockDTO = new List <WorkBlockDTO>()
            {
                workBlockDTO1, workBlockDTO2, workBlockDTO3
            };


            var driverDuty = new DriverDuty(driverDutyCode, workBlockList);

            var expected = new DriverDutyDTO(
                driverDuty.Id.AsGuid(),
                driverDutyCode,
                listWorkBlockDTO
                );

            var actual = mapper.DomainToDTO(driverDuty);

            Assert.Equal(actual, expected);
        }
Beispiel #8
0
        public async Task <WorkBlockDTO> AddWorkBlock(CreatingWorkBlockDTO workBlockDTO)
        {
            List <Trip> tripList = new List <Trip>();

            foreach (var tripId in workBlockDTO.tripList)
            {
                tripList.Add(await this._tripRepository.GetByIdAsync(new TripId(tripId)));
            }

            var wb      = new WorkBlock(workBlockDTO.startingTime, workBlockDTO.endingTime, tripList);
            var savedWb = await this._workBlockRepository.AddAsync(wb);

            await this._unitOfWork.CommitAsync();

            return(this._workBlockMapper.DomainToDTO(savedWb));
        }
Beispiel #9
0
        public WorkBlockDTO DomainToDTO(WorkBlock workBlock)
        {
            var tripDTOList = new List <TripDTO> ();

            foreach (var trip in workBlock.tripList)
            {
                var tripDTO = _tripMapper.DomainToDTO(trip);
                tripDTOList.Add(tripDTO);
            }

            var workBlockDTO = new WorkBlockDTO(
                workBlock.Id.AsGuid(),
                workBlock.startingTime.ToString(),
                workBlock.endingTime.ToString(),
                tripDTOList
                );

            return(workBlockDTO);
        }
Beispiel #10
0
        public async void GetAll()
        {
            var repo                      = new Mock <IDriverDutyRepository>();
            var repoWorkBlocks            = new Mock <IWorkBlockRepository>();
            var repoVehicleDutyRepository = new Mock <IVehicleDutyRepository>();
            var uow = new Mock <IUnitOfWork>();

            string driverDutyCode = "dDutycode1";
            var    tripList       = new List <Trip>();


            string lineID            = "Line:1";
            string pathID            = "Path:1";
            string tripDepartureTime = "20:12:10";

            var trip = new Trip(lineID, pathID, tripDepartureTime);

            tripList.Add(trip);

            var workBlock1 = new WorkBlock("9:0:0", "10:0:0", tripList);
            var workBlock2 = new WorkBlock("10:0:0", "13:0:0", tripList);
            var workBlock3 = new WorkBlock("14:0:0", "18:0:0", tripList);

            var workBlockList = new List <WorkBlock> {
                workBlock1, workBlock2, workBlock3
            };

            var driverDuty = new DriverDuty(driverDutyCode, workBlockList);

            var tripDTO  = new TripDTO(trip.Id.AsGuid(), new LineId(lineID), new PathId(pathID), tripDepartureTime);
            var tripsDTO = new List <TripDTO>()
            {
                tripDTO
            };


            var listWorkBlocksString = new List <String>()
            {
                workBlock1.Id.Value, workBlock2.Id.Value, workBlock3.Id.Value
            };

            var workBlockDTO1 = new WorkBlockDTO(workBlock1.Id.AsGuid(), workBlock1.startingTime.time, workBlock1.endingTime.time, tripsDTO);
            var workBlockDTO2 = new WorkBlockDTO(workBlock2.Id.AsGuid(), workBlock2.startingTime.time, workBlock2.endingTime.time, tripsDTO);
            var workBlockDTO3 = new WorkBlockDTO(workBlock3.Id.AsGuid(), workBlock3.startingTime.time, workBlock3.endingTime.time, tripsDTO);

            var listWorkBlockDTO = new List <WorkBlockDTO>()
            {
                workBlockDTO1, workBlockDTO2, workBlockDTO3
            };

            var driverDutyDTO = new DriverDutyDTO(driverDuty.Id.AsGuid(), driverDutyCode, listWorkBlockDTO);

            var listDriverDTOs = new List <DriverDutyDTO>()
            {
                driverDutyDTO
            };

            var listDrivers = new List <DriverDuty>()
            {
                driverDuty
            };

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

            var service = new DriverDutyService(repo.Object, repoWorkBlocks.Object, repoVehicleDutyRepository.Object, uow.Object);

            var actual = await service.GetAll();

            Assert.Equal(listDriverDTOs, actual);
        }
Beispiel #11
0
        public async void AddDriverDuty()
        {
            var repo                      = new Mock <IDriverDutyRepository>();
            var repoWorkBlocks            = new Mock <IWorkBlockRepository>();
            var repoVehicleDutyRepository = new Mock <IVehicleDutyRepository>();

            var uow = new Mock <IUnitOfWork>();

            string driverDutyCode = "dDutycode1";
            var    tripList       = new List <Trip>();


            string lineID            = "Line:1";
            string pathID            = "Path:1";
            string tripDepartureTime = "20:12:10";

            var trip = new Trip(lineID, pathID, tripDepartureTime);

            tripList.Add(trip);

            var workBlock1 = new WorkBlock("9:0:0", "10:0:0", tripList);
            var workBlock2 = new WorkBlock("10:0:0", "13:0:0", tripList);
            var workBlock3 = new WorkBlock("14:0:0", "18:0:0", tripList);

            var workBlockList = new List <WorkBlock> {
                workBlock1, workBlock2, workBlock3
            };

            var driverDuty = new DriverDuty(driverDutyCode, workBlockList);

            var tripDTO  = new TripDTO(trip.Id.AsGuid(), new LineId(lineID), new PathId(pathID), tripDepartureTime);
            var tripsDTO = new List <TripDTO>()
            {
                tripDTO
            };

            var tripsDTOString = new List <string>()
            {
                trip.Id.ToString()
            };


            var cworkBlockDTO1 = new CreatingWorkBlockDTO(tripsDTOString, workBlock1.startingTime.time, workBlock1.endingTime.time);
            var cworkBlockDTO2 = new CreatingWorkBlockDTO(tripsDTOString, workBlock2.startingTime.time, workBlock2.endingTime.time);
            var cworkBlockDTO3 = new CreatingWorkBlockDTO(tripsDTOString, workBlock3.startingTime.time, workBlock3.endingTime.time);


            var listWorkBlocksString = new List <String>()
            {
                workBlock1.Id.Value, workBlock2.Id.Value, workBlock3.Id.Value
            };

            var workBlockDTO1 = new WorkBlockDTO(workBlock1.Id.AsGuid(), workBlock1.startingTime.time, workBlock1.endingTime.time, tripsDTO);
            var workBlockDTO2 = new WorkBlockDTO(workBlock2.Id.AsGuid(), workBlock2.startingTime.time, workBlock2.endingTime.time, tripsDTO);
            var workBlockDTO3 = new WorkBlockDTO(workBlock3.Id.AsGuid(), workBlock3.startingTime.time, workBlock3.endingTime.time, tripsDTO);

            var listWorkBlockDTO = new List <WorkBlockDTO>()
            {
                workBlockDTO1, workBlockDTO2, workBlockDTO3
            };

            var driverDutyDTO = new DriverDutyDTO(driverDuty.Id.AsGuid(), driverDutyCode, listWorkBlockDTO);

            var creatingDriverDutyDTO = new CreatingDriverDutyDTO(driverDutyCode, listWorkBlocksString);

            var workBlockID1 = new WorkBlockID(workBlockDTO1.Id);
            var workBlockID2 = new WorkBlockID(workBlockDTO2.Id);
            var workBlockID3 = new WorkBlockID(workBlockDTO3.Id);

            string vehicleDutyCode = "code:1";

            string registration = "AA11AA";
            string vin          = "123456789AAAAAAAA";
            string entranceDate = "27/01/1978";
            string vehicleType  = "vehicleType1";

            Vehicle vehicle = new Vehicle(registration, vin, entranceDate, vehicleType);


            VehicleDuty vehicleDuty = new VehicleDuty(vehicleDutyCode, tripList);

            repoWorkBlocks.Setup(_ => _.GetByIdAsync(workBlockID1)).ReturnsAsync(workBlock1);

            repoWorkBlocks.Setup(_ => _.GetByIdAsync(workBlockID2)).ReturnsAsync(workBlock2);

            repoWorkBlocks.Setup(_ => _.GetByIdAsync(workBlockID3)).ReturnsAsync(workBlock3);

            repoVehicleDutyRepository.Setup(_ => _.getVehicleDutyByWorkblock(workBlock1)).ReturnsAsync(vehicleDuty);

            repoVehicleDutyRepository.Setup(_ => _.getVehicleDutyByWorkblock(workBlock2)).ReturnsAsync(vehicleDuty);

            repoVehicleDutyRepository.Setup(_ => _.getVehicleDutyByWorkblock(workBlock3)).ReturnsAsync(vehicleDuty);

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

            var service = new DriverDutyService(repo.Object, repoWorkBlocks.Object, repoVehicleDutyRepository.Object, uow.Object);

            var actual = await service.AddDriverDuty(creatingDriverDutyDTO);

            Assert.Equal(driverDutyDTO, actual);
        }
Beispiel #12
0
 public Task <VehicleDuty> getVehicleDutyByWorkblock(WorkBlock workblock)
 {
     return(this.vehicleDuties.Where(vD => vD.workBlockList.Contains(workblock)).FirstOrDefaultAsync());
 }