示例#1
0
 public void FromNow_2Days_2Days()
 {
     using (TimeReseter.Set(14.February(2007).In(2.Hours())))
     {
         Assert.That(2.Days().FromNow(), Is.EqualTo(16.February(2007).In(2.Hours())));
     }
 }
        public void MessageGrouping_SameSource_VerifyGrouping()
        {
            var subject = new MonitorWorkItem(new MonitorConfiguration())
                          .AddMessageGroupingPatterns(ExportIntegrationErrorsStep.MessageGroupingPattern);

            using (TimeReseter.SetUtc(new DateTimeOffset(2015, 06, 13, 12, 00, 00, TimeSpan.Zero)))
            {
                subject.Add(Time.UtcNow.AddHours(-2), "Source", "Message. ErrorID: 1");
                subject.Add(Time.UtcNow.AddHours(-1), "Source", "Message. ErrorID: 2");
                subject.Add(Time.UtcNow, "Source", "Message. ErrorID: 3");

                MonitorEntry[] entries = subject.GetEntries(Target.Service);

                Assert.That(entries.Length, Is.EqualTo(1));
                Assert.That(entries[0].DateTime, Is.EqualTo(Time.UtcNow));
                Assert.That(entries[0].Source, Is.EqualTo("Source"));
                Assert.That(entries[0].Message, Is.EqualTo(string.Join(Environment.NewLine,
                                                                       "Message. ErrorID: 3",
                                                                       string.Empty,
                                                                       "--- Additional similar entries (Total: 3) ---",
                                                                       string.Empty,
                                                                       "ErrorID: 2 (6/13/2015 11:00:00 AM +00:00)",
                                                                       "ErrorID: 1 (6/13/2015 10:00:00 AM +00:00)")));
            }
        }
示例#3
0
 public void Ago_TimeNowMinusTimeSpan()
 {
     using (TimeReseter.Set(10.February(2000).InUtc()))
     {
         Assert.That(2.Days().Ago(), Is.EqualTo(8.February(2000).InUtc()));
     }
 }
 public void UnixTimestamp_DateIsSecondOfJanuary1970_VerifyResult()
 {
     using (TimeReseter.Set(new DateTimeOffset(2.January(1970), TimeSpan.Zero)))
     {
         Assert.That(Time.UnixTimestamp, Is.EqualTo(3600d * 24));
     }
 }
 public void UnixTimestamp_DateIs13OfJune1984_VerifyResult()
 {
     using (TimeReseter.Set(13.June(1984).At(Time.Noon).InUtc()))
     {
         Assert.That(Time.UnixTimestamp, Is.EqualTo(455976000d));
     }
 }
 public void UnixTimestamp_DateIsFirstOfJanuary1970_VerifyResult()
 {
     using (TimeReseter.Set(Time.UnixEpoch))
     {
         Assert.That(Time.UnixTimestamp, Is.EqualTo(0d));
     }
 }
示例#7
0
 public void Elapsed_1DayFromNow_1Days()
 {
     using (TimeReseter.Set(10.February(2000).InUtc()))
     {
         TimeSpan passed = 11.February(2000).InUtc().Elapsed();
         Assert.That(passed, Is.EqualTo(1.Days()));
     }
 }
示例#8
0
        public void Set_DoesNotSetUtcNow()
        {
            var born = 11.March(1977);

            using (TimeReseter.Set(born))
            {
                Assert.That(Time.UtcNow.DateTime, Is.Not.EqualTo(born));
            }
        }
示例#9
0
        public void SetUtc_SetsUtcTime()
        {
            var born = 11.March(1977).InUtc();

            using (TimeReseter.SetUtc(born))
            {
                Assert.That(Time.UtcNow, Is.EqualTo(born));
            }
        }
示例#10
0
        public void Set_SetsTimeNow()
        {
            var born = 11.March(1977);

            using (TimeReseter.Set(born))
            {
                Assert.That(Time.Now.DateTime, Is.EqualTo(born));
            }
        }
示例#11
0
        public void SetUtc_SetsBackUtcTimeWhenDisposed()
        {
            var born    = 11.March(1977).InUtc();
            var reseter = TimeReseter.SetUtc(born);

            reseter.Dispose();
            DateTimeOffset timeNow = Time.UtcNow, dtNow = DateTimeOffset.UtcNow;

            Assert.That(timeNow - dtNow, Is.LessThan(Time.OneSecond));
        }
