本文整理汇总了C#中CronExpression.IsSatisfiedBy方法的典型用法代码示例。如果您正苦于以下问题:C# CronExpression.IsSatisfiedBy方法的具体用法?C# CronExpression.IsSatisfiedBy怎么用?C# CronExpression.IsSatisfiedBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CronExpression
的用法示例。
在下文中一共展示了CronExpression.IsSatisfiedBy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCronExpressionParsingIncorrectDayOfWeek
public void TestCronExpressionParsingIncorrectDayOfWeek()
{
// test failed before because of improper trimming
try
{
string expr = string.Format(" * * * * * {0}", DateTime.Now.Year);
CronExpression ce = new CronExpression(expr);
ce.IsSatisfiedBy(DateTime.UtcNow.AddMinutes(2));
Assert.Fail("Accepted wrong format");
}
catch (FormatException fe)
{
Assert.AreEqual("Day-of-Week values must be between 1 and 7", fe.Message);
}
}
示例2: TestNthWeekDayPassingMonth
public void TestNthWeekDayPassingMonth()
{
CronExpression ce = new CronExpression("0 30 10-13 ? * FRI#3");
DateTime start = new DateTime(2008, 12, 19, 0, 0, 0);
for (int i = 0; i < 200; ++i)
{
bool shouldFire = (start.Hour >= 10 && start.Hour <= 13 && start.Minute == 30 && (start.DayOfWeek == DayOfWeek.Wednesday || start.DayOfWeek == DayOfWeek.Friday));
shouldFire = shouldFire && start.Day > 15 && start.Day < 28;
bool satisfied = ce.IsSatisfiedBy(start.ToUniversalTime());
Assert.AreEqual(shouldFire, satisfied);
// cycle with half hour precision
start = start.AddHours(0.5);
}
}
示例3: TestIsSatisfiedBy
public void TestIsSatisfiedBy()
{
CronExpression cronExpression = new CronExpression("0 15 10 * * ? 2005");
DateTime cal = new DateTime(2005, 6, 1, 10, 15, 0).ToUniversalTime();
Assert.IsTrue(cronExpression.IsSatisfiedBy(cal));
cal = cal.AddYears(1);
Assert.IsFalse(cronExpression.IsSatisfiedBy(cal));
cal = new DateTime(2005, 6, 1, 10, 16, 0).ToUniversalTime();
Assert.IsFalse(cronExpression.IsSatisfiedBy(cal));
cal = new DateTime(2005, 6, 1, 10, 14, 0).ToUniversalTime();
Assert.IsFalse(cronExpression.IsSatisfiedBy(cal));
cronExpression = new CronExpression("0 15 10 ? * MON-FRI");
// weekends
cal = new DateTime(2007, 6, 9, 10, 15, 0).ToUniversalTime();
Assert.IsFalse(cronExpression.IsSatisfiedBy(cal));
Assert.IsFalse(cronExpression.IsSatisfiedBy(cal.AddDays(1)));
}
示例4: TestLastDayOffset
public void TestLastDayOffset()
{
CronExpression cronExpression = new CronExpression("0 15 10 L-2 * ? 2010");
DateTime cal = new DateTime(2010, 10, 29, 10, 15, 0).ToUniversalTime(); // last day - 2
Assert.IsTrue(cronExpression.IsSatisfiedBy(cal));
cal = new DateTime(2010, 10, 28, 10, 15, 0).ToUniversalTime();
Assert.IsFalse(cronExpression.IsSatisfiedBy(cal));
cronExpression = new CronExpression("0 15 10 L-5W * ? 2010");
cal = new DateTime(2010, 10, 26, 10, 15, 0).ToUniversalTime(); // last day - 5
Assert.IsTrue(cronExpression.IsSatisfiedBy(cal));
cronExpression = new CronExpression("0 15 10 L-1 * ? 2010");
cal = new DateTime(2010, 10, 30, 10, 15, 0).ToUniversalTime(); // last day - 1
Assert.IsTrue(cronExpression.IsSatisfiedBy(cal));
cronExpression = new CronExpression("0 15 10 L-1W * ? 2010");
cal = new DateTime(2010, 10, 29, 10, 15, 0).ToUniversalTime(); // nearest weekday to last day - 1 (29th is a friday in 2010)
Assert.IsTrue(cronExpression.IsSatisfiedBy(cal));
}
示例5: TestCronExpressionWithExtraWhiteSpace
public void TestCronExpressionWithExtraWhiteSpace()
{
// test failed before because of improper trimming
string expr = " 30 * * * * ? ";
CronExpression calendar = new CronExpression(expr);
Assert.IsFalse(calendar.IsSatisfiedBy(DateTime.Now.AddMinutes(2)), "Time was included");
}