public void ScanTest(string shiftsField, List<TimePeriodToken> expectedTokens) { var scanner = new TimePeriodScanner(shiftsField); scanner.Scan(); var actualTokens = scanner.Tokens; Assert.IsTrue(expectedTokens.SequenceEqual<TimePeriodToken>(actualTokens)); }
public List<Shift> MakeShifts(Task task, List<ShiftsSpecification> shiftsSpecifications) { var shifts = new List<Shift>(); DateTime date; string datePattern = "dd-MM-yyyy"; bool exceedingAllowed = true; var orderedShiftsSpecifications = shiftsSpecifications.OrderBy(x => x.Date); ShiftsSpecification previousShiftsSpec = null; foreach (var shiftsSpec in orderedShiftsSpecifications) { var scanner = new TimePeriodScanner(shiftsSpec.Declaration); scanner.Scan(); var dateParsedSuccesfully = DateTime.TryParseExact(shiftsSpec.Date, datePattern, null, DateTimeStyles.None, out date); var boolParsedSuccessfully = true; if (shiftsSpec.ExceedingAllowed.Equals("y")) { exceedingAllowed = true; } else if (shiftsSpec.ExceedingAllowed.Equals("n")) { exceedingAllowed = false; } else boolParsedSuccessfully = false; if (dateParsedSuccesfully && boolParsedSuccessfully) { var parser = new ShiftsFactory(scanner.Tokens, task, date, shiftsSpec.Interval, exceedingAllowed); parser.Parse(); shifts.AddRange(parser.Result); } /* To ensure that multiple errors are not logged for the same invalid date format the previous shift specs date. The list is ordered by date. */ else if (previousShiftsSpec != null && shiftsSpec.Date != previousShiftsSpec.Date) { ErrorLogger.LogErrorInvalidDateFormat(shiftsSpec); } previousShiftsSpec = shiftsSpec; } return shifts; }