Beispiel #1
0
        public ElevatorHelperTest()
        {
            List <Passenger> passengers       = new List <Passenger>();
            Floor            elevatorPosition = new Floor(0);

            elevator       = new Elevator(passengers, elevatorPosition, Direction.DOWN);
            elevatorHelper = new ElevatorHelper();
        }
Beispiel #2
0
        public void ElevatorHelper_FindPassengerAtDestination()
        {
            List <Passenger> passengers       = new List <Passenger>();
            Floor            elevatorPosition = new Floor(7);

            elevator       = new Elevator(passengers, elevatorPosition, Direction.DOWN);
            elevatorHelper = new ElevatorHelper();

            elevator.Passengers.Add(new Passenger("Mike", "John", new Floor(4), new Floor(7), Direction.UP));
            elevator.Passengers.Add(new Passenger("Samuel", "Doe", new Floor(5), new Floor(8), Direction.DOWN));

            List <Passenger> passenger = elevatorHelper.FindPassengerAtDestination(elevator);

            Assert.Equal("Mike", passenger.FirstOrDefault().FirstName);
        }
Beispiel #3
0
        public ActionResult <ApiResponse <Elevator> > GetElevator(int floor)
        {
            try
            {
                Logger.Info($"Elevators called from floor - {floor}");
                var elevator = ElevatorHelper.GetNearestElevator(_elevators, floor);

                if (floor > elevator.MaxFloor)
                {
                    Logger.Warn($"Elevators called from floor - {floor} - invalid request");
                    return(Ok(new ApiResponse <Elevator>()
                    {
                        ResponseCode = ResponseCodeType.Error,
                        Message = Resources.Resources.ExceedsLimit,
                    }));
                }
                if (elevator.CurrentState == State.Idle)
                {
                    elevator.RunElevator(floor);
                    Logger.Warn($"Elevator served - {elevator.Guid}");
                    var apiResponse = new ApiResponse <Elevator>()
                    {
                        ResponseCode   = ResponseCodeType.Success,
                        ResponseObject = elevator
                    };
                    return(Ok(apiResponse));
                }
                Logger.Warn($"Elevators called from floor - {floor} - all busy");
                return(Ok(new ApiResponse <Elevator>()
                {
                    ResponseCode = ResponseCodeType.Error,
                    Message = Resources.Resources.Waiting,
                }));
            }
            catch (Exception ex)
            {
                Logger.Error($"call Elevator failed - {ex.Message}");
                return(Ok(new ApiResponse <Elevator>()
                {
                    ResponseCode = ResponseCodeType.Error,
                    Message = Resources.Resources.ErrorMessage,
                }));
            }
        }
Beispiel #4
0
 public ElevatorControl()
 {
     elevatorHelper = new ElevatorHelper();
 }