Esempio n. 1
0
        public void BaseStartEndDatePair_FiveMinutes_Pass()
        {
            //create pair
            StartEndDatePair pair = new StartEndDatePair();

            //set the date
            DateTime date = DateTime.UtcNow;

            //call method
            DateManager.BaseStartEndDatePair(pair, DateRange.FiveMinutes);

            //expect either 0, 5, 10, etc depending where the current date rests
            var min = (date.Minute >= 55) ? 55 : (date.Minute >= 50) ? 50 : (date.Minute >= 45) ? 45 : (date.Minute >= 40) ? 40 : (date.Minute >= 35) ? 35 : (date.Minute >= 30) ? 30 : (date.Minute >= 25) ? 25 : (date.Minute >= 20) ? 20 : (date.Minute >= 15) ? 15 : (date.Minute >= 10) ? 10 : (date.Minute >= 5) ? 5 : 0;

            //check results
            Assert.AreEqual(date.Year, pair.StartDate.Year);
            Assert.AreEqual(date.Month, pair.StartDate.Month);
            Assert.AreEqual(date.Day, pair.StartDate.Day);
            Assert.AreEqual(date.Hour, pair.StartDate.Hour);
            Assert.AreEqual(min, pair.StartDate.Minute);
            Assert.AreEqual(date.Year, pair.EndDate.Year);
            Assert.AreEqual(date.Month, pair.EndDate.Month);
            Assert.AreEqual(date.Day, pair.EndDate.Day);
            var hour = (min > 55) ? date.Hour + 1 : date.Hour;

            Assert.AreEqual(hour, pair.EndDate.Hour);
            Assert.AreEqual(pair.StartDate.AddMinutes(5).Minute, pair.EndDate.Minute);
        }
Esempio n. 2
0
        public void BaseStartEndDatePair_FifteenMinutes_SetDate6_Pass()
        {
            //create pair
            StartEndDatePair pair = new StartEndDatePair();
            //set the date
            DateTime date = new DateTime(2015, 3, 3, 15, 52, 20);

            //call method
            DateManager.BaseStartEndDatePair(pair, DateRange.FifteenMinutes, date);

            //expect 45 as min set to 52
            var min = 45;

            //check results
            Assert.AreEqual(date.Year, pair.StartDate.Year);
            Assert.AreEqual(date.Month, pair.StartDate.Month);
            Assert.AreEqual(date.Day, pair.StartDate.Day);
            Assert.AreEqual(date.Hour, pair.StartDate.Hour);
            Assert.AreEqual(min, pair.StartDate.Minute);
            Assert.AreEqual(date.Year, pair.EndDate.Year);
            Assert.AreEqual(date.Month, pair.EndDate.Month);
            Assert.AreEqual(date.Day, pair.EndDate.Day);
            Assert.AreEqual(date.Hour + 1, pair.EndDate.Hour); //should be into the next hour
            Assert.AreEqual(pair.StartDate.AddMinutes(15).Minute, pair.EndDate.Minute);
        }
Esempio n. 3
0
        public void BaseStartEndDatePair_HalfHour_SetDate2_Pass()
        {
            //create pair
            StartEndDatePair pair = new StartEndDatePair();
            //set the date
            DateTime date = new DateTime(2015, 3, 3, 15, 47, 20);

            //call method
            DateManager.BaseStartEndDatePair(pair, DateRange.HalfHour, date);

            //expect min to be 30 as it is set to 47
            int min = 30;

            //check results
            Assert.AreEqual(date.Year, pair.StartDate.Year);
            Assert.AreEqual(date.Month, pair.StartDate.Month);
            Assert.AreEqual(date.Day, pair.StartDate.Day);
            Assert.AreEqual(date.Hour, pair.StartDate.Hour);
            Assert.AreEqual(min, pair.StartDate.Minute);
            Assert.AreEqual(date.Year, pair.EndDate.Year);
            Assert.AreEqual(date.Month, pair.EndDate.Month);
            Assert.AreEqual(date.Day, pair.EndDate.Day);
            Assert.AreEqual(date.Hour + 1, pair.EndDate.Hour); //should be into the next hour
            Assert.AreEqual(pair.StartDate.AddMinutes(30).Minute, pair.EndDate.Minute);
        }
