コード例 #1
0
        public void When_person_in_lift_enters_a_floor_number_then_lift_notifies_its_current_location()
        {
            // Arrange
            var testScheduler = new TestScheduler();
            var theLiftEngine = new LiftEventGenerator(testScheduler);
            var theLift = new ObservableLift(LiftConstants.GroundFloor, theLiftEngine);
            _liftStatuses.Clear();
            theLift.Subscribe(this);

            // Act
            theLift.OnNext(new LiftMoveRequest { Floor = LiftConstants.FirstFloor });
            testScheduler.Start();
            testScheduler.AdvanceBy(5);

            // Assert
            Assert.That(_liftStatuses.Count, Is.GreaterThan(0));

            Assert.That(_liftStatuses[0].CurrentFloor, Is.EqualTo(LiftConstants.GroundFloor));
        }
コード例 #2
0
        public void When_lift_arrives_at_new_floor_after_person_calls_lift_then_lift_stops_moving()
        {
            // Arrange
            var theLift = new ObservableLift(LiftConstants.GroundFloor, this);
            _liftEngineEvents.Clear();
            theLift.Subscribe(this);

            // Act
            _currentObserver.OnNext(new LiftCall { Floor = LiftConstants.FourthFloor });
            _currentObserver.OnNext(new LiftEngineUpwardsEvent { Floor = LiftConstants.FourthFloor });

            // Assert
            Assert.That(_liftEngineEvents.Count, Is.GreaterThan(1));

            Assert.That(_liftEngineEvents[_liftEngineEvents.Count - 1].Direction, Is.EqualTo(Direction.None));
            Assert.That(_liftEngineEvents[_liftEngineEvents.Count - 1].CurrentFloor, Is.EqualTo(LiftConstants.FloorIsIrrelevant));
        }
コード例 #3
0
        public void When_person_in_lift_enters_a_lower_floor_number_then_lift_is_told_to_start_moving_downwards()
        {
            // Arrange
            var theLift = new ObservableLift(LiftConstants.ThirdFloor, this);
            _liftEngineEvents.Clear();
            theLift.Subscribe(this);

            // Act
            _currentObserver.OnNext(new LiftMoveRequest { Floor = LiftConstants.FirstFloor });

            // Assert
            Assert.That(_liftEngineEvents.Count, Is.GreaterThan(0));

            Assert.That(_liftEngineEvents[0].Direction, Is.EqualTo(Direction.Down));
            Assert.That(_liftEngineEvents[0].CurrentFloor, Is.EqualTo(LiftConstants.ThirdFloor));
        }
コード例 #4
0
        public void When_person_in_lift_enters_a_higher_floor_number_then_lift_engine_is_asked_to_move_upwards_and_then_stopped_when_it_reaches_destination()
        {
            // Arrange
            var theLift = new ObservableLift(LiftConstants.GroundFloor, this);
            _liftEngineEvents.Clear();
            theLift.Subscribe(this);

            // Act
            _currentObserver.OnNext(new LiftMoveRequest { Floor = LiftConstants.ThirdFloor });
            _currentObserver.OnNext(new LiftEngineUpwardsEvent { Floor = LiftConstants.ThirdFloor });

            // Assert
            Assert.That(_liftEngineEvents.Count, Is.EqualTo(2));

            Assert.That(_liftEngineEvents[0].Direction, Is.EqualTo(Direction.Up));
            Assert.That(_liftEngineEvents[0].CurrentFloor, Is.EqualTo(LiftConstants.GroundFloor));

            Assert.That(_liftEngineEvents[1].Direction, Is.EqualTo(Direction.None));
            Assert.That(_liftEngineEvents[1].CurrentFloor, Is.EqualTo(LiftConstants.FloorIsIrrelevant));
        }
コード例 #5
0
        public void When_person_in_lift_enters_a_floor_number_then_lift_is_told_to_move_to_that_floor()
        {
            // Arrange
            var theLift = new ObservableLift(LiftConstants.GroundFloor, this);
            _liftEngineEvents.Clear();
            theLift.Subscribe(this);

            // Act
            _currentObserver.OnNext(new LiftMoveRequest { Floor = LiftConstants.FourthFloor });

            // Assert
            Assert.That(_liftEngineEvents.Count, Is.GreaterThan(0));

            Assert.That(_liftEngineEvents[0].Direction, Is.EqualTo(Direction.Up));
            Assert.That(_liftEngineEvents[0].LastFloor, Is.EqualTo(LiftConstants.FourthFloor));
        }
コード例 #6
0
        public void When_person_calls_lift_to_higher_floor_number_then_lift_is_told_to_start_moving_upwards()
        {
            // Arrange
            var theLift = new ObservableLift(LiftConstants.GroundFloor, this);
            _liftEngineEvents.Clear();
            theLift.Subscribe(this);

            // Act
            _currentObserver.OnNext(new LiftCall { Floor = LiftConstants.ThirdFloor });

            // Assert
            Assert.That(_liftEngineEvents.Count, Is.GreaterThan(0));

            Assert.That(_liftEngineEvents[0].Direction, Is.EqualTo(Direction.Up));
            Assert.That(_liftEngineEvents[0].CurrentFloor, Is.EqualTo(LiftConstants.GroundFloor));
        }
コード例 #7
0
        public void When_person_calls_lift_to_floor_number_then_lift_notifies_direction_and_location_for_every_floor_it_passes()
        {
            // Arrange
            var theLift = new ObservableLift(LiftConstants.GroundFloor, this);
            _liftStatuses.Clear();
            theLift.Subscribe(this);

            // Act
            _currentObserver.OnNext(new LiftCall { Floor = LiftConstants.ThirdFloor });
            _currentObserver.OnNext(new LiftEngineUpwardsEvent { Floor = LiftConstants.GroundFloor });
            _currentObserver.OnNext(new LiftEngineUpwardsEvent { Floor = LiftConstants.FirstFloor });
            _currentObserver.OnNext(new LiftEngineUpwardsEvent { Floor = LiftConstants.SecondFloor });
            _currentObserver.OnNext(new LiftEngineUpwardsEvent { Floor = LiftConstants.ThirdFloor });

            // Assert
            Assert.That(_liftStatuses.Count, Is.EqualTo(4));

            Assert.That(_liftStatuses[0].CurrentDirection, Is.EqualTo(Direction.Up));
            Assert.That(_liftStatuses[0].CurrentFloor, Is.EqualTo(LiftConstants.GroundFloor));

            Assert.That(_liftStatuses[1].CurrentDirection, Is.EqualTo(Direction.Up));
            Assert.That(_liftStatuses[1].CurrentFloor, Is.EqualTo(LiftConstants.FirstFloor));

            Assert.That(_liftStatuses[2].CurrentDirection, Is.EqualTo(Direction.Up));
            Assert.That(_liftStatuses[2].CurrentFloor, Is.EqualTo(LiftConstants.SecondFloor));

            Assert.That(_liftStatuses[3].CurrentDirection, Is.EqualTo(Direction.None));
            Assert.That(_liftStatuses[3].CurrentFloor, Is.EqualTo(LiftConstants.ThirdFloor));
        }