示例#12
0
        public void Explore()
        {
            using (CultureReseter.Set("da-DK"))
            {
                Assert.That(2001.IsLeapYear(), Is.False);
                Assert.That(25.October(2012).InUtc().Week(), Is.EqualTo(43));

                Assert.That(DayOfWeek.Monday.DaysTill(DayOfWeek.Thursday), Is.EqualTo(3));
                Assert.That(DayOfWeek.Monday.DaysSince(DayOfWeek.Friday), Is.EqualTo(3));
                Assert.That(/* Mon */ 16.June(2008).InUtc().Previous(DayOfWeek.Thursday),
                            Is.EqualTo(12.June(2008).InUtc() /* Thu */));
                Assert.That(/* Thu */ 12.June(2008).InUtc().Next(DayOfWeek.Monday), Is.EqualTo(16.June(2008).InUtc() /* Mon */));

                Assert.That(12.June(2008).At(15.Hours().Minutes(43).Seconds(10)).InUtc()
                            .BeginningOfDay(), Is.EqualTo(12.June(2008).At(Time.MidNight).InUtc()));
                Assert.That(12.June(2008).InUtc().BeginningOfWeek(), Is.EqualTo(9.June(2008).InUtc()));
                Assert.That(12.June(2008).InUtc().BeginningOf(Period.Year), Is.EqualTo(1.January(2008).InUtc()));
                Assert.That(12.June(2008).InUtc().EndOfWeek(), Is.EqualTo(15.June(2008).At(Time.EndOfDay).InUtc()));

                Assert.That(11.March(1977).InUtc().Difference(14.March(1977).InUtc()), Is.EqualTo(3.Days()));
                DateTimeOffset firstFebruary = 1.February(2008).InUtc(), fifthFebruary = 5.February(2008).InUtc();
                Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InAtLeast(2.Days()), Is.True);
                Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InAtMost(4.Days()), Is.True);
                Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InLessThan(1.Weeks()), Is.True);
                Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InMoreThan(Time.OneHour), Is.True);
                Assert.That(firstFebruary.DiffersFrom(firstFebruary).InNothing(), Is.True);
                Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InSomething(), Is.True);

                using (TimeReseter.Set(10.February(2000).At(Time.Noon).In(1.Hours())))
                {
                    Assert.That(2.Days().Ago(), Is.EqualTo(8.February(2000).At(Time.Noon).In(Time.Offset)));
                    Assert.That(2.Days().FromNow(), Is.EqualTo(12.February(2000).At(Time.Noon).In(Time.Offset)));
                    Assert.That(9.February(2000).In(Time.Offset).Elapsed(), Is.EqualTo(1.Days().Hours(12)));
                }

                Assert.That(TimeSpan.Zero.Describe(), Is.EqualTo("now"));
                Assert.That(59.Seconds().Describe(), Is.EqualTo("59 seconds"));
                Assert.That(1.Minutes().Seconds(1).Describe(), Is.EqualTo("about 1 minute"));
                Assert.That(3.Minutes().Seconds(31).Describe(), Is.EqualTo("about 4 minutes"));
                Assert.That(3.Hours().Minutes(3).Seconds(1).Describe(), Is.EqualTo("about 3 hours"));
                Assert.That(2.Days().Minutes(1).Seconds(1).Describe(), Is.EqualTo("about 2 days"));
                Assert.That(2.Days().Minutes(1).Seconds(1).AsLapseDescription(), Is.EqualTo("about 2 days ago"));

                Assert.That(1.January(2008).At(15.Hours()).AsOffset(3.Hours()),
                            Is.EqualTo(new DateTimeOffset(2008, 1, 1, 15, 0, 0, 3.Hours())));
                Assert.That(1.January(2008).At(15.Hours()).AsUtcOffset(),
                            Is.EqualTo(new DateTimeOffset(2008, 1, 1, 15, 0, 0, 0.Hours())));

                Assert.That(25.October(2012).At(15.Hours().Minutes(55)).InUtc().SetTime(15, 56, 0),
                            Is.EqualTo(25.October(2012).At(15.Hours().Minutes(56)).InUtc()));
            }
        }
