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); }
public void Setup() { level1 = new Level(1, ""); level1Copy = new Level(1, ""); level2 = new Level(2, ""); nullLevel = null; }
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); }
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); }
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(); } }
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); } }
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"); }
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]"); }
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(); }
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=]"); }
public void It_will_set_current_level() { var level1 = new Level(1, "ground level"); lift.AddLevel(level1); lift.Start(); Assert.AreEqual(level1, lift.CurrentLevel); }
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, "")); }
public void StubGetCurrentLevelAndReturn(Level stubbedCurrentLevel) { this.stubbedCurrentLevel = stubbedCurrentLevel; }
public void SaveCurrentLevel(Level level) { storedCurrentLevel = level; }
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); }
public void It_should_set_Description_property() { var level = new Level(1, "initial schema"); Assert.AreEqual("initial schema", level.Description); }
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); }
public void It_should_set_Number_property() { var level = new Level(1, "description"); Assert.AreEqual(1, level.Number); }
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) { }
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); }
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"); }
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"); }
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(); }
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"); }
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; } }