Exemplo n.º 1
0
        public void RelativeTest()
        {
            var minTime     = DateTime.MinValue;
            var maxTime     = DateTime.MaxValue;
            var offset      = 1;
            var offsetTypes = new Dictionary <TimeOffset, PropertyInfo>()
            {
                { TimeOffset.Milliseconds, typeof(TimeSpan).GetProperty("Milliseconds") },
                { TimeOffset.Seconds, typeof(TimeSpan).GetProperty("Seconds") },
                { TimeOffset.Minutes, typeof(TimeSpan).GetProperty("Minutes") },
                { TimeOffset.Hours, typeof(TimeSpan).GetProperty("Hours") },
                { TimeOffset.Days, typeof(TimeSpan).GetProperty("Days") }
                //TimeOffset.Months,
                //TimeOffset.Years
            };

            foreach (var offsetType in offsetTypes)
            {
                var rc = new Relative()
                {
                    MinValue   = minTime,
                    Offset     = offset,
                    OffsetType = offsetType.Key,
                    MaxValue   = maxTime
                };
                var      range = new TimeRangeImpl();
                DateTime now   = DateTime.UtcNow;
                rc.Convert(range);
                TimeSpan delta = now - range.StartTime;
                Assert.AreEqual(offsetType.Value.GetValue(delta), offset);
            }
        }