using Core.Entities;
namespace Tests.Builders;
///
/// Helper utilities for working with test data builders.
///
public static class BuilderExtensions
{
///
/// Resets all builder ID counters to 1.
/// Call this in test SetUp to ensure test isolation.
///
public static void ResetAllBuilders()
{
EventDefinitionBuilder.ResetIdCounter();
StudentBuilder.ResetIdCounter();
TeamBuilder.ResetIdCounter();
}
///
/// Creates a student with event rankings for multiple events.
///
/// The student builder
/// Dictionary of events to their ranks (1-10)
/// The builder for method chaining
public static StudentBuilder WithRankings(this StudentBuilder builder, Dictionary rankedEvents)
{
foreach (var (eventDef, rank) in rankedEvents)
{
builder.WithRanking(eventDef, rank);
}
return builder;
}
///
/// Creates a team with a captain as the first student.
///
/// The team builder
/// Students to add (first one becomes captain)
/// The builder for method chaining
public static TeamBuilder WithStudentsAndCaptain(this TeamBuilder builder, params Student[] students)
{
if (students.Length == 0)
return builder;
builder.WithStudents(students);
builder.WithCaptain(students[0]);
return builder;
}
///
/// Creates multiple event definitions at once.
///
/// Event names
/// Array of individual event definitions
public static EventDefinition[] CreateIndividualEvents(params string[] names)
{
return names.Select(name => EventDefinitionBuilder.Individual(name).Build()).ToArray();
}
///
/// Creates multiple students at once with sequential names.
///
/// Number of students to create
/// Base first name (will be suffixed with numbers)
/// Base last name
/// Array of students
public static Student[] CreateStudents(int count, string baseFirstName = "Student", string baseLastName = "Test")
{
var students = new Student[count];
for (int i = 0; i < count; i++)
{
students[i] = StudentBuilder.Default()
.WithName($"{baseFirstName}{i + 1}", baseLastName)
.Build();
}
return students;
}
}