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));
        }