Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 837dae0

Browse files
Utilizing Constants.Iso8601Formats in SimpleJson deserialization
1 parent de9eebd commit 837dae0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/GitHub.Api/Helpers/SimpleJson.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,9 +1369,9 @@ public virtual object DeserializeObject(object value, Type type)
13691369
if (type == typeof(NPath) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(NPath)))
13701370
return new NPath(str);
13711371
if (type == typeof(DateTime) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(DateTime)))
1372-
return DateTime.ParseExact(str, Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
1372+
return DateTime.ParseExact(str, Constants.Iso8601Formats, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
13731373
if (type == typeof(DateTimeOffset) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(DateTimeOffset)))
1374-
return DateTimeOffset.ParseExact(str, Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
1374+
return DateTimeOffset.ParseExact(str, Constants.Iso8601Formats, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
13751375
if (type == typeof(Guid) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(Guid)))
13761376
return new Guid(str);
13771377
if (type == typeof(UriString) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(UriString)))

src/tests/UnitTests/IO/LockOutputProcessorTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ public void ShouldParseTwoLocksFormat()
6868
new GitLock("2f9cfde9c159d50e235cc1402c3e534b0bf2198afb20760697a5f9b07bf04fb3", "somezip.zip".ToNPath(), new GitUser("GitHub User", ""), now)
6969
};
7070

71+
AssertProcessOutput(output, expected);
72+
}
73+
74+
[Test]
75+
public void ShouldParseVSTSLocksFormat()
76+
{
77+
var nowString = DateTimeOffset.UtcNow.ToString(Constants.Iso8601FormatPointZ);
78+
var now = DateTimeOffset.ParseExact(nowString, Constants.Iso8601Formats, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
79+
var output = new[]
80+
{
81+
$@"[{{""id"":""7"" ,""path"":""Assets/Main.unity"",""owner"":{{""name"":""GitHub User""}},""locked_at"":""{nowString}""}}]",
82+
string.Empty,
83+
"1 lock(s) matched query.",
84+
null
85+
};
86+
87+
var expected = new[] {
88+
new GitLock("7", "Assets/Main.unity".ToNPath(), new GitUser("GitHub User", ""), now),
89+
};
7190

7291
AssertProcessOutput(output, expected);
7392
}

0 commit comments

Comments
 (0)