public void GetTimesTest() { // Set up the mock for the service var mockAppointmentService = new Mock <IAppointmentService>(); mockAppointmentService.Setup(a => a.GetAllAppointments()).Returns(CreateTestAppointments); // Get the mocked appointment API controller var appointmentApiController = new AppointmentApiController(mockAppointmentService.Object); // Get the unavailable dates var timesResponse = appointmentApiController.GetTimes(DATE_FULL); // Make sure the response is of the correct type Assert.IsType <JsonResult>(timesResponse); // Get the list of times as dynamic object var times = timesResponse.Value as dynamic; // Create a list of times List <String> occupiedTimes = new List <String>(); // Loop through the values, keep track of the count int timeCount = 0; // Create a list of expected values List <string> expectedValues = new List <string>() { "{ available = True, formattedTime = 09:30, time = { hour = 9, minute = 30, second = 0 } }", "{ available = False, formattedTime = 12:30, time = { hour = 12, minute = 30, second = 0 } }", "{ available = False, formattedTime = 15:00, time = { hour = 15, minute = 0, second = 0 } }" }; // Loop through the results and compare the actual values to the expected foreach (dynamic timeObject in times) { // Compare the values Assert.Equal(timeObject.ToString(), expectedValues[timeCount]); // Increase the time count timeCount++; } // Assert the count Assert.Equal(timeCount, 3); }
public void GetDatesTest() { // Set up the mock for the service var mockAppointmentService = new Mock <IAppointmentService>(); mockAppointmentService.Setup(a => a.GetAllAppointments()).Returns(CreateTestAppointments); // Get the mocked appointment API controller var appointmentApiController = new AppointmentApiController(mockAppointmentService.Object); // Get the unavailable dates var datesResponse = appointmentApiController.GetDates(); // Make sure the response is of the correct type Assert.IsType <JsonResult>(datesResponse); // Get the list of dates as dynamic object var dates = datesResponse.Value as dynamic; // Loop through the values, keep track of the count int count = 0; foreach (var dateString in dates) { // Make sure the value is a string Assert.IsType <String>(dateString); // Make sure this date equals the full date Assert.Equal(dateString, DATE_FULL); // Increase the count count++; } // Assert the count Assert.Equal(count, 1); }