public void UtcIsNotReturnedInIdsIfNotAdvertisedByProvider()
        {
            var source   = new TestDateTimeZoneSource("Test1", "Test2");
            var provider = new DateTimeZoneCache(source);

            Assert.False(provider.Ids.Contains(DateTimeZone.UtcId));
        }
        public void InvalidProvider_NullIdSequence()
        {
            string[] ids    = null;
            var      source = new TestDateTimeZoneSource(ids);

            Assert.Throws <InvalidDateTimeZoneSourceException>(() => new DateTimeZoneCache(source));
        }
Пример #3
0
 public void SourceIsNotAskedForUtcIfAdvertised()
 {
     var source = new TestDateTimeZoneSource("Test1", "Test2", "UTC");
     var provider = new DateTimeZoneCache(source);
     var zone = provider[DateTimeZone.UtcId];
     Assert.IsNotNull(zone);
     Assert.IsNull(source.LastRequestedId);
 }
        public void SourceIsNotAskedForUnknownIds()
        {
            var source   = new TestDateTimeZoneSource("Test1", "Test2");
            var provider = new DateTimeZoneCache(source);

            Assert.Throws <DateTimeZoneNotFoundException>(() => { var ignored = provider["Unknown"]; });
            Assert.IsNull(source.LastRequestedId);
        }
        public void InvalidProvider_NullVersionId()
        {
            var source = new TestDateTimeZoneSource("Test1", "Test2")
            {
                VersionId = null
            };

            Assert.Throws <InvalidDateTimeZoneSourceException>(() => new DateTimeZoneCache(source));
        }
        public void SourceIsNotAskedForUtcIfAdvertised()
        {
            var source   = new TestDateTimeZoneSource("Test1", "Test2", "UTC");
            var provider = new DateTimeZoneCache(source);
            var zone     = provider[DateTimeZone.UtcId];

            Assert.IsNotNull(zone);
            Assert.IsNull(source.LastRequestedId);
        }
        public void FixedOffsetZeroReturnsUtc()
        {
            string       id       = "UTC+00:00";
            var          source   = new TestDateTimeZoneSource("Test1", "Test2", id);
            var          provider = new DateTimeZoneCache(source);
            DateTimeZone zone     = provider[id];

            Assert.AreEqual(DateTimeZone.Utc, zone);
            Assert.IsNull(source.LastRequestedId);
        }
Пример #8
0
        public void FixedOffsetConsultsSourceWhenAdvertised()
        {
            string       id       = "UTC+05:30";
            var          source   = new TestDateTimeZoneSource("Test1", "Test2", id);
            var          provider = new DateTimeZoneCache(source);
            DateTimeZone zone     = provider[id];

            Assert.AreEqual(id, zone.Id);
            Assert.AreEqual(id, source.LastRequestedId);
        }
        public void FixedOffsetUncached()
        {
            string       id       = "UTC+05:26";
            var          source   = new TestDateTimeZoneSource("Test1", "Test2");
            var          provider = new DateTimeZoneCache(source);
            DateTimeZone zone1    = provider[id];
            DateTimeZone zone2    = provider[id];

            Assert.AreNotSame(zone1, zone2);
            Assert.AreEqual(zone1, zone2);
        }
Пример #10
0
        public void FixedOffsetSucceedsWithoutConsultingSourceWhenAdvertised()
        {
            string       id       = "UTC+05:30";
            var          source   = new TestDateTimeZoneSource("Test1", "Test2", id);
            var          provider = new DateTimeZoneCache(source);
            DateTimeZone zone     = provider[id];

            Assert.AreEqual(DateTimeZone.ForOffset(Offset.FromHoursAndMinutes(5, 30)), zone);
            Assert.AreEqual(id, zone.Id);
            Assert.IsNull(source.LastRequestedId);
        }
Пример #11
0
        public void CachingForPresentValues()
        {
            var source = new TestDateTimeZoneSource("Test1", "Test2");
            var provider = new DateTimeZoneCache(source);
            var zone1a = provider["Test1"];
            Assert.IsNotNull(zone1a);
            Assert.AreEqual("Test1", source.LastRequestedId);

            // Hit up the cache (and thus the source) for Test2
            Assert.IsNotNull(provider["Test2"]);
            Assert.AreEqual("Test2", source.LastRequestedId);

            // Ask for Test1 again
            var zone1b = provider["Test1"];
            // We won't have consulted the source again
            Assert.AreEqual("Test2", source.LastRequestedId);

            Assert.AreSame(zone1a, zone1b);
        }
