public void DuplicateIds()
 {
     var builder = new FakeDateTimeZoneSource.Builder
     {
         CreateZone("x"), CreateZone("y"), CreateZone("x")
     };
     AssertBuildFails(builder);
 }
 public void ForId_Missing()
 {
     var source = new FakeDateTimeZoneSource.Builder
     {
         CreateZone("x"), CreateZone("y")
     }.Build();
     Assert.Throws<ArgumentException>(() => source.ForId("missing"));
 }
 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" });
 }
Ejemplo n.º 4
0
        public void NullZoneViaProperty()
        {
            var source = new FakeDateTimeZoneSource.Builder
            {
                Zones = { null }
            };

            AssertBuildFails(source);
        }
Ejemplo n.º 5
0
        public void ForId_Missing()
        {
            var source = new FakeDateTimeZoneSource.Builder
            {
                CreateZone("x"), CreateZone("y")
            }.Build();

            Assert.Throws <ArgumentException>(() => source.ForId("missing"));
        }
Ejemplo n.º 6
0
        public void DuplicateIds()
        {
            var builder = new FakeDateTimeZoneSource.Builder
            {
                CreateZone("x"), CreateZone("y"), CreateZone("x")
            };

            AssertBuildFails(builder);
        }
Ejemplo n.º 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" });
        }
Ejemplo n.º 8
0
        public void InvalidWindowsMapping_NullCanonicalId()
        {
            var source = new FakeDateTimeZoneSource.Builder
            {
                BclIdsToZoneIds = { { "x", null } },
                Zones           = { CreateZone("z") }
            };

            AssertBuildFails(source);
        }
 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"));
 }
Ejemplo n.º 10
0
        public void InvalidWindowsMapping_MissingZone()
        {
            var source = new FakeDateTimeZoneSource.Builder
            {
                BclIdsToZoneIds = { { TimeZoneInfo.Local.Id, "z" } },
                Zones           = { CreateZone("x"), CreateZone("y") }
            };

            AssertBuildFails(source);
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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
     }
 }
        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());
        }
Ejemplo n.º 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));
        }
        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));
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);
        }
 public void NullZoneViaProperty()
 {
     var source = new FakeDateTimeZoneSource.Builder
     {
         Zones = { null }
     };
     AssertBuildFails(source);
 }
 public void InvalidWindowsMapping_MissingZone()
 {
     var source = new FakeDateTimeZoneSource.Builder
     {
         BclIdsToZoneIds = { { TimeZoneInfo.Local.Id, "z" } },
         Zones = { CreateZone("x"), CreateZone("y") }
     };
     AssertBuildFails(source);
 }
 public void InvalidWindowsMapping_NullCanonicalId()
 {
     var source = new FakeDateTimeZoneSource.Builder
     {
         BclIdsToZoneIds = { { "x", null } },
         Zones = { CreateZone("z") }
     };
     AssertBuildFails(source);
 }