public void IsTimeSlogValidForBoard_TimeIsNotSpecified_ThrowsException() { var unitUnderTest = new SchedulingBoard(Guid.NewGuid()); var timeSlot = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Control); Assert.Throws <ArgumentNullException>(() => unitUnderTest.IsTimeSlogValidForBoard(timeSlot)); }
public void GetTimeForTimeSlot_EmptyBoard_Success() { var unitUnderTest = new SchedulingBoard(Guid.NewGuid()) { StartsAt = DateTime.Today.Date.AddDays(1).AddHours(8) }; var scheduledAt = unitUnderTest.GetTimeForTimeSlot(TimeSlotFactory.CreateTimeSlot(TimeSlotType.Control)); Assert.NotNull(scheduledAt); Assert.Equal(unitUnderTest.StartsAt, scheduledAt); }
public void IsTimeSlogValidForBoard_TimeSlotIsBeforeStartOfBoard_Success() { var unitUnderTest = new SchedulingBoard(Guid.NewGuid()) { StartsAt = DateTime.Now.AddHours(2) }; var timeSlot = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Control); timeSlot.SetTime(DateTime.Now.AddHours(1)); var result = unitUnderTest.IsTimeSlogValidForBoard(timeSlot); Assert.False(result); }
public async Task GetTimeSlotDetailsAsync_HandleResult_Success() { var id = Guid.NewGuid(); var timeSlot = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Control); var schedulingRepositoryMock = new Mock <ISchedulingRepository>(); schedulingRepositoryMock.Setup(m => m.FetchTimeSlotAsync(id)).ReturnsAsync(timeSlot); var unitUnderTest = new TimeSlotController(schedulingRepositoryMock.Object); var result = await unitUnderTest.GetTimeSlotDetailsAsync(id); Assert.IsType <OkObjectResult>(result); Assert.Equal(timeSlot.Id, (((ObjectResult)result).Value as TimeSlot)?.Id); }
public void GetTimeForTimeSlot_FreeSpotOnBeginningOfInterval_Success() { var unitUnderTest = new SchedulingBoard(Guid.NewGuid()) { StartsAt = DateTime.Today.Date.AddDays(1).AddHours(8) }; var timeSlot = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Control); timeSlot.SetTime(unitUnderTest.StartsAt.AddHours(2)); unitUnderTest.AddTimeSlot(timeSlot); var scheduledAt = unitUnderTest.GetTimeForTimeSlot(TimeSlotFactory.CreateTimeSlot(TimeSlotType.Control)); Assert.NotNull(scheduledAt); Assert.Equal(unitUnderTest.StartsAt, scheduledAt); }
public void AddTimeSlot_TimeSlotWithoutTimeNotPossible_Success() { var unitUnderTest = new SchedulingBoard(Guid.NewGuid()) { StartsAt = DateTime.Today.Date.AddDays(1).AddHours(8) }; for (int i = 0; i < 4; i++) { var timeSlot = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Intervention); timeSlot.SetTime(unitUnderTest.StartsAt.AddMinutes(120 * i)); unitUnderTest.AddTimeSlot(timeSlot); } var result = unitUnderTest.AddTimeSlot(TimeSlotFactory.CreateTimeSlot(TimeSlotType.Control)); Assert.False(result); }
public void Usage_FullBoardButBreaksDoesNotCount_Success() { var unitUnderTest = new SchedulingBoard(Guid.NewGuid()) { StartsAt = DateTime.Today.Date.AddDays(1).AddHours(8) }; for (int i = 0; i < 4; i++) { var timeSlotIntervention = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Intervention); timeSlotIntervention.SetTime(unitUnderTest.StartsAt.AddMinutes(120 * i)); unitUnderTest.AddTimeSlot(timeSlotIntervention); } var result = unitUnderTest.Usage; Assert.Equal((decimal)0.75, result); }
public void Usage_FullBoard_Success() { var unitUnderTest = new SchedulingBoard(Guid.NewGuid()) { StartsAt = DateTime.Today.Date.AddDays(1).AddHours(8) }; for (int i = 0; i < 16; i++) { var timeSlot = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Control); timeSlot.SetTime(unitUnderTest.StartsAt.AddMinutes(30 * i)); unitUnderTest.AddTimeSlot(timeSlot); } var result = unitUnderTest.Usage; Assert.Equal(1, result); }
public void IsTimeSlogValidForBoard_OverlappingAtTheEnd_Success() { var unitUnderTest = new SchedulingBoard(Guid.NewGuid()) { StartsAt = DateTime.Today.Date.AddDays(1).AddHours(8) }; var timeSlotExamination = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Examination); timeSlotExamination.SetTime(unitUnderTest.StartsAt.AddHours(1)); unitUnderTest.AddTimeSlot(timeSlotExamination); var timeSlotControl = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Examination); timeSlotControl.SetTime(unitUnderTest.StartsAt.AddMinutes(30)); var isValid = unitUnderTest.IsTimeSlogValidForBoard(timeSlotControl); Assert.False(isValid); }
public DateTime?GetTimeForTimeSlot(TimeSlot timeSlot) { var timeSlotCandidate = TimeSlotFactory.CreateTimeSlot(timeSlot.TimeSlotType); timeSlotCandidate.SetTime(StartsAt < DateTime.Now ? DateTime.Now : StartsAt); if (IsTimeSlogValidForBoard(timeSlotCandidate)) { return(timeSlotCandidate.ScheduledFor); } foreach (var alreadyScheduledTimeSlots in SchedulerTimeSlot.Where(m => m.MandatoryBreakConcludesAt.HasValue)) { timeSlotCandidate.SetTime(alreadyScheduledTimeSlots.MandatoryBreakConcludesAt.GetValueOrDefault()); if (IsTimeSlogValidForBoard(timeSlotCandidate)) { return(timeSlotCandidate.ScheduledFor); } } return(null); }
public void GetTimeForTimeSlot_BoardIsCompletelyFull_Success() { var unitUnderTest = new SchedulingBoard(Guid.NewGuid()) { StartsAt = DateTime.Today.Date.AddDays(1).AddHours(8) }; for (int i = 0; i < 3; i++) { var timeSlotIntervention = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Intervention); timeSlotIntervention.SetTime(unitUnderTest.StartsAt.AddHours(2 * i)); unitUnderTest.AddTimeSlot(timeSlotIntervention); } var timeSlotExamination = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Examination); timeSlotExamination.SetTime(unitUnderTest.StartsAt.AddHours(6)); unitUnderTest.AddTimeSlot(timeSlotExamination); var scheduledAt = unitUnderTest.GetTimeForTimeSlot(TimeSlotFactory.CreateTimeSlot(TimeSlotType.Intervention)); Assert.Null(scheduledAt); }
public void GetTimeForTimeSlot_FreeSpotAtTheEndOfIntervalNoTimeForBreak_Success() { var unitUnderTest = new SchedulingBoard(Guid.NewGuid()) { StartsAt = DateTime.Today.Date.AddDays(1).AddHours(8) }; for (int i = 0; i < 3; i++) { var timeSlotIntervention = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Intervention); timeSlotIntervention.SetTime(unitUnderTest.StartsAt.AddHours(2 * i)); unitUnderTest.AddTimeSlot(timeSlotIntervention); } var timeSlotControl = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Control); timeSlotControl.SetTime(unitUnderTest.StartsAt.AddHours(6)); unitUnderTest.AddTimeSlot(timeSlotControl); var scheduledAt = unitUnderTest.GetTimeForTimeSlot(TimeSlotFactory.CreateTimeSlot(TimeSlotType.Intervention)); Assert.NotNull(scheduledAt); Assert.NotEqual(unitUnderTest.StartsAt, scheduledAt); }
public void SetTime_TimeInPast_ThrowsException() { var unitUnderTest = TimeSlotFactory.CreateTimeSlot(TimeSlotType.Control); Assert.Throws <ArgumentException>(() => unitUnderTest.SetTime(DateTime.Now.AddHours(-1))); }
public void CreateTimeSlot_UnknownType_ThrowsException() { Assert.Throws <ArgumentException>(() => TimeSlotFactory.CreateTimeSlot((TimeSlotType)(-1))); }
public virtual TimeSlot ToEntity() { return(TimeSlotFactory.CreateTimeSlot(TimeSlotType)); }