Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit tests for Availability.IsNotAvailable #132

Merged
merged 1 commit into from
Jan 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Features/AvailabilityHours/Availability.cs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ public static class Availability
/// <param name="newEndHour">La nueva hora de finalización generada.</param>
/// <param name="unavailableTimeRange">Una instancia con el rango de tiempo no disponible.</param>
/// <returns><c>true</c> sí la nueva franja de horario no está disponible, de lo contrario devuelve <c>false</c>.</returns>
private static bool IsNotAvailable(ref TimeSpan newStartHour, ref TimeSpan newEndHour, UnavailableTimeRangeDto unavailableTimeRange)
public static bool IsNotAvailable(ref TimeSpan newStartHour, ref TimeSpan newEndHour, UnavailableTimeRangeDto unavailableTimeRange)
=> unavailableTimeRange.StartHour < newEndHour && newStartHour < unavailableTimeRange.EndHour;

/// <summary>
58 changes: 58 additions & 0 deletions tests/Features/AvailabilityHours/AvailabilityTests.cs
Original file line number Diff line number Diff line change
@@ -140,4 +140,62 @@ public void GetAvailableHours_WhenAppointmentDateIsEqualToTheCurrentDate_ShouldD
Assert.AreEqual(expected[i].EndHour, actual: availableHours[i].EndHour);
}
}

[DataTestMethod]
[DataRow("08:20", "09:00",
"09:00", "09:30")]
[DataRow("11:40", "12:20",
"11:00", "11:40")]
[DataRow("10:00", "10:30",
"10:40", "11:20")]
[DataRow("10:00", "10:30",
"09:00", "09:40")]
public void IsNotAvailable_WhenNewTimeRangeIsAvailable_ShouldReturnFalse(string newStartHour,
string newEndHour,
string startHourNotAvailable,
string startEndNotAvailable)
{
var unavailableTimeRange = new UnavailableTimeRangeDto
{
StartHour = TimeSpan.Parse(startHourNotAvailable),
EndHour = TimeSpan.Parse(startEndNotAvailable)
};
var newStartHourSpan = TimeSpan.Parse(newStartHour);
var newEndHourSpan = TimeSpan.Parse(newEndHour);

bool result = Availability.IsNotAvailable(ref newStartHourSpan, ref newEndHourSpan, unavailableTimeRange);

Assert.IsFalse(result);
}

[DataTestMethod]
[DataRow("09:00", "09:30",
"09:00", "09:30")]
[DataRow("09:00", "09:30",
"09:20", "09:35")]
[DataRow("10:00", "10:30",
"10:25", "11:20")]
[DataRow("10:00", "10:30",
"09:00", "10:10")]
[DataRow("10:00", "10:30",
"10:29", "12:00")]
[DataRow("12:20", "12:50",
"12:00", "13:00")]
public void IsNotAvailable_WhenNewTimeRangeIsNotAvailable_ShouldReturnTrue(string newStartHour,
string newEndHour,
string startHourNotAvailable,
string startEndNotAvailable)
{
var unavailableTimeRange = new UnavailableTimeRangeDto
{
StartHour = TimeSpan.Parse(startHourNotAvailable),
EndHour = TimeSpan.Parse(startEndNotAvailable)
};
var newStartHourSpan = TimeSpan.Parse(newStartHour);
var newEndHourSpan = TimeSpan.Parse(newEndHour);

bool result = Availability.IsNotAvailable(ref newStartHourSpan, ref newEndHourSpan, unavailableTimeRange);

Assert.IsTrue(result);
}
}