예제 #1
0
        public void Should_have_saved_current_level(Level expectedLevel)
        {
            if (storedCurrentLevel == null) throw new Exception("No level stored yet");
            var errorMessage = string.Format("Expected {0}, but was {1}", expectedLevel, storedCurrentLevel);

            if (!storedCurrentLevel.Equals(expectedLevel)) throw new Exception(errorMessage);
        }
예제 #2
0
 public void Setup()
 {
     level1 = new Level(1, "");
     level1Copy = new Level(1, "");
     level2 = new Level(2, "");
     nullLevel = null;
 }
예제 #3
0
파일: Lift.cs 프로젝트: goeran/Elevator
        public void AddLevel(Level level)
        {
            if (level == null) throw new ArgumentNullException();
            if (levels.ContainsKey(level.Number)) throw new ArgumentException("Level already exists");

            levels.Add(level.Number, level);
            Announce("Level loaded: {0}, {1}", level.Number, level.Description);
        }
예제 #4
0
            public void It_ignore_comment_when_checking_equality()
            {
                var level1 = new Level(1, "level 1");
                var level1Copy = new Level(1, "level 1 copy");

                Assert.IsTrue(level1.Equals(level1Copy));
                Assert.AreEqual(level1Copy, level1);
            }
예제 #5
0
파일: Lift.cs 프로젝트: goeran/Elevator
        public void Start()
        {
            if (!levels.Any()) throw new InvalidOperationException("At least one level must be specified before the lift can be started");

            isStarted = true;
            if (levelDataStorage.HasStoredLevelInfo())
            {
                var storedLevel = levelDataStorage.GetCurrentLevel();
                CurrentLevel = levels[storedLevel.Number];
                AnnounceStart();
            }
            else
            {
                CurrentLevel = levels.First().Value;
                AnnounceStart();
                LiftUp();
            }
        }
예제 #6
0
        public void SaveCurrentLevel(Level level)
        {
            GuardForInitialized();
            var levelDto = new LevelDTO()
            {
                LevelNumber = level.Number,
                Description = level.Description
            };

            var existingLevelsWithSameNumber = elevatorCollection.Find(Query.EQ("LevelNumber", level.Number));
            if (existingLevelsWithSameNumber.Any())
            {
                var existingLevel = existingLevelsWithSameNumber.First();
                existingLevel.Description = level.Description;
                elevatorCollection.Save(existingLevel);
            }
            else
            {
                elevatorCollection.Save(levelDto);
            }
        }
예제 #7
0
            public void It_will_call_up_on_the_level_object()
            {
                var hasCalledUpDelegate = false;
                var level1 = new Level(1, "");
                var level2 = new Level(2, "", () => { hasCalledUpDelegate = true; });
                mocked.storage.StubGetCurrentLevelAndReturn(level1);
                lift.AddLevel(level1, level2);
                lift.Start();

                lift.Up();

                Assert.IsTrue(hasCalledUpDelegate, "Expected up to be called on level object");
            }
예제 #8
0
            public void It_will_announce_going_up()
            {
                var level1 = new Level(1, "level 1");
                var level2 = new Level(2, "level 2");
                lift.AddLevel(level1, level2);
                lift.Start();

                lift.Up();

                mocked.logger.Should_contain_entry("Arrived at [Level Number=2, Description=level 2]");
            }
예제 #9
0
            public void It_will_not_store_level_if_lift_fails()
            {
                var level1 = new Level(1, "", () => { throw new Exception("Something happened"); });
                lift.AddLevel(level1);

                lift.Start();

                mocked.storage.Should_not_have_saved_current_level();
            }
예제 #10
0
            public void It_will_announce_going_up()
            {
                var level1 = new Level(1, "");
                lift.AddLevel(level1);

                lift.Start();

                mocked.logger.Should_contain_entry("Arrived at [Level Number=1, Description=]");
            }
예제 #11
0
            public void It_will_set_current_level()
            {
                var level1 = new Level(1, "ground level");
                lift.AddLevel(level1);

                lift.Start();

                Assert.AreEqual(level1, lift.CurrentLevel);
            }
예제 #12
0
            public void It_will_not_store_level_if_lift_fails()
            {
                var level1 = new Level(1, "");
                var level2 = new Level(2, "", () => { throw new Exception("Could not lift"); });
                lift.AddLevel(level1, level2);
                lift.Start();

                lift.Start();

                mocked.storage.Should_have_saved_current_level(new Level(1, ""));
            }
예제 #13
0
 public void StubGetCurrentLevelAndReturn(Level stubbedCurrentLevel)
 {
     this.stubbedCurrentLevel = stubbedCurrentLevel;
 }
