pszczyg

Untitled

Jun 30th, 2017
286
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     [TestFixture]
  2.     public class DateTimeProviderTests
  3.     {
  4.         [Test]
  5.         public void Meters_Are_Checked_In_Desired_Time()
  6.         {
  7.             //Sets current time to 2016/05/05 21:34:00
  8.             var dateTimeMock = new TestDateTimeProvider(new DateTime(2016, 5, 5, 21, 34, 00));
  9.             var meterLoader = new Mock<IAmActiveMetersLoader>();
  10.             var sut = new SystemTimeDependendProductionCode(meterLoader.Object);
  11.  
  12.             sut.DoPeriodicCheckIfNeeded();
  13.  
  14.             //System check should occur after 22:00, so at 21:34 there should
  15.             //be no invocations of ReloadAllActiveMeters
  16.             meterLoader.Verify(x => x.ReloadAllActiveMeters(), Times.Exactly(0));
  17.  
  18.             //We're moving time forward, to the threshold hour: 22:00
  19.             dateTimeMock.Now = new DateTime(2016, 5, 5, 22, 00, 00);
  20.             sut.DoPeriodicCheckIfNeeded();
  21.             //Still, no invocation should occur
  22.             meterLoader.Verify(x => x.ReloadAllActiveMeters(), Times.Exactly(0));
  23.  
  24.             //Minute after 22:00
  25.             dateTimeMock.Now = new DateTime(2016, 5, 5, 22, 01, 00);
  26.             sut.DoPeriodicCheckIfNeeded();
  27.             //Method should be called
  28.             meterLoader.Verify(x => x.ReloadAllActiveMeters(), Times.Exactly(1));
  29.         }
  30.     }
RAW Paste Data