Пример #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);
 }