public IActionResult GetEmployees() { try { var employees = _employeeQuery.GetEmployees(); return(Ok(employees)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public async Task Should_Return200OK_When_ValidParametersFor_GetSuitableMeetings() { var apiEndpoint = "/meetings?EmployeeIds=23&EmployeeIds=43&EmployeeIds=345&DesiredMeetingLength=30&" + "requestedEarliestMeetingTime=11/23/2019 08:00:00&requestedLatestMeetingTime=11/23/2019 09:00:00&" + "officeHoursStartTime=08:00:00&officeHoursEndTime=10:00:00"; A.CallTo(() => _employeeQuery.GetEmployees(A <IEnumerable <string> > ._)) .Returns(Task.FromResult(A.Dummy <IEnumerable <Employee> >())); var response = await _client.GetAsync(apiEndpoint); A.CallTo(() => _employeeQuery.GetEmployees(A <IEnumerable <string> > .That.IsSameSequenceAs("23", "43", "345"))) .MustHaveHappenedOnceExactly(); var requestedEarliestTime = (DateTime.Parse("11/23/2019 08:00:00"), DateTime.Parse("11/23/2019 09:00:00")); var officeHours = (TimeSpan.Parse("08:00:00"), TimeSpan.Parse("10:00:00")); A.CallTo(() => _meetingQuery.GetSuitableMeetings(A <IEnumerable <BusySlot> > ._, 30, requestedEarliestTime, officeHours)) .MustHaveHappened(); response.EnsureSuccessStatusCode(); response.StatusCode.Should().Be(StatusCodes.Status200OK); }
public async Task <ActionResult <IEnumerable <Meeting> > > GetSuitableMeetings([FromQuery] SuitableMeetingsRequest suitableMeetingsRequest) { var validationResult = _validator.Validate(suitableMeetingsRequest); if (!validationResult.IsValid) { return(BadRequest(validationResult)); } var employees = await _employeeQuery.GetEmployees(suitableMeetingsRequest.EmployeeIds ?? new List <string>()); var allEmployeeBusySlots = employees.Aggregate(new List <BusySlot>() as IEnumerable <BusySlot>, (a, b) => a.Concat(b.BusySlots)); var suitableMeetings = _meetingQuery.GetSuitableMeetings( allEmployeeBusySlots, suitableMeetingsRequest.DesiredMeetingLength, (suitableMeetingsRequest.requestedEarliestMeetingTime, suitableMeetingsRequest.requestedLatestMeetingTime), (suitableMeetingsRequest.officeHoursStartTime, suitableMeetingsRequest.officeHoursEndTime)); return(Ok(suitableMeetings)); }