Skip to content

Commit 9194362

Browse files
authored
[Azure.Messaging.ServiceBus] Fix AmqpMessageBodyTests (Azure#22008)
The `DateTime` and `DateTimeOffset` test values in `AmqpMessageBodyTests.s_amqpValues` were created with `DateTimeOffset.Parse`, which would fail with the following exception when run on a system with a non-US culture: ``` System.TypeInitializationException : The type initializer for 'Azure.Core.Amqp.Tests.AmqpMessageBodyTests' threw an exception. ----> System.FormatException : String was not recognized as a valid DateTime. at Azure.Core.Amqp.Tests.AmqpMessageBodyTests..ctor() --FormatException at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles, TimeSpan& offset) at System.DateTimeOffset.Parse(String input) at Azure.Core.Amqp.Tests.AmqpMessageBodyTests..cctor() ``` By using `new DateTimeOffset(2021, 3, 24, 0, 0, 0, TimeSpan.Zero)` instead of `DateTimeOffset.Parse("3/24/21")` we ensure that the tests pass on any system regardless of its configured culture.
1 parent 893aee7 commit 9194362

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

sdk/core/Azure.Core.Amqp/tests/AmqpMessageBodyTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public class AmqpMessageBodyTests
2727
new double[] { 3.1415926 },
2828
new decimal(3.1415926),
2929
new decimal[] { new decimal(3.1415926) },
30-
DateTimeOffset.Parse("3/24/21").UtcDateTime,
31-
new DateTime[] {DateTimeOffset.Parse("3/24/21").UtcDateTime },
32-
DateTimeOffset.Parse("3/24/21"),
33-
new DateTimeOffset[] {DateTimeOffset.Parse("3/24/21") },
30+
new DateTimeOffset(2021, 3, 24, 0, 0, 0, TimeSpan.Zero).UtcDateTime,
31+
new DateTime[] { new DateTimeOffset(2021, 3, 24, 0, 0, 0, TimeSpan.Zero).UtcDateTime },
32+
new DateTimeOffset(2021, 3, 24, 0, 0, 0, TimeSpan.Zero),
33+
new DateTimeOffset[] { new DateTimeOffset(2021, 3, 24, 0, 0, 0, TimeSpan.Zero) },
3434
TimeSpan.FromSeconds(5),
3535
new TimeSpan[] {TimeSpan.FromSeconds(5)},
3636
new Uri("http://localHost"),
@@ -45,8 +45,8 @@ public class AmqpMessageBodyTests
4545
new Dictionary<string, short> {{ "key", 1 } },
4646
new Dictionary<string, double> {{ "key", 3.1415926 } },
4747
new Dictionary<string, decimal> {{ "key", new decimal(3.1415926) } },
48-
new Dictionary<string, DateTime> {{ "key", DateTimeOffset.Parse("3/24/21").UtcDateTime } },
49-
new Dictionary<string, DateTimeOffset> {{ "key", DateTimeOffset.Parse("3/24/21") } },
48+
new Dictionary<string, DateTime> {{ "key", new DateTimeOffset(2021, 3, 24, 0, 0, 0, TimeSpan.Zero).UtcDateTime } },
49+
new Dictionary<string, DateTimeOffset> {{ "key", new DateTimeOffset(2021, 3, 24, 0, 0, 0, TimeSpan.Zero) } },
5050
new Dictionary<string, TimeSpan> {{ "key", TimeSpan.FromSeconds(5) } },
5151
new Dictionary<string, Uri> {{ "key", new Uri("http://localHost") } },
5252
new Dictionary<string, Guid> {{ "key", new Guid("55f239a6-5d50-4f6d-8f84-deed326e4554") } },

0 commit comments

Comments
 (0)