Ejemplo n.º 1
0
        public void prop_Ending_set(string beginning,
                                    string ending)
        {
            var obj = new DateTimePeriod(XmlConvert.ToDateTime(beginning, XmlDateTimeSerializationMode.Utc), DateTime.MaxValue);

            Assert.DoesNotThrow(() => obj.Ending = XmlConvert.ToDateTime(ending, XmlDateTimeSerializationMode.Utc));
        }
Ejemplo n.º 2
0
        public void prop_Ending_set_whenArgumentOutOfRangeException(string beginning,
                                                                    string ending)
        {
            var obj = new DateTimePeriod(XmlConvert.ToDateTime(beginning, XmlDateTimeSerializationMode.Utc), DateTime.MaxValue);

            Assert.Throws <ArgumentOutOfRangeException>(() => obj.Ending = XmlConvert.ToDateTime(ending, XmlDateTimeSerializationMode.Utc));
        }
Ejemplo n.º 3
0
        public void prop_Duration_get()
        {
            var expected = DateTime.MaxValue - DateTime.MinValue;
            var actual   = new DateTimePeriod(DateTime.MinValue, DateTime.MaxValue).Duration;

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 4
0
        public void op_Contains_Month(bool expected,
                                      string value)
        {
            var period = new DateTimePeriod(XmlConvert.ToDateTime("2012-11-01T00:00:00Z", XmlDateTimeSerializationMode.Utc),
                                            XmlConvert.ToDateTime("2012-11-30T23:59:59Z", XmlDateTimeSerializationMode.Utc));
            var actual = period.Contains(Month.FromString(value));

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 5
0
        DateTimePeriod ICalculateDateTimePeriod <Date> .Until(Date value)
        {
            var later = value.ToDateTime();

            if (later < _date)
            {
                throw new ArgumentOutOfRangeException("value");
            }

            return(DateTimePeriod.Between(_date, later));
        }
Ejemplo n.º 6
0
        public void prop_Calendar_Year()
        {
            var date = new Date(2012, 11, 10);

            var expected = new DateTimePeriod
            {
                Ending    = new DateTime(2012, 12, 31),
                Beginning = new DateTime(2012, 1, 1)
            };
            var actual = date.Calendar.Year;

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 7
0
        public void prop_Period_Years_intZero()
        {
            var date = Date.Today.LocalTime;

            var expected = new DateTimePeriod
            {
                Ending    = date.ToDateTime(),
                Beginning = date.ToDateTime()
            };
            var actual = date.Period.Years(0);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 8
0
        public void prop_Calendar_Week_whenSunday()
        {
            var date = new Date(2012, 11, 4);

            var expected = new DateTimePeriod
            {
                Ending    = new DateTime(2012, 11, 4),
                Beginning = new DateTime(2012, 10, 29)
            };
            var actual = date.Calendar.Week;

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 9
0
        public void prop_Period_Weeks_int()
        {
            var date = Date.Today.LocalTime;

            var expected = new DateTimePeriod
            {
                Ending    = date.AddDays(13).ToDateTime(),
                Beginning = date.ToDateTime()
            };
            var actual = date.Period.Weeks(2);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 10
0
        public void prop_Period_Years_intNegative()
        {
            var date = Date.Today.LocalTime;

            var expected = new DateTimePeriod
            {
                Ending    = date.ToDateTime(),
                Beginning = date.AddYears(-1).AddDays(1).ToDateTime()
            };
            var actual = date.Period.Years(-1);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 11
0
        public void prop_Period_Since_DateSame()
        {
            var date  = Date.Today.LocalTime;
            var since = Date.Today.LocalTime;

            var expected = new DateTimePeriod
            {
                Ending    = since.ToDateTime(),
                Beginning = date.ToDateTime()
            };
            var actual = date.Period.Since(since);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 12
0
        public void prop_Period_Until_DateSame()
        {
            var date  = Date.Today.LocalTime;
            var until = Date.Today.LocalTime;

            var expected = new DateTimePeriod
            {
                Ending    = until.ToDateTime(),
                Beginning = date.ToDateTime()
            };
            var actual = date.Period.Until(until);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 13
0
        public void prop_Period_Between_DateSame()
        {
            var date  = Date.Today.LocalTime;
            var other = Date.Today.LocalTime;

            var expected = new DateTimePeriod
            {
                Ending    = other.ToDateTime(),
                Beginning = date.ToDateTime()
            };
            var actual = date.Period.Between(other);

            Assert.Equal(expected, actual);
        }
        public void op_Months_int()
        {
            var expected = new DateTimePeriod();

            var mock = new Mock <ICalculateDateTimePeriod <Date> >();

            mock
            .Setup(x => x.Months(1))
            .Returns(expected)
            .Verifiable();

            var actual = mock.Object.Months(1);

            Assert.Equal(expected, actual);

            mock.VerifyAll();
        }
        public void op_Until_T()
        {
            var expected = new DateTimePeriod();
            var value    = Date.Today.LocalTime;

            var mock = new Mock <ICalculateDateTimePeriod <Date> >();

            mock
            .Setup(x => x.Until(value))
            .Returns(expected)
            .Verifiable();

            var actual = mock.Object.Until(value);

            Assert.Equal(expected, actual);

            mock.VerifyAll();
        }
Ejemplo n.º 16
0
 DateTimePeriod ICalculateDateTimePeriod <Date> .Years(int value)
 {
     return(0 == value
                ? new DateTimePeriod(_date, _date)
                : DateTimePeriod.Between(_date, _date.AddYears(value).AddDays(value > 0 ? -1 : 1)));
 }
Ejemplo n.º 17
0
 DateTimePeriod ICalculateDateTimePeriod <Date> .Weeks(int value)
 {
     return(0 == value
                ? new DateTimePeriod(_date, _date)
                : DateTimePeriod.Between(_date, AddWeeks(value).ToDateTime().AddDays(value > 0 ? -1 : 1)));
 }
Ejemplo n.º 18
0
 DateTimePeriod ICalculateDateTimePeriod <Date> .Between(Date value)
 {
     return(DateTimePeriod.Between(_date, value.ToDateTime()));
 }