コード例 #1
0
 public void DuplicateIds()
 {
     var builder = new FakeDateTimeZoneSource.Builder
     {
         CreateZone("x"), CreateZone("y"), CreateZone("x")
     };
     AssertBuildFails(builder);
 }
コード例 #2
0
 public void ForId_Missing()
 {
     var source = new FakeDateTimeZoneSource.Builder
     {
         CreateZone("x"), CreateZone("y")
     }.Build();
     Assert.Throws<ArgumentException>(() => source.ForId("missing"));
 }
コード例 #3
0
 public void Ids()
 {
     var source = new FakeDateTimeZoneSource.Builder
     {
         CreateZone("x"), CreateZone("y"), CreateZone("a"), CreateZone("b")
     }.Build();
     CollectionAssert.AreEquivalent(source.GetIds(), new[] { "x", "y", "a", "b" });
 }
コード例 #4
0
        public void NullZoneViaProperty()
        {
            var source = new FakeDateTimeZoneSource.Builder
            {
                Zones = { null }
            };

            AssertBuildFails(source);
        }
コード例 #5
0
        public void ForId_Missing()
        {
            var source = new FakeDateTimeZoneSource.Builder
            {
                CreateZone("x"), CreateZone("y")
            }.Build();

            Assert.Throws <ArgumentException>(() => source.ForId("missing"));
        }
コード例 #6
0
        public void DuplicateIds()
        {
            var builder = new FakeDateTimeZoneSource.Builder
            {
                CreateZone("x"), CreateZone("y"), CreateZone("x")
            };

            AssertBuildFails(builder);
        }
コード例 #7
0
        public void Ids()
        {
            var source = new FakeDateTimeZoneSource.Builder
            {
                CreateZone("x"), CreateZone("y"), CreateZone("a"), CreateZone("b")
            }.Build();

            CollectionAssert.AreEquivalent(source.GetIds(), new[] { "x", "y", "a", "b" });
        }
コード例 #8
0
        public void InvalidWindowsMapping_NullCanonicalId()
        {
            var source = new FakeDateTimeZoneSource.Builder
            {
                BclIdsToZoneIds = { { "x", null } },
                Zones           = { CreateZone("z") }
            };

            AssertBuildFails(source);
        }
コード例 #9
0
 public void ForId_Present()
 {
     var zone = CreateZone("x");
     var source = new FakeDateTimeZoneSource.Builder
     {
         // The "right" one and some others
         zone, CreateZone("y"), CreateZone("a"), CreateZone("b")
     }.Build();
     Assert.AreSame(zone, source.ForId("x"));
 }
コード例 #10
0
        public void InvalidWindowsMapping_MissingZone()
        {
            var source = new FakeDateTimeZoneSource.Builder
            {
                BclIdsToZoneIds = { { TimeZoneInfo.Local.Id, "z" } },
                Zones           = { CreateZone("x"), CreateZone("y") }
            };

            AssertBuildFails(source);
        }
コード例 #11
0
        public void ForId_Present()
        {
            var zone   = CreateZone("x");
            var source = new FakeDateTimeZoneSource.Builder
            {
                // The "right" one and some others
                zone, CreateZone("y"), CreateZone("a"), CreateZone("b")
            }.Build();

            Assert.AreSame(zone, source.ForId("x"));
        }
コード例 #12
0
        public void ValidWindowsMapping()
        {
            string localId = TimeZoneInfo.Local.Id;
            var    source  = new FakeDateTimeZoneSource.Builder
            {
                BclIdsToZoneIds = { { localId, "x" } },
                Zones           = { CreateZone("x"), CreateZone("y") }
            }.Build();

            Assert.AreEqual("x", source.GetSystemDefaultId());
        }
コード例 #13
0
 // We don't really care how it fails - just that an exception is thrown.
 // Unfortuntely NUnit requires the exact exception type :(
 private static void AssertBuildFails(FakeDateTimeZoneSource.Builder builder)
 {
     try
     {
         builder.Build();
         Assert.Fail("Expected exception");
     }
     catch (Exception)
     {
         // Expected
     }
 }
コード例 #14
0
        public void GetAllZones()
        {
            // Note: in ID order.
            var zone1 = DateTimeZoneProviders.Tzdb["America/New_York"];
            var zone2 = DateTimeZoneProviders.Tzdb["Europe/London"];
            var zone3 = DateTimeZoneProviders.Tzdb["Europe/Paris"];

            var provider = new FakeDateTimeZoneSource.Builder {
                zone1, zone2, zone3
            }.Build().ToProvider();

            CollectionAssert.AreEqual(new[] { zone1, zone2, zone3 }, provider.GetAllZones());
        }
