Esempio n. 1
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());
 }
Esempio n. 2
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());
 }
        public void when_not_on_a_market_day_do_thing2() {
            var clock = new FakeClock(
                Instant.FromUtc(2016, 5, 8, 0, 0));
            var stock = new Stock();
            var marketDay = new MarketDay(
                Instant.FromUtc(2016, 5, 8, 0, 0));

            var myClass = new MyClassNodaTime(stock, marketDay, clock);

            Assert.Equal("Thing2 done!", myClass.thingState);
        }
        public void LogCorrectValue()
        {
            var clock = new FakeClock(Instant.FromDateTimeOffset(DateTimeOffset.Now));
            var logger = Substitute.For<ILogger>();
            var client = Substitute.For<IRestClient>();

            var job = new Jobs.CheckInJob(clock, logger, client);
            job.CheckIn();

            logger.Received().Information(Arg.Is("Sending Payload @ {now}"), Arg.Is(clock.Now));
        }
        public void PostRestPayload()
        {
            var clock = new FakeClock(Instant.FromDateTimeOffset(DateTimeOffset.Now));
            var logger = Substitute.For<ILogger>();
            var client = Substitute.For<IRestClient>();
            client.BaseUrl = new Uri("http://localhost");

            var job = new Jobs.CheckInJob(clock, logger, client);
            job.CheckIn();

            client.ReceivedWithAnyArgs().Post<Payload>(new RestRequest("/hello"));
        }
Esempio n. 6
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());
 }
Esempio n. 7
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());
 }
        public void GetArpVerificationStatus_CalledWith_ReturnsArpVerificationStatusVerifyingArp()
        {
            

            var london = TimeZones.London;
            var hongKong = TimeZones.HongKong;

            var londonInstant = Instant.FromUtc(2016, 1, 20, 23, 15, 0);


            //Assume that using Instant.FromUtc() will always return expected value
            //test that dates running on hongkong servers have the correct offsets applied
            //Write simpleapplication and log all values run simultaneously on hongKong and UK servers
            //Ultimately we want to be able store datetimes as a utc value and be able to represent that datime with deisred offset,
            //Such that if a user wave workflow is to perform a date calculation it should do so accounting for the offset, in the current environment
            //Is it important that when chcking on weekends we ensure that the right offset is used basd on the waveuser/colleagues TimeZone
            //i.e. Friday 23:00 for a colleague in London (Not a weekend day) would be Saturday 07:00 in Hong Kong (is a weekend day)
            var utc = _now.InUtc();

            var hongKongOffset = hongKong.GetUtcOffset(londonInstant);
            Duration hongKongDuration = Duration.FromTicks(hongKongOffset.Ticks);

            var londonOffset = london.GetUtcOffset(londonInstant);
            Duration londonDuration = Duration.FromTicks(londonOffset.Ticks);

            ZonedDateTime londonInstantZonedDateTime = londonInstant.InUtc();

            ZonedDateTime hongKongInstantZonedDateTime = londonInstantZonedDateTime + hongKongDuration;



            //var r = hongKong.ResolveLocal(londonInstantZonedDateTime.LocalDateTime);
            var localDate = new LocalDateTime(2016, 1, 20, 22, 29, 0);

            var londonLocalDateTime = london.AtStrictly(localDate);
            
            //var hongKongLocalDateTime = hongKong.GetUtcOffset(aTimeStamp);//hongKong.AtLeniently(localDate) + hongKong.GetUtcOffset();
            var systemClock = new FakeClock(Instant.FromUtc(2016, 1, 20, 23, 15, 0), Duration.FromStandardDays(10));

            var service = new ArpVerificationStatusService(systemClock);

            ZonedDateTime nowInIsoUtc = systemClock.Now.InUtc();
            var nowInIsoUtcPlusTenDays = service.SendExpiryNotifications();

            var period = Period.Between(nowInIsoUtc.LocalDateTime, nowInIsoUtcPlusTenDays.LocalDateTime, PeriodUnits.Days);

            Assert.AreEqual(period.Days, 10);
        }
Esempio n. 9
0
        public void TryKeepAlive_Should_Return_Correct_Lag_Value()
        {
            const int AccountId = 1;
            var clock = new FakeClock(SystemClock.Instance.Now);
            var service = CreateAccountService(clock);

            int sessionId;
            service.TryRegisterSession(AccountId, out sessionId);

            TimeSpan lag;
            service.TryKeepAlive(AccountId, out lag);
            clock.AdvanceSeconds(15);
            service.TryKeepAlive(AccountId, out lag);

            lag.Duration().Should().Be(TimeSpan.FromSeconds(15));
        }
Esempio n. 10
0
 public void AdvanceSeconds()
 {
     FakeClock clock = new FakeClock(Instant.FromUnixTimeTicks(100L));
     clock.AdvanceSeconds(3);
     Assert.AreEqual(100 + 3 * NodaConstants.TicksPerSecond, clock.GetCurrentInstant().ToUnixTimeTicks());
 }
Esempio n. 11
0
 public void AdvanceTicks()
 {
     FakeClock clock = new FakeClock(Instant.FromUnixTimeTicks(100L));
     clock.AdvanceTicks(3);
     Assert.AreEqual(103, clock.GetCurrentInstant().ToUnixTimeTicks());
 }
Esempio n. 12
0
 public void DirectConstruction()
 {
     Instant instant = Instant.FromUnixTimeTicks(100L);
     FakeClock clock = new FakeClock(instant);
     Assert.AreEqual(instant, clock.GetCurrentInstant());
 }
Esempio n. 13
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());
 }
Esempio n. 14
0
 public void AdvanceMilliseconds()
 {
     FakeClock clock = new FakeClock(Instant.FromTicksSinceUnixEpoch(100L));
     clock.AdvanceMilliseconds(3);
     Assert.AreEqual(100 + 3 * NodaConstants.TicksPerMillisecond, clock.GetCurrentInstant().Ticks);
 }
Esempio n. 15
0
 public void AdvanceTicks()
 {
     FakeClock clock = new FakeClock(Instant.FromTicksSinceUnixEpoch(100L));
     clock.AdvanceTicks(3);
     Assert.AreEqual(103, clock.GetCurrentInstant().Ticks);
 }
Esempio n. 16
0
        public void TryRegisterSession_Should_Initialize_Session_KeepAlive_Correctly()
        {
            const int AccountId = 1;
            var clock = new FakeClock(SystemClock.Instance.Now);
            var service = CreateAccountService(clock);

            int sessionId;
            service.TryRegisterSession(AccountId, out sessionId);

            TimeSpan lag;
            service.TryKeepAlive(AccountId, out lag);

            lag.Duration().Should().Be(TimeSpan.Zero);
        }