示例#1
0
        public void CheckPatternsForDifferentSeparatorAndYears()
        {
            Mock <ICultureUtil> cultureUtilMock = new Mock <ICultureUtil>();
            char newSeparator = '/';

            foreach (ShortDateTimeInfo pas in patternsAndSeparators)
            {
                cultureUtilMock.Setup(m => m.ShortDatePattern).Returns(pas.ShortDatePattern.Replace('.', newSeparator));
                cultureUtilMock.Setup(m => m.DateSeparator).Returns(pas.DateSeparator.Replace('.', newSeparator));

                DateTime today    = DateTime.Now.Date;
                DateTime tomorrow = DateTime.Now.Date.AddYears(1).Date;

                IPatternsUtil patternsUtil   = container.Resolve <IPatternsUtil>(new TypedParameter(typeof(ICultureUtil), cultureUtilMock.Object));
                PatternsDTO   resultPatterns = patternsUtil.GetPatterns(today, tomorrow);

                string expectedStart = pas.YearDiff.StartPattern.Replace('.', newSeparator);
                string resultStart   = resultPatterns.StartPattern;
                string expectedEnd   = pas.YearDiff.EndPattern.Replace('.', newSeparator);
                string resultEnd     = resultPatterns.EndPattern;

                Assert.AreEqual(expectedStart, resultStart);
                Assert.AreEqual(expectedEnd, resultEnd);
            }
        }
示例#2
0
        /// <summary>
        /// Calculate range for input dates
        /// </summary>
        /// <param name="startDate">
        /// Start range date
        /// </param>
        /// <param name="endDate">
        /// End range date
        /// </param>
        /// <returns>
        /// Calculated range
        /// </returns>
        public string CalculateRange(DateTime startDate, DateTime endDate)
        {
            Validator = new DatesOrderValidation(new DateTime[] { startDate, endDate });

            if (!Validator.IsValid)
            {
                _customILogger.Error(Validator.Message);
                return(null);
            }

            if (startDate.Equals(endDate))
            {
                return(GetRangeForSameDates(startDate));
            }

            PatternsDTO patterns = _patternsUtil.GetPatterns(startDate, endDate);

            return(GetRangeWithSeparator(startDate, endDate, patterns.StartPattern, patterns.EndPattern));
        }
示例#3
0
        public void CheckEndPatternForSameDates()
        {
            Mock <ICultureUtil> cultureUtilMock = new Mock <ICultureUtil>();

            foreach (ShortDateTimeInfo pas in patternsAndSeparators)
            {
                cultureUtilMock.Setup(m => m.ShortDatePattern).Returns(pas.ShortDatePattern);
                cultureUtilMock.Setup(m => m.DateSeparator).Returns(pas.DateSeparator);

                DateTime today = DateTime.Now.Date;

                IPatternsUtil patternsUtil   = container.Resolve <IPatternsUtil>(new TypedParameter(typeof(ICultureUtil), cultureUtilMock.Object));
                PatternsDTO   resultPatterns = patternsUtil.GetPatterns(today, today);

                string expected = pas.ShortDatePattern;
                string result   = resultPatterns.EndPattern;

                Assert.AreEqual(expected, result);
            }
        }