private IPreference GetPreference(string option) { IPreference preference; switch (option.ToUpper()) { case Options.EVERY_DAY_PREFERENCE: preference = new EveryDayPreference(); break; case Options.NEVER_PREFERENCE: preference = new NeverPreference(); break; case Options.DAY_OF_MONTH_PREFERENCE: string dayOfMonthMessage = "Enter the day of month (1 - 28), Any number less than 1 will be taken as 1 and any number greater than 28 will be taken as 28"; preference = ReadConsoleInput(DayOfMonthPreference.Parse, dayOfMonthMessage); break; case Options.DAYS_OF_WEEK_PREFERENCE: _(@"Enter a comma separated list of one or more weekday numbers, from 1 = Sun to 7 = Sat, example ""1,4,5"""); _("if any values are not a number between 1 and 7 the whole input will fail"); preference = ReadConsoleInput(DaysOfWeekPreference.Parse); break; default: throw new FormatException($"Option {option} is not valid, please try again"); } return(preference); }
public void Every_day_preference_determines_correct_result() { IPreference preference = new EveryDayPreference(); for (int d = 1; d <= 31; d++) { DateTime date = new DateTime(2020, 1, d); preference.SendOnDate(date).ShouldBeTrue($"Testing {date:ddd dd/MM/yyyy}"); } }