67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
using MeetTheTeacher.Model;
|
|
|
|
namespace MeetTheTeacher.Test.Model;
|
|
|
|
public sealed class TimeFrameTests
|
|
{
|
|
[Fact]
|
|
public void Construction_Simple()
|
|
{
|
|
var start = new TimeOnly(14, 51);
|
|
var end = new TimeOnly(17, 28);
|
|
|
|
var tf = new TimeFrame(start, end);
|
|
|
|
tf.Start.Should().Be(start);
|
|
tf.End.Should().Be(end);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("10:00-12:00", "10:00", "12:00")]
|
|
[InlineData("14:30-15:00", "14:30", "15:00")]
|
|
[InlineData("09:15-09:45", "09:15", "09:45")]
|
|
public void TryParse_Valid(string input, string expectedStart, string expectedEnd)
|
|
{
|
|
TimeFrame.TryParse(input, out TimeFrame? result).Should().BeTrue();
|
|
|
|
result.Should().NotBeNull();
|
|
result?.Start.Should().Be(TimeOnly.Parse(expectedStart));
|
|
result?.End.Should().Be(TimeOnly.Parse(expectedEnd));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("12:00-10:00", "10:00", "12:00")]
|
|
[InlineData("15:00-14:30", "14:30", "15:00")]
|
|
public void TryParse_StartEndSwapped(string input, string expectedStart, string expectedEnd)
|
|
{
|
|
TimeFrame.TryParse(input, out TimeFrame? result).Should().BeTrue();
|
|
|
|
result.Should().NotBeNull();
|
|
result?.Start.Should().Be(TimeOnly.Parse(expectedStart));
|
|
result?.End.Should().Be(TimeOnly.Parse(expectedEnd));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("invalid-12:00")]
|
|
[InlineData("10:00-invalid")]
|
|
[InlineData("25:00-12:00")]
|
|
[InlineData("10:00-28:00")]
|
|
[InlineData("10:62-22:00")]
|
|
[InlineData("10:a2-22:00")]
|
|
[InlineData(" ")]
|
|
[InlineData("")]
|
|
public void TryParse_InvalidInputs_ReturnsFalse(string input)
|
|
{
|
|
TimeFrame.TryParse(input, out TimeFrame? result).Should().BeFalse();
|
|
|
|
result.Should().BeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void StringRepresentation()
|
|
{
|
|
var timeFrame = new TimeFrame(new TimeOnly(10, 0), new TimeOnly(12, 0));
|
|
|
|
timeFrame.ToString().Should().Be("10:00-12:00");
|
|
}
|
|
}
|