Esempio n. 4
0
        public void BaseStartEndDatePair_HalfHour_Pass()
        {
            //create pair
            StartEndDatePair pair = new StartEndDatePair();
            //set the date
            DateTime date = DateTime.UtcNow;

            //call method
            DateManager.BaseStartEndDatePair(pair, DateRange.HalfHour);

            //expect either 0 or 30 depending if it is past or on the 30 min mark
            int min = (date.Minute >= 30) ? 30 : 0;

            //check results
            Assert.AreEqual(date.Year, pair.StartDate.Year);
            Assert.AreEqual(date.Month, pair.StartDate.Month);
            Assert.AreEqual(date.Day, pair.StartDate.Day);
            Assert.AreEqual(date.Hour, pair.StartDate.Hour);
            Assert.AreEqual(min, pair.StartDate.Minute);
            Assert.AreEqual(date.Year, pair.EndDate.Year);
            Assert.AreEqual(date.Month, pair.EndDate.Month);
            Assert.AreEqual(date.Day, pair.EndDate.Day);
            var hour = (min > 0) ? date.Hour + 1 : date.Hour;

            Assert.AreEqual(hour, pair.EndDate.Hour);
            Assert.AreEqual(pair.StartDate.AddMinutes(30).Minute, pair.EndDate.Minute);
        }
Esempio n. 5
0
 /// <summary>
 /// Method used to call the date manager
 /// </summary>
 /// <param name="dateRange">The date range to set the default values on</param>
 /// <param name="useBase">Set to true to use the base date range or false to use the start from now date</param>
 /// <param name="date">The date to to get the start from</param>
 /// <param name="culture">Optional culture to set the date ranges from</param>
 private void CallDateManager(string dateRange, bool useBase, DateTime date, CultureInfo culture = null)
 {
     if (useBase)
     {
         DateManager.BaseStartEndDatePair(this, dateRange, date, culture);
     }
     else
     {
         DateManager.SetStartEndDatePair(this, dateRange, date);
     }
 }
Esempio n. 6
0
        public void BaseStartEndDatePair_Month_SetDate_Pass()
        {
            //create pair
            StartEndDatePair pair = new StartEndDatePair();
            //set the date
            DateTime date = new DateTime(2015, 3, 3, 15, 47, 20);

            //call method
            DateManager.BaseStartEndDatePair(pair, DateRange.Month, date);

            //check results
            Assert.AreEqual(date.Year, pair.StartDate.Year);
            Assert.AreEqual(date.Month, pair.StartDate.Month);
            Assert.AreEqual(1, pair.StartDate.Day);
            Assert.AreEqual(date.Year, pair.EndDate.Year);
            Assert.AreEqual(date.Month + 1, pair.EndDate.Month);
            Assert.AreEqual(1, pair.EndDate.Day);
        }
Esempio n. 7
0
        public void BaseStartEndDatePair_Year_Pass()
        {
            //create pair
            StartEndDatePair pair = new StartEndDatePair();
            //set the date
            DateTime date = DateTime.UtcNow;

            //call method
            DateManager.BaseStartEndDatePair(pair, DateRange.Year);

            //check results
            Assert.AreEqual(date.Year, pair.StartDate.Year);
            Assert.AreEqual(1, pair.StartDate.Month);
            Assert.AreEqual(1, pair.StartDate.Day);
            Assert.AreEqual(date.Year + 1, pair.EndDate.Year);
            Assert.AreEqual(1, pair.EndDate.Month);
            Assert.AreEqual(1, pair.EndDate.Day);
        }
Esempio n. 8
0
        public void BaseStartEndDatePair_Timespan_Pass()
        {
            //create pair
            StartEndDatePair pair = new StartEndDatePair();

            DateTime blankStart = new DateTime(2000, 1, 1);
            DateTime blankEnd   = new DateTime(2100, 1, 1);

            //call method
            DateManager.BaseStartEndDatePair(pair, DateRange.Timespan);

            //check results
            Assert.AreEqual(blankStart.Year, pair.StartDate.Year);
            Assert.AreEqual(blankStart.Month, pair.StartDate.Month);
            Assert.AreEqual(blankStart.Day, pair.StartDate.Day);
            Assert.AreEqual(blankStart.Hour, pair.StartDate.Hour);
            Assert.AreEqual(blankStart.Minute, pair.StartDate.Minute);
            Assert.AreEqual(blankEnd.Year, pair.EndDate.Year);
            Assert.AreEqual(blankEnd.Month, pair.EndDate.Month);
            Assert.AreEqual(blankEnd.Day, pair.EndDate.Day);
            Assert.AreEqual(blankEnd.Hour, pair.EndDate.Hour);
            Assert.AreEqual(blankEnd.Minute, pair.EndDate.Minute);
        }