Advertisement
pszczyg

Untitled

Jun 29th, 2017
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. [TestFixture]
  2.     public class SystemTimeTests
  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.             SystemTime.SetNow(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.  
  19.             //We're moving time forward, to the threshold hour: 22:00
  20.             SystemTime.SetNow(new DateTime(2016, 5, 5, 22, 00, 00));
  21.             sut.DoPeriodicCheckIfNeeded();
  22.             //Still, no invocation should occur
  23.             meterLoader.Verify(x => x.ReloadAllActiveMeters(), Times.Exactly(0));
  24.  
  25.             //Minute after 22:00
  26.             SystemTime.SetNow(new DateTime(2016, 5, 5, 22, 01, 00));
  27.             sut.DoPeriodicCheckIfNeeded();
  28.             //Method should be called
  29.             meterLoader.Verify(x => x.ReloadAllActiveMeters(), Times.Exactly(1));
  30.  
  31.             //Clean up in order to conduct other tests
  32.             SystemTime.ResetNow();
  33.         }
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement