From 2c5df5e15ce71203b3cb07115a341e2d7fde16d7 Mon Sep 17 00:00:00 2001 From: "Stephen A. Imhoff" Date: Sun, 13 Mar 2022 21:51:14 +0000 Subject: [PATCH 1/5] Correct whitespace --- .../ConstructorTests/ConstructorTests.ParameterMatching.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs b/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs index 59a05d7be91207..4b710afc1782ac 100644 --- a/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs +++ b/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; @@ -833,7 +833,7 @@ public async Task HonorExtensionDataGeneric() [Fact] public async Task ArgumentDeserialization_Honors_JsonInclude() { - Point_MembersHave_JsonInclude point = new Point_MembersHave_JsonInclude(1, 2,3); + Point_MembersHave_JsonInclude point = new Point_MembersHave_JsonInclude(1, 2, 3); string json = await JsonSerializerWrapperForString.SerializeWrapper(point); Assert.Contains(@"""X"":1", json); From a45fc0125728ac5f26d4038e6eb30d7a3a57d08e Mon Sep 17 00:00:00 2001 From: "Stephen A. Imhoff" Date: Sun, 13 Mar 2022 21:54:27 +0000 Subject: [PATCH 2/5] Switch DateTime.Now -> DateTime.UtcNow --- .../ConstructorTests.ParameterMatching.cs | 26 +++++++++---------- .../Serialization/NullableTests.cs | 4 +-- .../Serialization/NumberHandlingTests.cs | 6 ++--- .../Utf8JsonWriterTests.cs | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs b/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs index 4b710afc1782ac..1b0bd97dfbf402 100644 --- a/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs +++ b/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; @@ -376,8 +376,8 @@ public async Task ClassWithPrimitives_Parameterless() point.SecondInt = 348943; point.FirstString = "934sdkjfskdfssf"; point.SecondString = "sdad9434243242"; - point.FirstDateTime = DateTime.Now; - point.SecondDateTime = DateTime.Now.AddHours(1).AddYears(1); + point.FirstDateTime = DateTime.UtcNow; + point.SecondDateTime = DateTime.UtcNow.AddHours(1).AddYears(1); point.X = 234235; point.Y = 912874; @@ -387,8 +387,8 @@ public async Task ClassWithPrimitives_Parameterless() point.FourthInt = 348943; point.ThirdString = "934sdkjfskdfssf"; point.FourthString = "sdad9434243242"; - point.ThirdDateTime = DateTime.Now; - point.FourthDateTime = DateTime.Now.AddHours(1).AddYears(1); + point.ThirdDateTime = DateTime.UtcNow; + point.FourthDateTime = DateTime.UtcNow.AddHours(1).AddYears(1); string json = await JsonSerializerWrapperForString.SerializeWrapper(point); @@ -421,15 +421,15 @@ public async Task ClassWithPrimitives() point.SecondInt = 348943; point.FirstString = "934sdkjfskdfssf"; point.SecondString = "sdad9434243242"; - point.FirstDateTime = DateTime.Now; - point.SecondDateTime = DateTime.Now.AddHours(1).AddYears(1); + point.FirstDateTime = DateTime.UtcNow; + point.SecondDateTime = DateTime.UtcNow.AddHours(1).AddYears(1); point.ThirdInt = 348943; point.FourthInt = 348943; point.ThirdString = "934sdkjfskdfssf"; point.FourthString = "sdad9434243242"; - point.ThirdDateTime = DateTime.Now; - point.FourthDateTime = DateTime.Now.AddHours(1).AddYears(1); + point.ThirdDateTime = DateTime.UtcNow; + point.FourthDateTime = DateTime.UtcNow.AddHours(1).AddYears(1); string json = await JsonSerializerWrapperForString.SerializeWrapper(point); @@ -462,15 +462,15 @@ public async Task ClassWithPrimitivesPerf() point.SecondInt = 348943; point.FirstString = "934sdkjfskdfssf"; point.SecondString = "sdad9434243242"; - point.FirstDateTime = DateTime.Now; - point.SecondDateTime = DateTime.Now.AddHours(1).AddYears(1); + point.FirstDateTime = DateTime.UtcNow; + point.SecondDateTime = DateTime.UtcNow.AddHours(1).AddYears(1); point.ThirdInt = 348943; point.FourthInt = 348943; point.ThirdString = "934sdkjfskdfssf"; point.FourthString = "sdad9434243242"; - point.ThirdDateTime = DateTime.Now; - point.FourthDateTime = DateTime.Now.AddHours(1).AddYears(1); + point.ThirdDateTime = DateTime.UtcNow; + point.FourthDateTime = DateTime.UtcNow.AddHours(1).AddYears(1); string json = await JsonSerializerWrapperForString.SerializeWrapper(point); diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NullableTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NullableTests.cs index 42ec4baa1e7bf2..5c96ddf30e6147 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NullableTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NullableTests.cs @@ -22,7 +22,7 @@ public static void DictionaryWithNullableValue() dictOfDictWithNull: new Dictionary> { { "key", dictWithFloatNull } }, 42.0f); - DateTime now = DateTime.Now; + DateTime now = DateTime.UtcNow; Dictionary dictWithDateTimeValue = new Dictionary { { "key", now } }; Dictionary dictWithDateTimeNull = new Dictionary { { "key", null } }; TestDictionaryWithNullableValue, Dictionary>, DateTime?>( @@ -205,7 +205,7 @@ public static void EnumerableWithNullableValue() enumerableOfEnumerableWithNull: new List> { ieWithFloatNull }, 42.0f); - DateTime now = DateTime.Now; + DateTime now = DateTime.UtcNow; IEnumerable ieWithDateTimeValue = new List { now }; IEnumerable ieWithDateTimeNull = new List { null }; TestEnumerableWithNullableValue, IEnumerable>, DateTime?>( diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NumberHandlingTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NumberHandlingTests.cs index 857ad1b4014569..e1c6f0e0b12f4f 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NumberHandlingTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NumberHandlingTests.cs @@ -256,7 +256,7 @@ public class Class_With_ListsOfBoxedNumbers [Fact] public static void NonNumber_AsBoxed_Property() { - DateTime dateTime = DateTime.Now; + DateTime dateTime = DateTime.UtcNow; Guid? nullableGuid = Guid.NewGuid(); string expected = @$"{{""MyDateTime"":{JsonSerializer.Serialize(dateTime)},""MyNullableGuid"":{JsonSerializer.Serialize(nullableGuid)}}}"; @@ -293,7 +293,7 @@ public class Class_With_BoxedNonNumbers [Fact] public static void NonNumber_AsBoxed_CollectionRootType_Element() { - DateTime dateTime = DateTime.Now; + DateTime dateTime = DateTime.UtcNow; Guid? nullableGuid = Guid.NewGuid(); string expected = @$"[{JsonSerializer.Serialize(dateTime)}]"; @@ -324,7 +324,7 @@ public static void NonNumber_AsBoxed_CollectionRootType_Element() [Fact] public static void NonNumber_AsBoxed_CollectionProperty_Element() { - DateTime dateTime = DateTime.Now; + DateTime dateTime = DateTime.UtcNow; Guid? nullableGuid = Guid.NewGuid(); string expected = @$"{{""MyDateTimes"":[{JsonSerializer.Serialize(dateTime)}],""MyNullableGuids"":[{JsonSerializer.Serialize(nullableGuid)}]}}"; diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonWriterTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonWriterTests.cs index 4c1dd8a04939b8..01379896492876 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonWriterTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonWriterTests.cs @@ -6195,7 +6195,7 @@ public void WriteLargeKeyOrValue(bool formatted, bool skipValidation) var output = new ArrayBufferWriter(1024); using var jsonUtf8 = new Utf8JsonWriter(output, options); jsonUtf8.WriteStartObject(); - Assert.Throws(() => jsonUtf8.WriteString(key, DateTime.Now)); + Assert.Throws(() => jsonUtf8.WriteString(key, DateTime.UtcNow)); Assert.Equal(0, output.WrittenCount); } From 9c048a38dcb097d14edbe61d37a22a3a82cacf6f Mon Sep 17 00:00:00 2001 From: "Stephen A. Imhoff" Date: Tue, 15 Mar 2022 03:10:58 +0000 Subject: [PATCH 3/5] Tweak formatting --- .../tests/Common/TestClasses/TestClasses.Constructor.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Text.Json/tests/Common/TestClasses/TestClasses.Constructor.cs b/src/libraries/System.Text.Json/tests/Common/TestClasses/TestClasses.Constructor.cs index 890d61f97245d1..b9a47a37511983 100644 --- a/src/libraries/System.Text.Json/tests/Common/TestClasses/TestClasses.Constructor.cs +++ b/src/libraries/System.Text.Json/tests/Common/TestClasses/TestClasses.Constructor.cs @@ -1308,7 +1308,8 @@ public Class_With_Ctor_With_64_Params(int int0, int int1, int int2, int int3, in Int56 = int56; Int57 = int57; Int58 = int58; Int59 = int59; Int60 = int60; Int61 = int61; Int62 = int62; Int63 = int63; } - public static string Json { + public static string Json + { get { StringBuilder sb = new StringBuilder(); @@ -2282,7 +2283,7 @@ public struct Point_With_Property { public int X { get; } public int Y { get; } - public int Z { get; set; } + public int Z { get; set; } [JsonConstructor] public Point_With_Property(int x, int y) From 5d8c5e4e73aeed15fb377805407597eb34c6149f Mon Sep 17 00:00:00 2001 From: "Stephen A. Imhoff" Date: Tue, 15 Mar 2022 03:15:22 +0000 Subject: [PATCH 4/5] Change references to UtcNow to a fixed date/time value. --- .../tests/System/DateTimeTestHelpers.cs | 18 +++++++++++++ .../ConstructorTests.ParameterMatching.cs | 26 +++++++++---------- .../TestClasses/TestClasses.Constructor.cs | 8 +++--- .../RealWorldContextTests.cs | 8 +++--- .../Serialization/NullableTests.cs | 4 +-- .../Serialization/NumberHandlingTests.cs | 6 ++--- .../System.Text.Json.Tests.csproj | 1 + .../Utf8JsonWriterTests.cs | 4 +-- 8 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 src/libraries/Common/tests/System/DateTimeTestHelpers.cs diff --git a/src/libraries/Common/tests/System/DateTimeTestHelpers.cs b/src/libraries/Common/tests/System/DateTimeTestHelpers.cs new file mode 100644 index 00000000000000..cda4861ac78510 --- /dev/null +++ b/src/libraries/Common/tests/System/DateTimeTestHelpers.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; + +namespace System +{ + // Provide date/time test helpers + public static class DateTimeTestHelpers + { + // Fixed DateTimeOffset, to avoid the use of DateTimeOffset.(Utc)Now in situations that simply require a value be present. + public static DateTimeOffset FixedDateTimeOffsetValue => new DateTimeOffset(2001, 2, 3, 4, 5, 6, 789, TimeSpan.Zero); + + // Fixed DateTime, to avoid the use of DateTime.(Utc)Now in situations that simply require a value be present. + public static DateTime FixedDateTimeValue => FixedDateTimeOffsetValue.UtcDateTime; + } + +} diff --git a/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs b/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs index 1b0bd97dfbf402..6f01b36bea69e8 100644 --- a/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs +++ b/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; @@ -376,8 +376,8 @@ public async Task ClassWithPrimitives_Parameterless() point.SecondInt = 348943; point.FirstString = "934sdkjfskdfssf"; point.SecondString = "sdad9434243242"; - point.FirstDateTime = DateTime.UtcNow; - point.SecondDateTime = DateTime.UtcNow.AddHours(1).AddYears(1); + point.FirstDateTime = DateTimeTestHelpers.FixedDateTimeValue; + point.SecondDateTime = DateTimeTestHelpers.FixedDateTimeValue.AddHours(1).AddYears(1); point.X = 234235; point.Y = 912874; @@ -387,8 +387,8 @@ public async Task ClassWithPrimitives_Parameterless() point.FourthInt = 348943; point.ThirdString = "934sdkjfskdfssf"; point.FourthString = "sdad9434243242"; - point.ThirdDateTime = DateTime.UtcNow; - point.FourthDateTime = DateTime.UtcNow.AddHours(1).AddYears(1); + point.ThirdDateTime = DateTimeTestHelpers.FixedDateTimeValue; + point.FourthDateTime = DateTimeTestHelpers.FixedDateTimeValue.AddHours(1).AddYears(1); string json = await JsonSerializerWrapperForString.SerializeWrapper(point); @@ -421,15 +421,15 @@ public async Task ClassWithPrimitives() point.SecondInt = 348943; point.FirstString = "934sdkjfskdfssf"; point.SecondString = "sdad9434243242"; - point.FirstDateTime = DateTime.UtcNow; - point.SecondDateTime = DateTime.UtcNow.AddHours(1).AddYears(1); + point.FirstDateTime = DateTimeTestHelpers.FixedDateTimeValue; + point.SecondDateTime = DateTimeTestHelpers.FixedDateTimeValue.AddHours(1).AddYears(1); point.ThirdInt = 348943; point.FourthInt = 348943; point.ThirdString = "934sdkjfskdfssf"; point.FourthString = "sdad9434243242"; - point.ThirdDateTime = DateTime.UtcNow; - point.FourthDateTime = DateTime.UtcNow.AddHours(1).AddYears(1); + point.ThirdDateTime = DateTimeTestHelpers.FixedDateTimeValue; + point.FourthDateTime = DateTimeTestHelpers.FixedDateTimeValue.AddHours(1).AddYears(1); string json = await JsonSerializerWrapperForString.SerializeWrapper(point); @@ -462,15 +462,15 @@ public async Task ClassWithPrimitivesPerf() point.SecondInt = 348943; point.FirstString = "934sdkjfskdfssf"; point.SecondString = "sdad9434243242"; - point.FirstDateTime = DateTime.UtcNow; - point.SecondDateTime = DateTime.UtcNow.AddHours(1).AddYears(1); + point.FirstDateTime = DateTimeTestHelpers.FixedDateTimeValue; + point.SecondDateTime = DateTimeTestHelpers.FixedDateTimeValue.AddHours(1).AddYears(1); point.ThirdInt = 348943; point.FourthInt = 348943; point.ThirdString = "934sdkjfskdfssf"; point.FourthString = "sdad9434243242"; - point.ThirdDateTime = DateTime.UtcNow; - point.FourthDateTime = DateTime.UtcNow.AddHours(1).AddYears(1); + point.ThirdDateTime = DateTimeTestHelpers.FixedDateTimeValue; + point.FourthDateTime = DateTimeTestHelpers.FixedDateTimeValue.AddHours(1).AddYears(1); string json = await JsonSerializerWrapperForString.SerializeWrapper(point); diff --git a/src/libraries/System.Text.Json/tests/Common/TestClasses/TestClasses.Constructor.cs b/src/libraries/System.Text.Json/tests/Common/TestClasses/TestClasses.Constructor.cs index b9a47a37511983..35e065a11d3b0b 100644 --- a/src/libraries/System.Text.Json/tests/Common/TestClasses/TestClasses.Constructor.cs +++ b/src/libraries/System.Text.Json/tests/Common/TestClasses/TestClasses.Constructor.cs @@ -2326,18 +2326,18 @@ public static MyEventsListerItem Instance = new MyEventsListerItem { Campaign = "A very nice campaign", - EndDate = DateTime.UtcNow.AddDays(7), + EndDate = DateTimeTestHelpers.FixedDateTimeValue.AddDays(7), EventId = 321, EventName = "wonderful name", Organization = "Local Animal Shelter", - StartDate = DateTime.UtcNow.AddDays(-7), + StartDate = DateTimeTestHelpers.FixedDateTimeValue.AddDays(-7), TimeZone = TimeZoneInfo.Utc.DisplayName, VolunteerCount = 15, Tasks = Enumerable.Repeat( new MyEventsListerItemTask { - StartDate = DateTime.UtcNow, - EndDate = DateTime.UtcNow.AddDays(1), + StartDate = DateTimeTestHelpers.FixedDateTimeValue, + EndDate = DateTimeTestHelpers.FixedDateTimeValue.AddDays(1), Name = "A very nice task to have" }, 4).ToList() }; diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/RealWorldContextTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/RealWorldContextTests.cs index 8c384fb7d98fdc..a71e76adbe2cfd 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/RealWorldContextTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/RealWorldContextTests.cs @@ -396,10 +396,10 @@ protected static ActiveOrUpcomingEvent CreateActiveOrUpcomingEvent() CampaignManagedOrganizerName = "Name FamilyName", CampaignName = "The very new campaign", Description = "The .NET Foundation works with Microsoft and the broader industry to increase the exposure of open source projects in the .NET community and the .NET Foundation. The .NET Foundation provides access to these resources to projects and looks to promote the activities of our communities.", - EndDate = DateTime.UtcNow.AddYears(1), + EndDate = DateTimeTestHelpers.FixedDateTimeValue.AddYears(1), Name = "Just a name", ImageUrl = "https://www.dotnetfoundation.org/theme/img/carousel/foundation-diagram-content.png", - StartDate = DateTime.UtcNow, + StartDate = DateTimeTestHelpers.FixedDateTimeValue, Offset = TimeSpan.FromHours(2) }; } @@ -460,10 +460,10 @@ protected static IndexViewModel CreateIndexViewModel() CampaignManagedOrganizerName = "Name FamilyName", CampaignName = "The very new campaign", Description = "The .NET Foundation works with Microsoft and the broader industry to increase the exposure of open source projects in the .NET community and the .NET Foundation. The .NET Foundation provides access to these resources to projects and looks to promote the activities of our communities.", - EndDate = DateTime.UtcNow.AddYears(1), + EndDate = DateTimeTestHelpers.FixedDateTimeValue.AddYears(1), Name = "Just a name", ImageUrl = "https://www.dotnetfoundation.org/theme/img/carousel/foundation-diagram-content.png", - StartDate = DateTime.UtcNow + StartDate = DateTimeTestHelpers.FixedDateTimeValue }, count: 20).ToList() }; diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NullableTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NullableTests.cs index 5c96ddf30e6147..2de66806636415 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NullableTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NullableTests.cs @@ -22,7 +22,7 @@ public static void DictionaryWithNullableValue() dictOfDictWithNull: new Dictionary> { { "key", dictWithFloatNull } }, 42.0f); - DateTime now = DateTime.UtcNow; + DateTime now = DateTimeTestHelpers.FixedDateTimeValue; Dictionary dictWithDateTimeValue = new Dictionary { { "key", now } }; Dictionary dictWithDateTimeNull = new Dictionary { { "key", null } }; TestDictionaryWithNullableValue, Dictionary>, DateTime?>( @@ -205,7 +205,7 @@ public static void EnumerableWithNullableValue() enumerableOfEnumerableWithNull: new List> { ieWithFloatNull }, 42.0f); - DateTime now = DateTime.UtcNow; + DateTime now = DateTimeTestHelpers.FixedDateTimeValue; IEnumerable ieWithDateTimeValue = new List { now }; IEnumerable ieWithDateTimeNull = new List { null }; TestEnumerableWithNullableValue, IEnumerable>, DateTime?>( diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NumberHandlingTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NumberHandlingTests.cs index e1c6f0e0b12f4f..418bcee063a700 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NumberHandlingTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NumberHandlingTests.cs @@ -256,7 +256,7 @@ public class Class_With_ListsOfBoxedNumbers [Fact] public static void NonNumber_AsBoxed_Property() { - DateTime dateTime = DateTime.UtcNow; + DateTime dateTime = DateTimeTestHelpers.FixedDateTimeValue; Guid? nullableGuid = Guid.NewGuid(); string expected = @$"{{""MyDateTime"":{JsonSerializer.Serialize(dateTime)},""MyNullableGuid"":{JsonSerializer.Serialize(nullableGuid)}}}"; @@ -293,7 +293,7 @@ public class Class_With_BoxedNonNumbers [Fact] public static void NonNumber_AsBoxed_CollectionRootType_Element() { - DateTime dateTime = DateTime.UtcNow; + DateTime dateTime = DateTimeTestHelpers.FixedDateTimeValue; Guid? nullableGuid = Guid.NewGuid(); string expected = @$"[{JsonSerializer.Serialize(dateTime)}]"; @@ -324,7 +324,7 @@ public static void NonNumber_AsBoxed_CollectionRootType_Element() [Fact] public static void NonNumber_AsBoxed_CollectionProperty_Element() { - DateTime dateTime = DateTime.UtcNow; + DateTime dateTime = DateTimeTestHelpers.FixedDateTimeValue; Guid? nullableGuid = Guid.NewGuid(); string expected = @$"{{""MyDateTimes"":[{JsonSerializer.Serialize(dateTime)}],""MyNullableGuids"":[{JsonSerializer.Serialize(nullableGuid)}]}}"; diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj index 546bdf6189e7ec..847393a0739755 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj @@ -24,6 +24,7 @@ + diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonWriterTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonWriterTests.cs index 01379896492876..4ce5bc05542fc0 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonWriterTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonWriterTests.cs @@ -6195,7 +6195,7 @@ public void WriteLargeKeyOrValue(bool formatted, bool skipValidation) var output = new ArrayBufferWriter(1024); using var jsonUtf8 = new Utf8JsonWriter(output, options); jsonUtf8.WriteStartObject(); - Assert.Throws(() => jsonUtf8.WriteString(key, DateTime.UtcNow)); + Assert.Throws(() => jsonUtf8.WriteString(key, DateTimeTestHelpers.FixedDateTimeValue)); Assert.Equal(0, output.WrittenCount); } @@ -6304,7 +6304,7 @@ public void WriteDateTimeOffset_TrimsFractionCorrectly(string testStr, string ex [Fact] public void WriteDateTime_TrimsFractionCorrectly_SerializerRoundtrip() { - DateTime utcNow = DateTime.UtcNow; + DateTime utcNow = DateTimeTestHelpers.FixedDateTimeValue; Assert.Equal(utcNow, JsonSerializer.Deserialize(JsonSerializer.SerializeToUtf8Bytes(utcNow), typeof(DateTime))); } From b2d08c1169e059243f1c9cd500f9c7d673517b88 Mon Sep 17 00:00:00 2001 From: "Stephen A. Imhoff" Date: Wed, 16 Mar 2022 01:22:50 +0000 Subject: [PATCH 5/5] Add missing common file reference --- .../System.Text.Json.SourceGeneration.Tests.targets | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/System.Text.Json.SourceGeneration.Tests.targets b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/System.Text.Json.SourceGeneration.Tests.targets index 2f977168e80437..604a43d1682383 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/System.Text.Json.SourceGeneration.Tests.targets +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/System.Text.Json.SourceGeneration.Tests.targets @@ -14,6 +14,7 @@ +