コード例 #15
0
        public void ValidWindowsMapping()
        {
#if PCL
            string localId = TimeZoneInfo.Local.StandardName;
#else
            string localId = TimeZoneInfo.Local.Id;
#endif
            var source = new FakeDateTimeZoneSource.Builder
            {
                BclIdsToZoneIds = { { localId, "x" } },
                Zones           = { CreateZone("x"), CreateZone("y") }
            }.Build();
            Assert.AreEqual("x", source.MapTimeZoneId(TimeZoneInfo.Local));
        }
コード例 #16
0
        public void ValidWindowsMapping()
        {
#if PCL
            string localId = TimeZoneInfo.Local.StandardName;
#else
            string localId = TimeZoneInfo.Local.Id;
#endif
            var source = new FakeDateTimeZoneSource.Builder
            {
                BclIdsToZoneIds = { { localId, "x"} },
                Zones = { CreateZone("x"), CreateZone("y") }
            }.Build();
            Assert.AreEqual("x", source.MapTimeZoneId(TimeZoneInfo.Local));
        }
コード例 #17
0
        public void GetEnumerator()
        {
            var x      = CreateZone("x");
            var y      = CreateZone("y");
            var source = new FakeDateTimeZoneSource.Builder
            {
                Zones = { x, y }
            };

            // Tests IEnumerable<T>
            CollectionAssert.AreEqual(new[] { x, y }, source.ToList());
            // Tests IEnumerable
            CollectionAssert.AreEqual(new[] { x, y }, source.OfType <DateTimeZone>().ToList());
        }
コード例 #18
0
        // We don't really care how it fails - just that an exception is thrown.
        // Unfortuntely NUnit requires the exact exception type :(
        private static void AssertBuildFails(FakeDateTimeZoneSource.Builder builder)
        {
            bool success = false;

            try
            {
                builder.Build();
                success = true;
            }
            catch (Exception)
            {
                // Expected
            }
            Assert.IsFalse(success);
        }
コード例 #19
0
        public void SerializationDelegatesToXmlSerializerSettings()
        {
            var original = XmlSerializationSettings.DateTimeZoneProvider;

            try
            {
#pragma warning disable CS0618 // Type or member is obsolete
                var provider1 = new FakeDateTimeZoneSource.Builder().Build().ToProvider();
                DateTimeZoneProviders.Serialization = provider1;
                Assert.AreSame(provider1, XmlSerializationSettings.DateTimeZoneProvider);

                var provider2 = new FakeDateTimeZoneSource.Builder().Build().ToProvider();
                XmlSerializationSettings.DateTimeZoneProvider = provider2;
                Assert.AreSame(provider2, DateTimeZoneProviders.Serialization);
#pragma warning restore CS0618 // Type or member is obsolete
            }
            finally
            {
                XmlSerializationSettings.DateTimeZoneProvider = original;
            }
        }
コード例 #20
0
        public void FindLongestZoneId()
        {
            var source = new FakeDateTimeZoneSource.Builder
            {
                CreateZone("ABC"),
                CreateZone("ABCA"),
                CreateZone("ABCB"),
                CreateZone("ABCBX"),
                CreateZone("ABCD")
            }.Build();

            var provider = new DateTimeZoneCache(source);
            var pattern  = ZonedDateTimePattern.Create("z 'x'", CultureInfo.InvariantCulture, Resolvers.StrictResolver,
                                                       provider, NodaConstants.UnixEpoch.InUtc());

            foreach (var id in provider.Ids)
            {
                var value = pattern.Parse($"{id} x").Value;
                Assert.AreEqual(id, value.Zone.Id);
            }

            DateTimeZone CreateZone(string id) =>
            new SingleTransitionDateTimeZone(NodaConstants.UnixEpoch - Duration.FromDays(1), Offset.FromHours(-1), Offset.FromHours(0), id);
        }
コード例 #21
0
 public void NullZoneViaProperty()
 {
     var source = new FakeDateTimeZoneSource.Builder
     {
         Zones = { null }
     };
     AssertBuildFails(source);
 }
コード例 #22
0
 public void InvalidWindowsMapping_MissingZone()
 {
     var source = new FakeDateTimeZoneSource.Builder
     {
         BclIdsToZoneIds = { { TimeZoneInfo.Local.Id, "z" } },
         Zones = { CreateZone("x"), CreateZone("y") }
     };
     AssertBuildFails(source);
 }
コード例 #23
0
 public void InvalidWindowsMapping_NullCanonicalId()
 {
     var source = new FakeDateTimeZoneSource.Builder
     {
         BclIdsToZoneIds = { { "x", null } },
         Zones = { CreateZone("z") }
     };
     AssertBuildFails(source);
 }