Skip to content

Commit f8605af

Browse files
committed
CrontabSchedule.TryParse shouldn't throw for null input
This is to be consistent with TryParse methods on types in the .NET Framework that also don't throw for null input.
1 parent abce185 commit f8605af

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

NCrontab.Tests/CrontabScheduleTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public void CannotParseEmptyString()
4242
Assert.Throws<CrontabException>(() => CrontabSchedule.Parse(string.Empty));
4343
}
4444

45+
[Test]
46+
public void TryParseNullString() =>
47+
Assert.That(CrontabSchedule.TryParse(null), Is.Null);
48+
49+
[Test]
50+
public void TryParseEmptyString() =>
51+
Assert.That(CrontabSchedule.TryParse(string.Empty), Is.Null);
52+
4553
[Test]
4654
public void AllTimeString()
4755
{
@@ -309,6 +317,10 @@ static void BadField(string expression, bool includingSeconds)
309317
{
310318
IncludingSeconds = includingSeconds
311319
}));
320+
Assert.That(CrontabSchedule.TryParse(expression, new ParseOptions
321+
{
322+
IncludingSeconds = includingSeconds
323+
}), Is.Null);
312324
}
313325

314326
[TestCase("bad * * * * *", false)]

NCrontab/AssemblyInfo.g.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// This code was generated by a tool. Any changes made manually will be lost
22
// the next time this code is regenerated.
3-
// Generated: Thu, 20 Oct 2016 06:08:37 GMT
4-
3+
// Generated: Thu, 20 Oct 2016 06:50:00 GMT
4+
55
using System.Reflection;
6-
6+
77
[assembly: AssemblyVersion("3.1.20120.0")]
8-
[assembly: AssemblyFileVersion("3.1.20120.608")]
8+
[assembly: AssemblyFileVersion("3.1.20120.650")]

NCrontab/CrontabSchedule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ public static CrontabSchedule Parse(string expression, ParseOptions options) =>
9999
public static CrontabSchedule TryParse(string expression) => TryParse(expression, null);
100100

101101
public static CrontabSchedule TryParse(string expression, ParseOptions options) =>
102-
TryParse(expression, options, v => v, _ => null);
102+
TryParse(expression ?? string.Empty, options, v => v, _ => null);
103103

104104
public static T TryParse<T>(string expression, Func<CrontabSchedule, T> valueSelector, Func<ExceptionProvider, T> errorSelector) =>
105-
TryParse(expression, null, valueSelector, errorSelector);
105+
TryParse(expression ?? string.Empty, null, valueSelector, errorSelector);
106106

107107
public static T TryParse<T>(string expression, ParseOptions options, Func<CrontabSchedule, T> valueSelector, Func<ExceptionProvider, T> errorSelector)
108108
{

0 commit comments

Comments
 (0)