Fix Timezone Test with Morocco on Windows (dotnet/corefx#37419)
authorTarek Mahmoud Sayed <tarekms@microsoft.com>
Mon, 6 May 2019 17:14:23 +0000 (10:14 -0700)
committerGitHub <noreply@github.com>
Mon, 6 May 2019 17:14:23 +0000 (10:14 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/5518ab965f32dafebc7be23be295531030fd9677

src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs

index c100f0d..9457cf1 100644 (file)
@@ -2221,12 +2221,23 @@ namespace System.Tests
                 {
                     Assert.False(string.IsNullOrWhiteSpace(tzi.StandardName));
                     Assert.Matches(@"^\(UTC(\+|-)[0-9]{2}:[0-9]{2}\) \S.*", tzi.DisplayName);
-                    
+
                     // see https://github.com/dotnet/corefx/pull/33204#issuecomment-438782500
                     if (PlatformDetection.IsNotWindowsNanoServer && !PlatformDetection.IsWindows7)
                     {
                         string offset = Regex.Match(tzi.DisplayName, @"(-|)[0-9]{2}:[0-9]{2}").Value;
-                        Assert.True(tzi.BaseUtcOffset == TimeSpan.Parse(offset), $"{offset} != {tzi.BaseUtcOffset}, dn:{tzi.DisplayName}, sn:{tzi.DisplayName}");
+                        TimeSpan ts = TimeSpan.Parse(offset);
+                        if (tzi.BaseUtcOffset != ts && tzi.Id.IndexOf("Morocco", StringComparison.Ordinal) >= 0)
+                        {
+                            // Windows data can report display name with UTC+01:00 offset which is not matching the actual BaseUtcOffset.
+                            // We special case this in the test to avoid the test failures like:
+                            //      01:00 != 00:00:00, dn:(UTC+01:00) Casablanca, sn:Morocco Standard Time
+                            Assert.True(tzi.BaseUtcOffset == new TimeSpan(0, 0, 0), $"{offset} != {tzi.BaseUtcOffset}, dn:{tzi.DisplayName}, sn:{tzi.StandardName}");
+                        }
+                        else
+                        {
+                            Assert.True(tzi.BaseUtcOffset == ts, $"{offset} != {tzi.BaseUtcOffset}, dn:{tzi.DisplayName}, sn:{tzi.StandardName}");
+                        }
                     }
                 }
             }