Exemplo n.º 1
0
            public void WhenOpenDoorsAndNoDirection_ThenLiftDoorsOpenAndSetDireciton()
            {
                var lift = new Lift()
                {
                    Level     = 5,
                    State     = LiftState.Stopped,
                    Direction = null
                };

                var passengerGettingOn = new Passenger(0);
                var summons            = new List <Summon>()
                {
                    new Summon(5, Direction.Down, new List <Passenger>()
                    {
                        passengerGettingOn
                    })
                };

                LiftService.ExecuteInstruction(Instruction.OpenDoors, lift, summons);

                Assert.True(lift.State == LiftState.DoorsOpen);
                // passengers get on
                Assert.Contains(passengerGettingOn, lift.Passengers);
                // answered summons are removed
                Assert.Empty(summons);
                // direction set
                Assert.True(lift.Direction == Direction.Down);
            }
Exemplo n.º 2
0
 public LiftController(IWordRepository repo, IProjectService projServ, IPermissionService permissionService)
 {
     _wordRepo          = repo;
     _projectService    = projServ;
     _liftService       = new LiftService(_wordRepo, _projectService);
     _permissionService = permissionService;
 }
Exemplo n.º 3
0
            public void CanOptimiseInstructionsStartingAtGround(List <Summon> summons, List <Instruction> optimalInstructions)
            {
                var lift = new Lift {
                    Level = 0
                };                                 // 0 = Ground
                var instructions = LiftService.CalculateOptimalInstructions(lift, summons);

                Assert.Equal(instructions, optimalInstructions);
            }
Exemplo n.º 4
0
        public IHttpActionResult TravelToNextStop()
        {
            var lift        = HttpContext.Current.Application["Lift"];
            var liftService = new LiftService((Lift)lift);

            liftService.Travel();

            HttpContext.Current.Application["Lift"] = liftService.Lift;
            return(Ok());
        }
Exemplo n.º 5
0
        public IHttpActionResult RequestStop(StopModel model)
        {
            var lift        = HttpContext.Current.Application["Lift"];
            var liftService = new LiftService((Lift)lift);

            liftService.RequestStop(model);

            HttpContext.Current.Application["Lift"] = liftService.Lift;
            return(Ok());
        }
Exemplo n.º 6
0
            public void WhenStop_ThenLiftStopped()
            {
                var lift = new Lift()
                {
                    State = LiftState.Moving
                };
                var summons = new List <Summon>();

                LiftService.ExecuteInstruction(Instruction.Stop, lift, summons);

                Assert.True(lift.State == LiftState.Stopped);
            }
Exemplo n.º 7
0
            public void WhenTravelDown_ThenMoveLiftDown()
            {
                var lift = new Lift()
                {
                    Level = 5,
                    State = LiftState.Stopped
                };
                var summons = new List <Summon>();

                LiftService.ExecuteInstruction(Instruction.TravelDown, lift, summons);

                Assert.True(lift.State == LiftState.Moving);
                Assert.True(lift.Direction == Direction.Down);
                Assert.True(lift.Level == 4);
            }
Exemplo n.º 8
0
            public void WhenStoppedAndSummonsAtSameLevelWithOppositeDirectionAndSummonsInSameDirection_ThenDontOpen()
            {
                var lift = new Lift
                {
                    Level     = 1,
                    State     = LiftState.Stopped,
                    Direction = Direction.Up
                };
                var summons = new List <Summon>()
                {
                    new Summon(1, Direction.Down, new List <Passenger>()), new Summon(2, Direction.Down, new List <Passenger>())
                };
                var nextInstruction = LiftService.CalculateNextInstruction(lift, summons);

                Assert.False(nextInstruction == Instruction.OpenDoors);
            }
Exemplo n.º 9
0
            public void WhenDoorsOpenAndSummonsAtSameLevelAndDirection_ThenStayOpen()
            {
                var lift = new Lift
                {
                    Level     = 1,
                    State     = LiftState.DoorsOpen,
                    Direction = Direction.Up
                };
                var summons = new List <Summon>()
                {
                    new Summon(1, Direction.Up, new List <Passenger>())
                };
                var nextInstruction = LiftService.CalculateNextInstruction(lift, summons);

                Assert.True(nextInstruction == Instruction.OpenDoors);
            }
Exemplo n.º 10
0
            public void WhenDoorsOpenAndPassengerAtDesiredLevel_ThenStayOpen()
            {
                var lift = new Lift
                {
                    Level      = 1,
                    State      = LiftState.DoorsOpen,
                    Passengers = new List <Passenger>()
                    {
                        new Passenger(1)
                    }
                };
                var summons         = new List <Summon>();
                var nextInstruction = LiftService.CalculateNextInstruction(lift, summons);

                Assert.True(nextInstruction == Instruction.OpenDoors);
            }
Exemplo n.º 11
0
            public void WhenStoppedDirectionDownAndSummonsBelow_ThenTravelDown()
            {
                var lift = new Lift
                {
                    Level     = 5,
                    State     = LiftState.Stopped,
                    Direction = Direction.Down
                };
                var summons = new List <Summon>()
                {
                    new Summon(2, Direction.Up, new List <Passenger>())
                };
                var nextInstruction = LiftService.CalculateNextInstruction(lift, summons);

                Assert.True(nextInstruction == Instruction.TravelDown);
            }