示例#13
0
        public void AdventConstructor_TwoMonthsThreeDaysAgo_PropertiesSet()
        {
            DateTime now = _keyDateInHistory;

            using (TimeReseter.Set(now))
            {
                DateTime twoMonthsThreeDaysAgo = now.AddMonths(-2).AddDays(-3);
                var      subject = new Age(twoMonthsThreeDaysAgo);
                Assert.That(subject, Must.Be.Age()
                            .WithBounds(twoMonthsThreeDaysAgo, now)
                            .Elapsed(now - twoMonthsThreeDaysAgo)
                            .WithComponents(days: 3, weeks: 0, months: 2, years: 0));
            }
        }
示例#14
0
        public void AdventConstructor_OneWeekAgo_SetsTimeProperties()
        {
            DateTime now = _keyDateInHistory;

            using (TimeReseter.Set(now))
            {
                var subject = new Age(1.Weeks().Ago().DateTime);

                Assert.That(subject.Years, Is.EqualTo(0));
                Assert.That(subject.Months, Is.EqualTo(0));
                Assert.That(subject.Weeks, Is.EqualTo(1));
                Assert.That(subject.Days, Is.EqualTo(0));
            }
        }
示例#15
0
        public void AdventConstructor_OneWeekAgo_PropertiesSetTo1WeekAgo()
        {
            DateTime now = _keyDateInHistory;

            using (TimeReseter.Set(now))
            {
                DateTime oneWeekAgo = now.AddDays(-7);
                var      subject    = new Age(oneWeekAgo);

                Assert.That(subject, Must.Be.Age()
                            .WithBounds(advent: oneWeekAgo, terminus: now)
                            .Elapsed(1.Weeks())
                            .WithComponents(days: 0, weeks: 1, months: 0, years: 0));
            }
        }
示例#16
0
        public void AdventConstructor_OneDayAgo_PropertiesSetTo1DayAgo()
        {
            DateTime now = _keyDateInHistory;

            using (TimeReseter.Set(now))
            {
                DateTime yesterday = Time.Yesterday.DateTime;
                var      subject   = new Age(yesterday);

                Assert.That(subject, Must.Be.Age()
                            .WithBounds(advent: yesterday, terminus: now)
                            .Elapsed(1.Days())
                            .WithComponents(days: 1, weeks: 0, months: 0, years: 0));
            }
        }
示例#17
0
        public void Create_Archives_Delete_Expired()
        {
            string baseDirectory = Guid.NewGuid().ToString("N");

            try
            {
                var logger = Substitute.For <ILogger>();

                var subject = new FileBasedArchiveService(new InMemoryRuntimeSettings()
                                                          .Set(FileBasedArchiveService.BaseDirectoryKey, baseDirectory), logger);

                using (TimeReseter.SetUtc(new DateTimeOffset(2015, 9, 22, 12, 0, 0, TimeSpan.Zero)))
                {
                    subject.ArchiveText("Name", "Content", options => options
                                        .Named("Archive Name 1")
                                        .ExpiresAfterDays(1));

                    ArchiveCreated archive2 = subject.ArchiveText("Name", "Content", options => options
                                                                  .Named("Archive Name 2")
                                                                  .ExpiresOn(new DateTimeOffset(2015, 10, 1, 12, 0, 0, TimeSpan.Zero)));

                    Archive[] archives = subject.GetAll();
                    Assert.That(archives.Length, Is.EqualTo(2));

                    using (TimeReseter.SetUtc(new DateTimeOffset(2015, 9, 24, 0, 0, 0, TimeSpan.Zero)))
                    {
                        int expired = subject.DeleteExpired();

                        Assert.That(expired, Is.EqualTo(1));

                        archives = subject.GetAll();

                        Assert.That(archives.Length, Is.EqualTo(1));
                        Assert.That(archives[0].Id, Is.EqualTo(archive2.Id));
                        Assert.That(archives[0].Name, Is.EqualTo("Archive Name 2"));

                        // zip + meta file
                        Assert.That(Directory.EnumerateFiles(baseDirectory).Count(), Is.EqualTo(2));
                    }
                }
            }
            finally
            {
                Directory.Delete(baseDirectory, true);
            }
        }
示例#18
0
        public void SetUtc_NonUtcTime_Exception()
        {
            DateTimeOffset nonUtc = 11.March(1977).In(2.Hours());

            Assert.That(() => TimeReseter.SetUtc(nonUtc), Throws.InstanceOf <InvalidTimeZoneException>());
        }