Ejemplo n.º 1
0
        public void ReferenceComparison()
        {
            var comparer = ZoneEqualityComparer.ForInterval(new Interval(Instants[0], Instants[2]));
            var zone     = DateTimeZoneProviders.Tzdb["Europe/London"];

            Assert.IsTrue(comparer.Equals(zone, zone));
        }
Ejemplo n.º 2
0
        public void ForInterval()
        {
            var interval = new Interval(Instants[3], Instants[5]);
            var comparer = ZoneEqualityComparer.ForInterval(interval);

            Assert.AreEqual(Options.OnlyMatchWallOffset, comparer.OptionsForTest);
            Assert.AreEqual(interval, comparer.IntervalForTest);
        }
Ejemplo n.º 3
0
        private void AssertEqual(DateTimeZone first, DateTimeZone second,
                                 Instant start, Instant end, Options options)
        {
            var comparer = ZoneEqualityComparer.ForInterval(new Interval(start, end)).WithOptions(options);

            Assert.IsTrue(comparer.Equals(first, second));
            Assert.AreEqual(comparer.GetHashCode(first), comparer.GetHashCode(second));
        }
Ejemplo n.º 4
0
        public void NullComparison()
        {
            var comparer = ZoneEqualityComparer.ForInterval(new Interval(Instants[0], Instants[2]));
            var zone     = DateTimeZoneProviders.Tzdb["Europe/London"];

            Assert.IsFalse(comparer.Equals(zone, null));
            Assert.IsFalse(comparer.Equals(null, zone));
        }
Ejemplo n.º 5
0
        private void AssertNotEqual(DateTimeZone first, DateTimeZone second,
                                    Instant start, Instant end, Options options)
        {
            var comparer = ZoneEqualityComparer.ForInterval(new Interval(start, end)).WithOptions(options);

            Assert.IsFalse(comparer.Equals(first, second));
            // If this fails, the code *could* still be correct - but it's unlikely...
            Assert.AreNotEqual(comparer.GetHashCode(first), comparer.GetHashCode(second));
        }
Ejemplo n.º 6
0
        public void WithOptions()
        {
            var interval       = new Interval(Instants[3], Instants[5]);
            var firstComparer  = ZoneEqualityComparer.ForInterval(interval);
            var secondComparer = firstComparer.WithOptions(Options.MatchNames);

            Assert.AreEqual(Options.MatchNames, secondComparer.OptionsForTest);
            Assert.AreEqual(interval, secondComparer.IntervalForTest);

            // Validate that the first comparer hasn't changed
            Assert.AreEqual(Options.OnlyMatchWallOffset, firstComparer.OptionsForTest);
            Assert.AreEqual(interval, firstComparer.IntervalForTest);
        }
        public void ResourceZoneEquivalence()
        {
            var streamSource = TzdbDateTimeZoneSource.Default;

#pragma warning disable 0618
            var resourceSource = new TzdbDateTimeZoneSource("NodaTime.Test.TestData.Tzdb",
                                                            Assembly.GetExecutingAssembly());
#pragma warning restore 0618
            Assert.AreEqual(streamSource.VersionId, resourceSource.VersionId);
            CollectionAssert.AreEquivalent(streamSource.GetIds(), resourceSource.GetIds());

            var interval = new Interval(Instant.FromUtc(1850, 1, 1, 0, 0), Instant.FromUtc(2050, 1, 1, 0, 0));
            var comparer = ZoneEqualityComparer.ForInterval(interval).WithOptions(ZoneEqualityComparer.Options.StrictestMatch);
            foreach (var id in streamSource.GetIds())
            {
                Assert.IsTrue(comparer.Equals(streamSource.ForId(id), resourceSource.ForId(id)),
                              "Zone {0} is equal under stream and resource formats", id);
            }
        }
Ejemplo n.º 8
0
        public void InvalidOptions()
        {
            var comparer = ZoneEqualityComparer.ForInterval(new Interval(Instants[0], Instants[2]));

            Assert.Throws <ArgumentOutOfRangeException>(() => comparer.WithOptions((ZoneEqualityComparer.Options) 9999));
        }