371 questions
Unit test always returning an empty list on Nunit yet has console output
NOVATROOP77
266
Reputation points
Why is this unit test failing even though when I check the console it is indead printing out each of the appointment slots why is my lists empty I am using NUINT. When I inspect the first list its null appointmentsSlots.
I no the logic works here in the dotnet fiddle. https://dotnetfiddle.net/xZYQvd
[TestCase(1, 1, "Dan")]//Bike , Student 1 , Slot 1
[TestCase(1, 2, "David")]//Bike , Student 1 , Slot 2
[TestCase(2, 1, "David")]//Weights , Student 1 , Slot 1
[TestCase(2, 2, "Dan")]//Weights , Student 1 , Slot 1
public void TestAppointmentSlots(int workoutType, int studentId, string studentName)
{
List<WorkoutAppointments> workoutAppointments = new List<WorkoutAppointments>();
List<AppointmentSlot> appointmentsSlots = new List<AppointmentSlot>();
int durationOfSession = 10;
int gapBetweenSessions = 0;
DateTime start = DateTime.Today.AddHours(9).AddMinutes(30);
DateTime end = DateTime.Today.AddHours(8).AddMinutes(30);
DateTime[] datetime;
for (DateTime appointment = start; appointment < end; appointment = appointment.AddMinutes(durationOfSession + gapBetweenSessions))
{
AppointmentSlot slot = new AppointmentSlot
{
SlotType = 1,
Year = start.Year,
Hour = start.Hour,
StartDate = start,
EndDate = end,
IsActive = true,
IsDeleted = false,
IsAvailable = false,
};
appointmentsSlots.Add(slot);
Console.Write(appointment
.ToString("HH:mm"));
}
foreach (var appointment in appointmentsSlots)
{
WorkoutAppointments workoutAppointment = new WorkoutAppointments();
workoutAppointment.Id = workoutAppointment.Id + 1;
workoutAppointment.StudentId = studentId;
workoutAppointment.StudentName = studentName;
workoutAppointment.StartTime = appointment.StartDate;
workoutAppointment.EndTime = appointment.EndDate;
workoutAppointment.Year = appointment.StartDate.Year;
workoutAppointment.Hour = appointment.StartDate.Hour;
workoutAppointment.Duration = durationOfSession;
workoutAppointment.IsStudentFinishedWorkOut = false;
workoutAppointment.IsActive = true;
workoutAppointment.IsDeleted = false;
workoutAppointments.Add(workoutAppointment);
}
Assert.AreEqual(appointmentsSlots.Count, 60);
}
Developer technologies Visual Studio Testing
Developer technologies C#
11,568 questions
Sign in to answer