Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bradymholt committed Mar 27, 2012
1 parent d448f7d commit 124bf2a
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 260 deletions.
6 changes: 3 additions & 3 deletions CronExpressionDescriptor.Test/TestCasing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ public class TestCasing
public void TestSentenceCasing()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("* * * * *", new Options() { CasingType = CasingTypeEnum.Sentence });
Assert.AreEqual("Every minute", ceh.GetDescription());
Assert.AreEqual("Every minute", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestTitleCasing()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("* * * * *", new Options() { CasingType = CasingTypeEnum.Title });
Assert.AreEqual("Every Minute", ceh.GetDescription());
Assert.AreEqual("Every Minute", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestLowerCasing()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("* * * * *", new Options() { CasingType = CasingTypeEnum.LowerCase });
Assert.AreEqual("every minute", ceh.GetDescription());
Assert.AreEqual("every minute", ceh.GetDescription(DescriptionTypeEnum.FULL));
}
}
}
16 changes: 8 additions & 8 deletions CronExpressionDescriptor.Test/TestExceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void TestNullCronExpressionException()
{
Options options = new Options() { ThrowExceptionOnParseError = true };
ExpressionDescriptor ceh = new ExpressionDescriptor(null, options);
ceh.GetDescription();
ceh.GetDescription(DescriptionTypeEnum.FULL);
}

[TestMethod]
Expand All @@ -24,16 +24,16 @@ public void TestEmptyCronExpressionException()
{
Options options = new Options() { ThrowExceptionOnParseError = true };
ExpressionDescriptor ceh = new ExpressionDescriptor(null, options);
ceh.GetDescription();
ceh.GetDescription(DescriptionTypeEnum.FULL);
}

