public void ParseTest(List<TimePeriodToken> TimePeriodTokens, List<Shift> expectedShifts)
        {
            var parser = new ShiftsFactory(TimePeriodTokens, task, date, interval, exceedingAllowed);

            var actualShifts = parser.Parse();

            Assert.IsTrue(expectedShifts.SequenceEqual<Shift>(actualShifts));
        }
        public void Parse_NoShifts_ErrorLoggedWithEmptyResult()
        {
            ErrorLogger.ClearLog();
            var tokenList = ShiftsStatement.NoStatement.AsTokens();
            var parser = new ShiftsFactory(tokenList, task, date, interval, exceedingAllowed);

            var actualShifts = parser.Parse();
            var expectedErrorMessage = new ErrorMessage(new DanishMessageContentProvider().GetMessageNoStatementInShiftsField(task.Name, date));

            Assert.IsTrue(actualShifts.Count == 0
                && ErrorLogger.LoggedErrors.Count == 1
                && ErrorLogger.LoggedErrors.Contains(expectedErrorMessage));
        }
        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;
        }