Example #1
0
        private void TestDeletions()
        {
            // team deletions
            Team[] teams = schedule.Teams.ToArray();

            foreach (Team team in teams)
            {
                schedule.DeleteTeam(team);
            }
            Assert.IsTrue(schedule.Teams.Count == 0);

            // shift deletions
            Shift[] shifts = schedule.Shifts.ToArray();

            foreach (Shift shift in shifts)
            {
                schedule.DeleteShift(shift);
            }
            Assert.IsTrue(schedule.Shifts.Count == 0);

            // non-working period deletions
            NonWorkingPeriod[] periods = schedule.NonWorkingPeriods.ToArray();

            foreach (NonWorkingPeriod period in periods)
            {
                schedule.DeleteNonWorkingPeriod(period);
            }
            Assert.IsTrue(schedule.NonWorkingPeriods.Count == 0);
        }
Example #2
0
        public void TestExceptions()
        {
            schedule = new WorkSchedule("Exceptions", "Test exceptions");
            Duration  shiftDuration = Duration.FromHours(24);
            LocalTime shiftStart    = new LocalTime(7, 0, 0);

            NonWorkingPeriod period = schedule.CreateNonWorkingPeriod("Non-working", "Non-working period",
                                                                      new LocalDateTime(2017, 1, 1, 0, 0, 0), Duration.FromHours(24));

            try
            {
                period.Duration = Duration.FromSeconds(0);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                // same period
                schedule.CreateNonWorkingPeriod("Non-working", "Non-working period", new LocalDateTime(2017, 1, 1, 0, 0, 0),
                                                Duration.FromHours(24));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            // shift
            Shift shift = schedule.CreateShift("Test", "Test shift", shiftStart, shiftDuration);

            try
            {
                // crosses midnight
                shift.CalculateWorkingTime(shiftStart.Minus(Period.FromHours(1)), shift.GetEnd().PlusHours(1));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                shift.Duration = Duration.FromSeconds(0);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                shift.Duration = Duration.FromSeconds(48 * 3600);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                // same shift
                shift = schedule.CreateShift("Test", "Test shift", shiftStart, shiftDuration);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            Rotation rotation = new Rotation("Rotation", "Rotation");

            rotation.AddSegment(shift, 5, 2);

            LocalDate startRotation = new LocalDate(2016, 12, 31);
            Team      team          = schedule.CreateTeam("Team", "Team", rotation, startRotation);

            // ok
            schedule.CalculateWorkingTime(new LocalDateTime(2017, 1, 1, 7, 0, 0), new LocalDateTime(2017, 2, 1, 0, 0, 0));

            try
            {
                // end before start
                schedule.CalculateWorkingTime(new LocalDateTime(2017, 1, 2, 0, 0, 0), new LocalDateTime(2017, 1, 1, 0, 0, 0));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                // same team
                team = schedule.CreateTeam("Team", "Team", rotation, startRotation);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                // date before start
                team.GetDayInRotation(new LocalDate(2016, 1, 1));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                // end before start
                schedule.PrintShiftInstances(new LocalDate(2017, 1, 2), new LocalDate(2017, 1, 1));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            try
            {
                // delete in-use shift
                schedule.DeleteShift(shift);
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            // breaks
            Break lunch = shift.CreateBreak("Lunch", "Lunch", new LocalTime(12, 0, 0), Duration.FromMinutes(60));

            lunch.Duration  = Duration.FromMinutes(30);
            lunch.StartTime = new LocalTime(11, 30, 0);
            shift.RemoveBreak(lunch);
            shift.RemoveBreak(lunch);

            Shift shift2 = schedule.CreateShift("Test2", "Test shift2", shiftStart, shiftDuration);

            Assert.IsFalse(shift.Equals(shift2));

            Break lunch2 = shift2.CreateBreak("Lunch2", "Lunch", new LocalTime(12, 0, 0), Duration.FromMinutes(60));

            shift.RemoveBreak(lunch2);

            // ok to delete
            WorkSchedule schedule2 = new WorkSchedule("Exceptions2", "Test exceptions2");

            schedule2.Name        = "Schedule 2";
            schedule2.Description = "a description";

            schedule2.DeleteShift(shift);
            schedule2.DeleteTeam(team);
            schedule2.DeleteNonWorkingPeriod(period);

            // nulls
            try
            {
                schedule.CreateShift(null, "1", shiftStart, Duration.FromMinutes(60));
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            Assert.IsFalse(shift.Equals(rotation));

            // hashcode()
            team.GetHashCode();
            String name = team.Name;
            Dictionary <String, Team> teams = new Dictionary <String, Team>();

            teams[name] = team;
            Team t = teams[name];
        }