Verified every finding against the code, then fixed correctness (redirects, advancement reset, duplicate heats, high-jump attempt entry, placement ranking with tie handling, delete-dependency 500s), security (secrets out of config, config-driven admin seed, login lockout, role authorization with school scoping, heat-time IDOR, forwarded headers, last-admin guards), schema integrity (nullable+filtered ExistingStudentId, unique indexes for rounds/heats/bar heights via SchemaIntegrityFixes migration), performance (N+1 removal in high jump/reports/standings/dashboard, SQL-side student paging), and hygiene (duplicate notifications, auto-dismiss scope, local bootstrap-icons, orphaned files, test-data.sql tournament creation). FluentValidation is now registered; AutoMapper bumped to 14.0.0 (advisory fully patched only in licence-changed 15.1.1 — documented). 11 new tests; 63/63 passing. Credential rotation and deploy-time DB_CONNECTION_STRING are required manual follow-ups, documented in bug-fixes.md. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
100 lines
2.4 KiB
C#
100 lines
2.4 KiB
C#
using SportsDivision.Domain.Entities;
|
|
using SportsDivision.Domain.Enums;
|
|
|
|
namespace SportsDivision.Domain.Tests;
|
|
|
|
public class StudentTests
|
|
{
|
|
[Fact]
|
|
public void GetAge_BirthdayNotYetPassed_ReturnsCorrectAge()
|
|
{
|
|
var student = new Student
|
|
{
|
|
DateOfBirth = new DateOnly(2010, 6, 15)
|
|
};
|
|
|
|
var referenceDate = new DateOnly(2024, 3, 1);
|
|
Assert.Equal(13, student.GetAge(referenceDate));
|
|
}
|
|
|
|
[Fact]
|
|
public void GetAge_BirthdayAlreadyPassed_ReturnsCorrectAge()
|
|
{
|
|
var student = new Student
|
|
{
|
|
DateOfBirth = new DateOnly(2010, 3, 15)
|
|
};
|
|
|
|
var referenceDate = new DateOnly(2024, 6, 1);
|
|
Assert.Equal(14, student.GetAge(referenceDate));
|
|
}
|
|
|
|
[Fact]
|
|
public void GetAge_OnBirthday_ReturnsCorrectAge()
|
|
{
|
|
var student = new Student
|
|
{
|
|
DateOfBirth = new DateOnly(2010, 6, 15)
|
|
};
|
|
|
|
var referenceDate = new DateOnly(2024, 6, 15);
|
|
Assert.Equal(14, student.GetAge(referenceDate));
|
|
}
|
|
|
|
[Fact]
|
|
public void GetAge_DayBeforeBirthday_ReturnsOneLess()
|
|
{
|
|
var student = new Student
|
|
{
|
|
DateOfBirth = new DateOnly(2010, 6, 15)
|
|
};
|
|
|
|
var referenceDate = new DateOnly(2024, 6, 14);
|
|
Assert.Equal(13, student.GetAge(referenceDate));
|
|
}
|
|
|
|
[Fact]
|
|
public void GetAge_LeapYearBirthday_Feb29_ReferenceNonLeapYear()
|
|
{
|
|
var student = new Student
|
|
{
|
|
DateOfBirth = new DateOnly(2012, 2, 29) // leap year
|
|
};
|
|
|
|
// March 1, 2025 — non-leap year; the Feb 29 birthday is treated as passed
|
|
var referenceDate = new DateOnly(2025, 3, 1);
|
|
Assert.Equal(13, student.GetAge(referenceDate));
|
|
}
|
|
|
|
[Fact]
|
|
public void GetAge_SameDayAsReference_ReturnsZero()
|
|
{
|
|
var student = new Student
|
|
{
|
|
DateOfBirth = new DateOnly(2024, 1, 1)
|
|
};
|
|
|
|
var referenceDate = new DateOnly(2024, 1, 1);
|
|
Assert.Equal(0, student.GetAge(referenceDate));
|
|
}
|
|
|
|
[Fact]
|
|
public void FullName_CombinesFirstAndLastName()
|
|
{
|
|
var student = new Student
|
|
{
|
|
FirstName = "John",
|
|
LastName = "Doe"
|
|
};
|
|
|
|
Assert.Equal("John Doe", student.FullName);
|
|
}
|
|
|
|
[Fact]
|
|
public void FullName_DefaultValues_ReturnsSpace()
|
|
{
|
|
var student = new Student();
|
|
Assert.Equal(" ", student.FullName);
|
|
}
|
|
}
|