Пример #12
0
        public void CachingForPresentValues()
        {
            var source   = new TestDateTimeZoneSource("Test1", "Test2");
            var provider = new DateTimeZoneCache(source);
            var zone1a   = provider["Test1"];

            Assert.IsNotNull(zone1a);
            Assert.AreEqual("Test1", source.LastRequestedId);

            // Hit up the cache (and thus the source) for Test2
            Assert.IsNotNull(provider["Test2"]);
            Assert.AreEqual("Test2", source.LastRequestedId);

            // Ask for Test1 again
            var zone1b = provider["Test1"];

            // We won't have consulted the source again
            Assert.AreEqual("Test2", source.LastRequestedId);

            Assert.AreSame(zone1a, zone1b);
        }
Пример #13
0
 public void UtcIsReturnedInIdsIfAdvertisedByProvider()
 {
     var source = new TestDateTimeZoneSource("Test1", "Test2", "UTC");
     var provider = new DateTimeZoneCache(source);
     Assert.True(provider.Ids.Contains(DateTimeZone.UtcId));
 }
Пример #14
0
 public void SourceIsNotAskedForUnknownIds()
 {
     var source = new TestDateTimeZoneSource("Test1", "Test2");
     var provider = new DateTimeZoneCache(source);
     Assert.Throws<DateTimeZoneNotFoundException>(() => { var ignored = provider["Unknown"]; });
     Assert.IsNull(source.LastRequestedId);
 }
Пример #15
0
 public void InvalidProvider_NullIdWithinSequence()
 {
     var source = new TestDateTimeZoneSource("Test1", null);
     Assert.Throws<InvalidDateTimeZoneSourceException>(() => new DateTimeZoneCache(source));
 }
Пример #16
0
 public void InvalidProvider_NullIdSequence()
 {
     string[] ids = null;
     var source = new TestDateTimeZoneSource(ids);
     Assert.Throws<InvalidDateTimeZoneSourceException>(() => new DateTimeZoneCache(source));
 }
Пример #17
0
 public void InvalidProvider_NullVersionId()
 {
     var source = new TestDateTimeZoneSource("Test1", "Test2") { VersionId = null };
     Assert.Throws<InvalidDateTimeZoneSourceException>(() => new DateTimeZoneCache(source));
 }
Пример #18
0
 public void FixedOffsetZeroReturnsUtc()
 {
     string id = "UTC+00:00";
     var source = new TestDateTimeZoneSource("Test1", "Test2", id);
     var provider = new DateTimeZoneCache(source);
     DateTimeZone zone = provider[id];
     Assert.AreEqual(DateTimeZone.Utc, zone);
     Assert.IsNull(source.LastRequestedId);
 }
Пример #19
0
 public void FixedOffsetUncached()
 {
     string id = "UTC+05:26";
     var source = new TestDateTimeZoneSource("Test1", "Test2");
     var provider = new DateTimeZoneCache(source);
     DateTimeZone zone1 = provider[id];
     DateTimeZone zone2 = provider[id];
     Assert.AreNotSame(zone1, zone2);
     Assert.AreEqual(zone1, zone2);
 }
Пример #20
0
 public void FixedOffsetSucceedsWithoutConsultingSourceWhenAdvertised()
 {
     string id = "UTC+05:30";
     var source = new TestDateTimeZoneSource("Test1", "Test2", id);
     var provider = new DateTimeZoneCache(source);
     DateTimeZone zone = provider[id];
     Assert.AreEqual(DateTimeZone.ForOffset(Offset.FromHoursAndMinutes(5, 30)), zone);
     Assert.AreEqual(id, zone.Id);
     Assert.IsNull(source.LastRequestedId);
 }
Пример #21
0
        public void InvalidProvider_NullIdWithinSequence()
        {
            var source = new TestDateTimeZoneSource("Test1", null);

            Assert.Throws <InvalidDateTimeZoneSourceException>(() => new DateTimeZoneCache(source));
        }