Test null check in Timestamps.TryParse and document parameters (#285)
Signed-off-by: Safia Abdalla <safia@safia.rocks>
This commit is contained in:
parent
3b78a265f5
commit
6385133391
|
@ -44,12 +44,11 @@ namespace CloudNative.CloudEvents
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to parse a string as an RFC-3339-formatted date/time and UTC offset.
|
/// Attempts to parse a string as an RFC-3339-formatted date/time and UTC offset.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="input">A string to be parsed as a <see cref="DateTimeOffset"/>.</param>
|
||||||
/// <param name="result"></param>
|
/// <param name="result">A <see cref="DateTimeOffset"/> parsed from the <paramref name="input"/>.</param>
|
||||||
/// <returns></returns>
|
/// <returns><see langword="true"/> if <paramref name="input"/> was parsed successfully, <see langword="false"/> otherwise.</returns>
|
||||||
public static bool TryParse(string input, out DateTimeOffset result)
|
internal static bool TryParse(string input, out DateTimeOffset result)
|
||||||
{
|
{
|
||||||
// TODO: Check this and add a test
|
|
||||||
Validation.CheckNotNull(input, nameof(input));
|
Validation.CheckNotNull(input, nameof(input));
|
||||||
|
|
||||||
if (input.Length < MinLength) // "yyyy-MM-ddTHH:mm:ssZ" is the shortest possible value.
|
if (input.Length < MinLength) // "yyyy-MM-ddTHH:mm:ssZ" is the shortest possible value.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2021 Cloud Native Foundation.
|
// Copyright 2021 Cloud Native Foundation.
|
||||||
// Licensed under the Apache 2.0 license.
|
// Licensed under the Apache 2.0 license.
|
||||||
// See LICENSE file in the project root for full license information.
|
// See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
|
@ -123,6 +123,13 @@ namespace CloudNative.CloudEvents.UnitTests
|
||||||
Assert.Throws<FormatException>(() => Timestamps.Parse(text));
|
Assert.Throws<FormatException>(() => Timestamps.Parse(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Parse_Null()
|
||||||
|
{
|
||||||
|
Assert.Throws<ArgumentNullException>(() => Timestamps.TryParse(null!, out _));
|
||||||
|
Assert.Throws<ArgumentNullException>(() => Timestamps.Parse(null!));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// As we're already testing parsing thoroughly, the simplest way of providing
|
/// As we're already testing parsing thoroughly, the simplest way of providing
|
||||||
/// a value to format is to parse a string. Many examples will round-trip, in which
|
/// a value to format is to parse a string. Many examples will round-trip, in which
|
||||||
|
|
Loading…
Reference in New Issue