示例#1
0
 public void ConstructionWithAdvance()
 {
     Instant instant = Instant.FromUnixTimeTicks(100L);
     Duration advance = Duration.FromTicks(5);
     FakeClock clock = new FakeClock(instant, advance);
     Assert.AreEqual(advance, clock.AutoAdvance);
     Assert.AreEqual(instant, clock.GetCurrentInstant());
     Assert.AreEqual(instant + advance, clock.GetCurrentInstant());
     Assert.AreEqual(instant + advance + advance, clock.GetCurrentInstant());
 }
示例#2
0
 public void ConstructionThenAdvance()
 {
     Instant instant = Instant.FromUnixTimeTicks(100L);
     FakeClock clock = new FakeClock(instant);
     Assert.AreEqual(instant, clock.GetCurrentInstant());
     Assert.AreEqual(instant, clock.GetCurrentInstant());
     Duration advance = Duration.FromTicks(5);
     clock.AutoAdvance = advance;
     // Setting auto-advance doesn't actually change the clock...
     // but this call will.
     Assert.AreEqual(instant, clock.GetCurrentInstant());
     Assert.AreEqual(instant + advance, clock.GetCurrentInstant());
     Assert.AreEqual(instant + advance + advance, clock.GetCurrentInstant());
 }
示例#3
0
 public void Advance()
 {
     FakeClock clock = new FakeClock(Instant.FromUnixTimeTicks(100L));
     Duration d = Duration.FromTicks(25);
     clock.Advance(d);
     Assert.AreEqual(125, clock.GetCurrentInstant().ToUnixTimeTicks());
 }
示例#4
0
 public void GetCurrent()
 {
     var julian = CalendarSystem.Julian;
     FakeClock underlyingClock = new FakeClock(NodaConstants.UnixEpoch);
     ZonedClock zonedClock = underlyingClock.InZone(SampleZone, julian);
     Assert.AreEqual(NodaConstants.UnixEpoch, zonedClock.GetCurrentInstant());
     Assert.AreEqual(new ZonedDateTime(underlyingClock.GetCurrentInstant(), SampleZone, julian),
         zonedClock.GetCurrentZonedDateTime());
     Assert.AreEqual(new LocalDateTime(1969, 12, 19, 2, 0, julian), zonedClock.GetCurrentLocalDateTime());
     Assert.AreEqual(new LocalDateTime(1969, 12, 19, 2, 0, julian).WithOffset(Offset.FromHours(2)),
         zonedClock.GetCurrentOffsetDateTime());
     Assert.AreEqual(new LocalDate(1969, 12, 19, julian), zonedClock.GetCurrentDate());
     Assert.AreEqual(new LocalTime(2, 0, 0), zonedClock.GetCurrentTimeOfDay());
 }
示例#5
0
 public void AdvanceSeconds()
 {
     FakeClock clock = new FakeClock(Instant.FromUnixTimeTicks(100L));
     clock.AdvanceSeconds(3);
     Assert.AreEqual(100 + 3 * NodaConstants.TicksPerSecond, clock.GetCurrentInstant().ToUnixTimeTicks());
 }
示例#6
0
 public void AdvanceTicks()
 {
     FakeClock clock = new FakeClock(Instant.FromUnixTimeTicks(100L));
     clock.AdvanceTicks(3);
     Assert.AreEqual(103, clock.GetCurrentInstant().ToUnixTimeTicks());
 }
示例#7
0
 public void DirectConstruction()
 {
     Instant instant = Instant.FromUnixTimeTicks(100L);
     FakeClock clock = new FakeClock(instant);
     Assert.AreEqual(instant, clock.GetCurrentInstant());
 }
示例#8
0
 public void Reset()
 {
     Instant instant1 = Instant.FromUnixTimeTicks(100L);
     Instant instant2 = Instant.FromUnixTimeTicks(500L);
     FakeClock clock = new FakeClock(instant1);
     Assert.AreEqual(instant1, clock.GetCurrentInstant());
     clock.Reset(instant2);
     Assert.AreEqual(instant2, clock.GetCurrentInstant());
 }
示例#9
0
 public void AdvanceMilliseconds()
 {
     FakeClock clock = new FakeClock(Instant.FromTicksSinceUnixEpoch(100L));
     clock.AdvanceMilliseconds(3);
     Assert.AreEqual(100 + 3 * NodaConstants.TicksPerMillisecond, clock.GetCurrentInstant().Ticks);
 }
示例#10
0
 public void AdvanceTicks()
 {
     FakeClock clock = new FakeClock(Instant.FromTicksSinceUnixEpoch(100L));
     clock.AdvanceTicks(3);
     Assert.AreEqual(103, clock.GetCurrentInstant().Ticks);
 }