Ejemplo n.º 1
0
        public override void WriteActualValueTo(MessageWriter writer)
        {
            //IF actual is not empty it means we've an issue with Casing or a space at the end
            if (!(actual is IEnumerable <string>))
            {
                return;
            }

            var isApproximate = false;

            foreach (var actualItem in (actual as IEnumerable <string>))
            {
                var text = string.Empty;
                if (actualItem.ToLowerInvariant() == Expected.ToLowerInvariant())
                {
                    text = string.Format("< <{0}> > (case not matching)", actualItem);
                }
                else if (actualItem.TrimEnd() == Expected)
                {
                    text = string.Format("< <{0}> > (with ending space(s))", actualItem);
                }
                else if (actualItem.TrimStart() == Expected)
                {
                    text = string.Format("< <{0}> > (with leading space(s))", actualItem);
                }
                else if (actualItem.ToLowerInvariant().Trim() == Expected.ToLowerInvariant().Trim())
                {
                    text = string.Format("< <{0}> > (small difference)", actualItem);
                }

                if (!string.IsNullOrEmpty(text))
                {
                    writer.WriteActualValue(text);
                    isApproximate = true;
                }
            }

            if (!isApproximate)
            {
                if (((IEnumerable <string>)actual).Count() == 0)
                {
                    writer.WriteActualValue(new WriterHelper.NothingFoundMessage());
                }
                else
                {
                    base.WriteActualValueTo(writer);
                    var closeMatch = GetCloseMatch();
                    if (!string.IsNullOrEmpty(closeMatch))
                    {
                        writer.WriteMessageLine("");
                        writer.WriteMessageLine("");
                        writer.WriteMessageLine(string.Format("The value '{0}' is close to your expectation.", closeMatch));
                        writer.DisplayStringDifferences(Expected, closeMatch, -1, false, true);
                    }
                }
            }
        }
        public DateTime?GetNextRunDate(ScheduleInfo scheduleInfo, Schedule schedule, DateTime?lastFromDate)
        {
            var curDate = scheduleInfo.ScheduleFromDate.Value;

            if (lastFromDate.HasValue)
            {
                curDate = lastFromDate.Value;
            }
            var curTime      = DateTime.Parse(Time);
            var curDateTime  = new DateTime(curDate.Year, curDate.Month, curDate.Day, curTime.Hour, curTime.Minute, curTime.Second);
            var nextDateTime = curDateTime;

            switch (Expected.ToLowerInvariant())
            {
            case "daily":
                if (lastFromDate.HasValue && lastFromDate.Value == curDateTime)
                {
                    try
                    {
                        return(nextDateTime.AddDays(1));
                    }
                    catch
                    {
                        return(null);
                    }
                }

                if (IsGoodTimeForToday(nextDateTime))
                {
                    return(nextDateTime);
                }

                try
                {
                    return(nextDateTime.AddDays(1));
                }
                catch
                {
                    return(null);
                }

            case "weekly":
                if (lastFromDate.HasValue && lastFromDate.Value == curDateTime)
                {
                    try
                    {
                        nextDateTime = nextDateTime.AddDays(1);
                    }
                    catch
                    {
                        return(null);
                    }
                }

                if (IsGoodDayOfWeek(nextDateTime) && IsGoodTimeForToday(nextDateTime))
                {
                    return(nextDateTime);
                }

                while (!IsGoodDayOfWeek(nextDateTime))
                {
                    try
                    {
                        nextDateTime = nextDateTime.AddDays(1);
                    }
                    catch
                    {
                        return(null);
                    }
                }
                return(nextDateTime);

            case "monthly":
                if (lastFromDate.HasValue && lastFromDate.Value == curDateTime)
                {
                    try
                    {
                        nextDateTime = nextDateTime.AddDays(1);
                    }
                    catch
                    {
                        return(null);
                    }
                }

                if (IsGoodMonthOfYear(nextDateTime) && IsGoodDayOfMonth(nextDateTime) && IsGoodTimeForToday(nextDateTime))
                {
                    return(nextDateTime);
                }

                while (!(IsGoodMonthOfYear(nextDateTime) && IsGoodDayOfMonth(nextDateTime)))
                {
                    try
                    {
                        nextDateTime = nextDateTime.AddDays(1);
                    }
                    catch
                    {
                        return(null);
                    }
                }
                return(nextDateTime);
            }
            return(null);
        }
Ejemplo n.º 3
0
        public override void WriteActualValueTo(MessageWriter writer)
        {
            //IF actual is not empty it means we've an issue with Casing or a space at the end
            if (actual is IEnumerable <IField> && ((IEnumerable <IField>)actual).Count() == 1)
            {
                if (((IEnumerable <IField>)actual).ToArray()[0].Caption.ToLowerInvariant() == Expected.ToLowerInvariant())
                {
                    writer.WriteActualValue(string.Format("< <{0}> > (case not matching)", ((IEnumerable <IField>)actual).ToArray()[0].Caption));
                }
                else if (((IEnumerable <IField>)actual).ToArray()[0].Caption.EndsWith(" "))
                {
                    writer.WriteActualValue(string.Format("< <{0}> > (with ending space(s))", ((IEnumerable <IField>)actual).ToArray()[0].Caption));
                }
                else
                {
                    writer.WriteActualValue(string.Format("< <{0}> > (small difference)", ((IEnumerable <IField>)actual).ToArray()[0].Caption));
                }
            }
            else
            {
                Investigate();

                if (actual is IEnumerable <IField> && ((IEnumerable <IField>)actual).Count() > 0)
                {
                    base.WriteActualValueTo(writer);
                }
                else
                {
                    writer.WriteActualValue(new WriterHelper.NothingFoundMessage());
                }

                var closeMatch = GetCloseMatch();
                if (!string.IsNullOrEmpty(closeMatch))
                {
                    writer.WriteMessageLine("");
                    writer.WriteMessageLine("");
                    writer.WriteMessageLine(string.Format("The value '{0}' is close to your expectation.", closeMatch));
                    writer.DisplayStringDifferences(Expected, closeMatch, -1, false, true);
                }
            }
        }