Esempio n. 1
0
		public void ShouldFireChangeLightOnTimeExpiration()
		{
			bool lightChangedFired = false;

			MockStoplightTimer timer = new MockStoplightTimer();
			StoplightSchedule schedule = new StoplightSchedule(timer);
			schedule.ChangeLight += delegate { lightChangedFired = true; };

			timer.Expire();
			Assert.IsTrue(lightChangedFired);
		}
Esempio n. 2
0
		public void ShouldSetTimerDurationForNextLight()
		{
			MockStoplightTimer timer = new MockStoplightTimer();
			StoplightSchedule schedule = new StoplightSchedule(timer);
			TimeSpan greenSchedule = new TimeSpan(800);
			TimeSpan yellowSchedule = new TimeSpan(1500);
			TimeSpan redSchedule = new TimeSpan(100);
			schedule.Update(greenSchedule, yellowSchedule, redSchedule);

			timer.Expire();
			Assert.AreEqual(yellowSchedule, timer.Duration);
		}
Esempio n. 3
0
		public void ShouldLogOnForceChange()
		{
			MockStoplightTimer timer = new MockStoplightTimer();
			MockLogger logger = new MockLogger();
			StoplightSchedule schedule = new StoplightSchedule(timer);
			schedule.Logger = logger;
			TimeSpan greenSchedule = new TimeSpan(800);
			TimeSpan yellowSchedule = new TimeSpan(1500);
			TimeSpan redSchedule = new TimeSpan(100);
			schedule.Update(greenSchedule, yellowSchedule, redSchedule);

			schedule.ForceChange();
			Assert.IsNotNull(logger.LastMessage);
			Assert.IsTrue(logger.LastMessage.StartsWith("FORCED CHANGE"));
		}
Esempio n. 4
0
		public void ShouldFireEventAndUpdateScheduleOnForceChange()
		{
			MockStoplightTimer timer = new MockStoplightTimer();
			StoplightSchedule schedule = new StoplightSchedule(timer);
			TimeSpan greenSchedule = new TimeSpan(800);
			TimeSpan yellowSchedule = new TimeSpan(1500);
			TimeSpan redSchedule = new TimeSpan(100);
			schedule.Update(greenSchedule, yellowSchedule, redSchedule);

			bool eventFired = false;
			schedule.ChangeLight += delegate { eventFired = true; };

			schedule.ForceChange();
			Assert.IsTrue(eventFired);
			Assert.AreEqual(yellowSchedule, timer.Duration);
		}