예제 #14
0
 public void SaveCurrentLevel(Level level)
 {
     storedCurrentLevel = level;
 }
예제 #15
0
            public void It_will_go_to_next_level()
            {
                var level1 = new Level(1, "");
                var level2 = new Level(2, "");
                lift.AddLevel(level1, level2);
                lift.Start();

                lift.Up();

                Assert.AreEqual(level2, lift.CurrentLevel);
            }
예제 #16
0
 public void It_should_set_Description_property()
 {
     var level = new Level(1, "initial schema");
     Assert.AreEqual("initial schema", level.Description);
 }
예제 #17
0
            public void It_will_handle_elevators_with_only_one_level()
            {
                var upCallCount = 0;
                var groundLevel = new Level(0, "The only level", () => upCallCount++);
                lift.AddLevel(groundLevel);
                lift.Start();
                mocked.storage.StubHasStoredLevelInfoAndReturn(true);

                lift.Up();

                Assert.AreEqual(1, upCallCount);
            }
예제 #18
0
 public void It_should_set_Number_property()
 {
     var level = new Level(1, "description");
     Assert.AreEqual(1, level.Number);
 }
예제 #19
0
            public void It_will_throw_exception_when_going_over_top_level()
            {
                var level1 = new Level(1, "");
                var level2 = new Level(2, "");
                lift.AddLevel(level1, level2);
                lift.Start();

                lift.Up();
                lift.Up();
            }
 public void SaveCurrentLevel(Level level)
 {
 }
예제 #21
0
            public void It_will_update_current_level_to_be_the_lowest_level()
            {
                var levelMinus1 = new Level(-1, "");
                var level1 = new Level(1, "");
                var level2 = new Level(2, "");
                lift.AddLevel(levelMinus1, level1, level2);

                lift.Start();

                Assert.AreEqual(levelMinus1, lift.CurrentLevel);
            }
예제 #22
0
            public void It_will_go_up_all_the_levels()
            {
                var level1Visited = 0;
                var level2Visited = 0;
                var level3Visited = 0;
                var level1 = new Level(1, "", () => level1Visited++);
                var level2 = new Level(2, "", () => level2Visited++);
                var level3 = new Level(3, "", () => level3Visited++);
                lift.AddLevel(level1, level2, level3);
                lift.Start();

                lift.Top();

                Assert.AreEqual(1, level1Visited, "Expected level 1 to be visited");
                Assert.AreEqual(1, level2Visited, "Expected level 2 to be visited");
                Assert.AreEqual(1, level3Visited, "Expected level 3 to be visited");
            }
예제 #23
0
            public void It_will_call_up_on_the_level_object()
            {
                var hasCalledUpDelegate = false;
                var level1 = new Level(1, "", () => { hasCalledUpDelegate = true; });
                lift.AddLevel(level1);

                lift.Start();

                Assert.IsTrue(hasCalledUpDelegate, "Expected up to be called on level object");
            }
예제 #24
0
            public void Setup()
            {
                level1VisitedCount = 0;
                level2VisitedCount = 0;
                level3VisitedCount = 0;
                level4VisitedCount = 0;
                level1 = new Level(1, "", () => level1VisitedCount++);
                level2 = new Level(2, "", () => level2VisitedCount++);
                level3 = new Level(3, "", () => level3VisitedCount++);
                level4 = new Level(4, "", () => level4VisitedCount++);
                lift.AddLevel(level1, level2, level3, level4);
                mocked.storage.StubHasStoredLevelInfoAndReturn(true);
                mocked.storage.StubGetCurrentLevelAndReturn(level2);
                lift.Start();

                lift.Top();
            }
예제 #25
0
            public void It_will_announce_the_failed_lift()
            {
                var level1 = new Level(1, "init setup", () => { throw new Exception("Failed because db is down"); });
                lift.AddLevel(level1);

                lift.Start();

                mocked.logger.Should_contain_entry("Failed to lift: Level 1, init setup");
                mocked.logger.Last_entry_should_start_with("System.Exception: Failed because db is down");
            }
예제 #26
0
파일: Lift.cs 프로젝트: goeran/Elevator
 private void PrepareLiftToNextLevel()
 {
     var currentLevelNumber = levels.IndexOfValue(CurrentLevel);
     if (levels.Count > 1 && currentLevelNumber >= levels.Count - 1) throw new InvalidOperationException("On the top level");
     var newCurrentLevelNumber = ++currentLevelNumber;
     if (newCurrentLevelNumber < levels.Count)
     {
         CurrentLevel = levels.ElementAt(newCurrentLevelNumber).Value;
     }
 }