[TestMethod]
public void TestNullCronExpressionError()
{
Options options = new Options() { ThrowExceptionOnParseError = false };
ExpressionDescriptor ceh = new ExpressionDescriptor(null, options);
string description = ceh.GetDescription();
Assert.AreEqual("Error: Expression is missing.", ceh.GetDescription());
string description = ceh.GetDescription(DescriptionTypeEnum.FULL);
Assert.AreEqual("Field 'ExpressionDescriptor.expression' not found.", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
Expand All @@ -42,16 +42,16 @@ public void TestInvalidCronExpressionException()
{
Options options = new Options() { ThrowExceptionOnParseError = true };
ExpressionDescriptor ceh = new ExpressionDescriptor("INVALID", options);
ceh.GetDescription();
ceh.GetDescription(DescriptionTypeEnum.FULL);
}

[TestMethod]
public void TestInvalidCronExpressionError()
{
Options options = new Options() { ThrowExceptionOnParseError = false };
ExpressionDescriptor ceh = new ExpressionDescriptor("INVALID CRON", options);
string description = ceh.GetDescription();
Assert.AreEqual("Error: Expression only has 2 parts. At least 5 part are required.", ceh.GetDescription());
string description = ceh.GetDescription(DescriptionTypeEnum.FULL);
Assert.AreEqual("Error: Expression only has 2 parts. At least 5 part are required.", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
Expand All @@ -60,7 +60,7 @@ public void TestInvalidSyntaxException()
{
Options options = new Options() { ThrowExceptionOnParseError = true };
ExpressionDescriptor ceh = new ExpressionDescriptor("* $ * * *", options);
string description = ceh.GetDescription();
string description = ceh.GetDescription(DescriptionTypeEnum.FULL);
}
}
}
74 changes: 37 additions & 37 deletions CronExpressionDescriptor.Test/TestFormats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,251 +14,251 @@ public class TestFormats
public void TestEveryMinute()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("* * * * *");
Assert.AreEqual("Every minute", ceh.GetDescription());
Assert.AreEqual("Every minute", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestEvery1Minute()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("*/1 * * * *");
Assert.AreEqual("Every minute", ceh.GetDescription());
Assert.AreEqual("Every minute", ceh.GetDescription(DescriptionTypeEnum.FULL));

ceh = new ExpressionDescriptor("0 0/1 * * * ?");
Assert.AreEqual("Every minute", ceh.GetDescription());
Assert.AreEqual("Every minute", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestEveryHour()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("0 0 * * * ?");
Assert.AreEqual("Every hour", ceh.GetDescription());
Assert.AreEqual("Every hour", ceh.GetDescription(DescriptionTypeEnum.FULL));

ceh = new ExpressionDescriptor("0 0 0/1 * * ?");
Assert.AreEqual("Every hour", ceh.GetDescription());
Assert.AreEqual("Every hour", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestTimeOfDayCertainDaysOfWeek()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("0 23 ? * MON-FRI");
Assert.AreEqual("At 11:00 PM, Monday through Friday", ceh.GetDescription());
Assert.AreEqual("At 11:00 PM, Monday through Friday", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestEverySecond()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("* * * * * *");
Assert.AreEqual("Every second", ceh.GetDescription());
Assert.AreEqual("Every second", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestEvery45Seconds()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("*/45 * * * * *");
Assert.AreEqual("Every 45 seconds", ceh.GetDescription());
Assert.AreEqual("Every 45 seconds", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestEvery5Minutes()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("*/5 * * * *");
Assert.AreEqual("Every 05 minutes", ceh.GetDescription());
Assert.AreEqual("Every 05 minutes", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestEvery5MinutesOnTheSecond()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("0 */5 * * * *");
Assert.AreEqual("Every 05 minutes", ceh.GetDescription());
Assert.AreEqual("Every 05 minutes", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestWeekdaysAtTime()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("30 11 * * 1-5");
Assert.AreEqual("At 11:30 AM, Monday through Friday", ceh.GetDescription());
Assert.AreEqual("At 11:30 AM, Monday through Friday", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestDailyAtTime()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("30 11 * * *");
Assert.AreEqual("At 11:30 AM", ceh.GetDescription());
Assert.AreEqual("At 11:30 AM", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestMinuteSpan()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("0-10 11 * * *");
Assert.AreEqual("Every minute between 11:00 AM and 11:10 AM", ceh.GetDescription());
Assert.AreEqual("Every minute between 11:00 AM and 11:10 AM", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestOneMonthOnly()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("* * * 3 *");
Assert.AreEqual("Every minute, only in March", ceh.GetDescription());
Assert.AreEqual("Every minute, only in March", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestTwoMonthsOnly()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("* * * 3,6 *");
Assert.AreEqual("Every minute, only in March and June", ceh.GetDescription());
Assert.AreEqual("Every minute, only in March and June", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestTwoTimesEachAfternoon()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("30 14,16 * * *");
Assert.AreEqual("At 02:30 PM and 04:30 PM", ceh.GetDescription());
Assert.AreEqual("At 02:30 PM and 04:30 PM", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestThreeTimesDaily()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("30 6,14,16 * * *");
Assert.AreEqual("At 06:30 AM, 02:30 PM and 04:30 PM", ceh.GetDescription());
Assert.AreEqual("At 06:30 AM, 02:30 PM and 04:30 PM", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestOnceAWeek()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("46 9 * * 1");
Assert.AreEqual("At 09:46 AM, only on Monday", ceh.GetDescription());
Assert.AreEqual("At 09:46 AM, only on Monday", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestDayOfMonth()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("23 12 15 * *");
Assert.AreEqual("At 12:23 PM, on day 15 of the month", ceh.GetDescription());
Assert.AreEqual("At 12:23 PM, on day 15 of the month", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestMonthName()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("23 12 * JAN *");
Assert.AreEqual("At 12:23 PM, only in January", ceh.GetDescription());
Assert.AreEqual("At 12:23 PM, only in January", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestDayOfMonthWithQuestionMark()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("23 12 ? JAN *");
Assert.AreEqual("At 12:23 PM, only in January", ceh.GetDescription());
Assert.AreEqual("At 12:23 PM, only in January", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestMonthNameRange2()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("23 12 * JAN-FEB *");
Assert.AreEqual("At 12:23 PM, January through February", ceh.GetDescription());
Assert.AreEqual("At 12:23 PM, January through February", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestMonthNameRange3()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("23 12 * JAN-MAR *");
Assert.AreEqual("At 12:23 PM, January through March", ceh.GetDescription());
Assert.AreEqual("At 12:23 PM, January through March", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestDayOfWeekName()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("23 12 * * SUN");
Assert.AreEqual("At 12:23 PM, only on Sunday", ceh.GetDescription());
Assert.AreEqual("At 12:23 PM, only on Sunday", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestDayOfWeekRange()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("*/5 15 * * MON-FRI");
Assert.AreEqual("Every 05 minutes, at 03:00 PM, Monday through Friday", ceh.GetDescription());
Assert.AreEqual("Every 05 minutes, at 03:00 PM, Monday through Friday", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestDayOfWeekOnceInMonth()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("* * * * MON#3");
Assert.AreEqual("Every minute, on the third Monday of the month", ceh.GetDescription());
Assert.AreEqual("Every minute, on the third Monday of the month", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestLastDayOfTheWeekOfTheMonth()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("* * * * 4L");
Assert.AreEqual("Every minute, on the last Thursday of the month", ceh.GetDescription());
Assert.AreEqual("Every minute, on the last Thursday of the month", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestLastDayOfTheMonth()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("*/5 * L JAN *");
Assert.AreEqual("Every 05 minutes, on the last day of the month, only in January", ceh.GetDescription());
Assert.AreEqual("Every 05 minutes, on the last day of the month, only in January", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestTimeOfDayWithSeconds()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("30 02 14 * * *");
Assert.AreEqual("At 02:02:30 PM", ceh.GetDescription());
Assert.AreEqual("At 02:02:30 PM", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestSecondInternvals()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("5-10 * * * * *");
Assert.AreEqual("Seconds 05 through 10 past the minute", ceh.GetDescription());
Assert.AreEqual("Seconds 05 through 10 past the minute", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestSecondMinutesHoursIntervals()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("5-10 30-35 10-12 * * *");
Assert.AreEqual("Seconds 05 through 10 past the minute, minutes 30 through 35 past the hour, between 10:00 AM and 12:00 PM", ceh.GetDescription());
Assert.AreEqual("Seconds 05 through 10 past the minute, minutes 30 through 35 past the hour, between 10:00 AM and 12:00 PM", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestEvery5MinutesAt30Seconds()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("30 */5 * * * *");
Assert.AreEqual("At 30 seconds past the minute, every 05 minutes", ceh.GetDescription());
Assert.AreEqual("At 30 seconds past the minute, every 05 minutes", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestMinutesPastTheHourRange()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("0 30 10-13 ? * WED,FRI");
Assert.AreEqual("At 30 minutes past the hour, between 10:00 AM and 01:00 PM, only on Wednesday and Friday", ceh.GetDescription());
Assert.AreEqual("At 30 minutes past the hour, between 10:00 AM and 01:00 PM, only on Wednesday and Friday", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestSecondsPastTheMinuteInterval()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("10 0/5 * * * ?");
Assert.AreEqual("At 10 seconds past the minute, every 05 minutes", ceh.GetDescription());
Assert.AreEqual("At 10 seconds past the minute, every 05 minutes", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestBetweenWithInterval()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("2-59/3 1,9,22 11-26 1-6 ?");
Assert.AreEqual("Every 03 minutes, minutes 02 through 59 past the hour, at 01:00 AM, 09:00 AM, and 10:00 PM, between day 11 and 26 of the month, January through June", ceh.GetDescription());
Assert.AreEqual("Every 03 minutes, minutes 02 through 59 past the hour, at 01:00 AM, 09:00 AM, and 10:00 PM, between day 11 and 26 of the month, January through June", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestRecurringFirstOfMonth()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("0 0 6 1/1 * ?");
Assert.AreEqual("At 06:00 AM", ceh.GetDescription());
Assert.AreEqual("At 06:00 AM", ceh.GetDescription(DescriptionTypeEnum.FULL));
}

[TestMethod]
public void TestMinutesPastTheHour()
{
ExpressionDescriptor ceh = new ExpressionDescriptor("0 5 0/1 * * ?");
Assert.AreEqual("At 05 minutes past the hour", ceh.GetDescription());
Assert.AreEqual("At 05 minutes past the hour", ceh.GetDescription(DescriptionTypeEnum.FULL));
}
}
}
2 changes: 2 additions & 0 deletions CronExpressionDescriptor/CronExpressionDescriptor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CasingTypeEnum.cs" />
<Compile Include="DescriptionTypeEnum.cs" />
<Compile Include="ExpressionDescriptor.cs" />
<Compile Include="ExpressionParser.cs" />
<Compile Include="Options.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 124bf2a

Please sign in to comment.