Exemplo n.º 12
0
            public void WhenStoppedDirectionUpAndSummonsAbove_ThenTravelUp()
            {
                var lift = new Lift
                {
                    Level     = 1,
                    State     = LiftState.Stopped,
                    Direction = Direction.Up
                };
                var summons = new List <Summon>()
                {
                    new Summon(2, Direction.Down, new List <Passenger>())
                };
                var nextInstruction = LiftService.CalculateNextInstruction(lift, summons);

                Assert.True(nextInstruction == Instruction.TravelUp);
            }
Exemplo n.º 13
0
            public void WhenStoppedAndDirectionDownAndNoPassengersAndNoSummonsBelowAndSummonOnLevel_ThenOpenDoors()
            {
                var lift = new Lift
                {
                    Level     = 5,
                    State     = LiftState.Stopped,
                    Direction = Direction.Down
                };
                var summons = new List <Summon>()
                {
                    new Summon(5, Direction.Up, new List <Passenger>())
                };
                var nextInstruction = LiftService.CalculateNextInstruction(lift, summons);

                Assert.True(nextInstruction == Instruction.OpenDoors);
            }
Exemplo n.º 14
0
            public void WhenMovingAndPassengerAtDesiredLevel_ThenStop()
            {
                var lift = new Lift
                {
                    Level      = 1,
                    State      = LiftState.Moving,
                    Direction  = Direction.Up,
                    Passengers = new List <Passenger>()
                    {
                        new Passenger(1)
                    }
                };
                var summons         = new List <Summon>();
                var nextInstruction = LiftService.CalculateNextInstruction(lift, summons);

                Assert.True(nextInstruction == Instruction.Stop);
            }
Exemplo n.º 15
0
            public void WhenStoppedAndDirectionDownAndPassengersDesiredLevelBelow_ThenTravelDown()
            {
                var lift = new Lift
                {
                    Level      = 5,
                    State      = LiftState.Stopped,
                    Direction  = Direction.Down,
                    Passengers = new List <Passenger>()
                    {
                        new Passenger(2)
                    }
                };
                var summons         = new List <Summon>();
                var nextInstruction = LiftService.CalculateNextInstruction(lift, summons);

                Assert.True(nextInstruction == Instruction.TravelDown);
            }
Exemplo n.º 16
0
            public void WhenStoppedDirectionUpAndPassengersDesiredLevelAbove_ThenTravelUp()
            {
                var lift = new Lift
                {
                    Level      = 1,
                    State      = LiftState.Stopped,
                    Direction  = Direction.Up,
                    Passengers = new List <Passenger>()
                    {
                        new Passenger(4)
                    }
                };
                var summons         = new List <Summon>();
                var nextInstruction = LiftService.CalculateNextInstruction(lift, summons);

                Assert.True(nextInstruction == Instruction.TravelUp);
            }
Exemplo n.º 17
0
            public void WhenMovingAndSummonAtLevelWithOppositeDirectionAndNoOtherSummonsOrPassengers_ThenStop()
            {
                var lift = new Lift
                {
                    Level      = 5,
                    State      = LiftState.Moving,
                    Direction  = Direction.Down,
                    Passengers = new List <Passenger>()
                };
                var summons = new List <Summon>()
                {
                    new Summon(5, Direction.Up, new List <Passenger>())
                };
                var nextInstruction = LiftService.CalculateNextInstruction(lift, summons);

                Assert.True(nextInstruction == Instruction.Stop);
            }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            Console.WriteLine("Elevator Company Tests");
            Console.WriteLine("-----------------------------------------");

            var lift  = new Lift();
            var testA = new List <Summon>
            {
                new Summon(0, Direction.Up, new List <Passenger>()
                {
                    new Passenger(5)
                })
            };

            var instructions = LiftService.CalculateOptimalInstructions(lift, testA);

            Console.WriteLine("Test A");
            PrintInstructions(instructions);

            lift = new Lift();
            var testB = new List <Summon>
            {
                new Summon(6, Direction.Down, new List <Passenger> {
                    new Passenger(1)
                }),
                new Summon(4, Direction.Down, new List <Passenger> {
                    new Passenger(1)
                }),
            };

            instructions = LiftService.CalculateOptimalInstructions(lift, testB);
            Console.WriteLine("Test B");
            PrintInstructions(instructions);

            lift = new Lift();
            var testC = new List <Summon>
            {
                new Summon(2, Direction.Up, new List <Passenger> {
                    new Passenger(6)
                }),
                new Summon(4, Direction.Down, new List <Passenger> {
                    new Passenger(0)
                }),
            };

            instructions = LiftService.CalculateOptimalInstructions(lift, testC);
            Console.WriteLine("Test C");
            PrintInstructions(instructions);

            lift = new Lift();
            var testD = new List <Summon>
            {
                new Summon(0, Direction.Up, new List <Passenger> {
                    new Passenger(5)
                }),
                new Summon(4, Direction.Down, new List <Passenger> {
                    new Passenger(0)
                }),
                new Summon(10, Direction.Down, new List <Passenger> {
                    new Passenger(0)
                })
            };

            instructions = LiftService.CalculateOptimalInstructions(lift, testD);
            Console.WriteLine("Test D");
            PrintInstructions(instructions);

            Console.ReadLine();
        }
Exemplo n.º 19
0
 public LiftsController(LiftService service)
 {
     _liftservice = service;
 }
Exemplo n.º 20
0
        public void Setup()
        {
            var lift = new Lift(11);

            _liftService = new LiftService(lift);
        }