Introduce unit testing on calculation objects
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
using Core.Entities;
|
||||
|
||||
namespace Tests.Builders;
|
||||
|
||||
/// <summary>
|
||||
/// Fluent builder for creating EventDefinition test entities.
|
||||
/// </summary>
|
||||
public class EventDefinitionBuilder
|
||||
{
|
||||
private static int _idCounter = 1;
|
||||
|
||||
private int _id = _idCounter++;
|
||||
private string _name = "Test Event";
|
||||
private string _shortName = "Test";
|
||||
private EventFormat _format = EventFormat.Individual;
|
||||
private int _minTeamSize = 1;
|
||||
private int _maxTeamSize = 1;
|
||||
private string? _semifinalistActivity = null;
|
||||
private bool _onSiteActivity = false;
|
||||
private int _regionalCount = 0;
|
||||
private int _stateCount = 2;
|
||||
private bool _presubmission = false;
|
||||
private string _eligibility = "All students";
|
||||
private string? _theme = null;
|
||||
private string? _description = null;
|
||||
private int? _levelOfEffort = null;
|
||||
private string? _documentation = null;
|
||||
private string? _notes = null;
|
||||
|
||||
public EventDefinitionBuilder WithName(string name)
|
||||
{
|
||||
_name = name;
|
||||
if (_shortName == "Test") _shortName = name; // Auto-sync short name
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder WithShortName(string shortName)
|
||||
{
|
||||
_shortName = shortName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder AsTeamEvent(int minSize, int maxSize)
|
||||
{
|
||||
_format = EventFormat.Team;
|
||||
_minTeamSize = minSize;
|
||||
_maxTeamSize = maxSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder AsIndividualEvent()
|
||||
{
|
||||
_format = EventFormat.Individual;
|
||||
_minTeamSize = 1;
|
||||
_maxTeamSize = 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder WithInterview()
|
||||
{
|
||||
_semifinalistActivity = "Interview";
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder WithPresentation()
|
||||
{
|
||||
_semifinalistActivity = "Presentation";
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder WithSemifinalistActivity(string activity)
|
||||
{
|
||||
_semifinalistActivity = activity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder AsOnSite()
|
||||
{
|
||||
_onSiteActivity = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder AsRegionalEvent(int count = 3)
|
||||
{
|
||||
_regionalCount = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder WithStateCount(int count)
|
||||
{
|
||||
_stateCount = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder WithPresubmission()
|
||||
{
|
||||
_presubmission = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder WithEligibility(string eligibility)
|
||||
{
|
||||
_eligibility = eligibility;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder WithTheme(string theme)
|
||||
{
|
||||
_theme = theme;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder WithDescription(string description)
|
||||
{
|
||||
_description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder WithLevelOfEffort(int level)
|
||||
{
|
||||
_levelOfEffort = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder WithDocumentation(string documentation)
|
||||
{
|
||||
_documentation = documentation;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinitionBuilder WithNotes(string notes)
|
||||
{
|
||||
_notes = notes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventDefinition Build()
|
||||
{
|
||||
return new EventDefinition
|
||||
{
|
||||
Id = _id,
|
||||
Name = _name,
|
||||
ShortName = _shortName,
|
||||
EventFormat = _format,
|
||||
MinTeamSize = _minTeamSize,
|
||||
MaxTeamSize = _maxTeamSize,
|
||||
SemifinalistActivity = _semifinalistActivity,
|
||||
OnSiteActivity = _onSiteActivity,
|
||||
ChapterEligibilityCountRegionals = _regionalCount,
|
||||
ChapterEligibilityCountState = _stateCount,
|
||||
Presubmission = _presubmission,
|
||||
Eligibility = _eligibility,
|
||||
Theme = _theme,
|
||||
Description = _description,
|
||||
LevelOfEffort = _levelOfEffort,
|
||||
Documentation = _documentation,
|
||||
Notes = _notes
|
||||
};
|
||||
}
|
||||
|
||||
// Static factory methods
|
||||
public static EventDefinitionBuilder Default() => new EventDefinitionBuilder();
|
||||
|
||||
public static EventDefinitionBuilder Individual(string name) =>
|
||||
new EventDefinitionBuilder()
|
||||
.WithName(name)
|
||||
.AsIndividualEvent();
|
||||
|
||||
public static EventDefinitionBuilder Team(string name, int minSize, int maxSize) =>
|
||||
new EventDefinitionBuilder()
|
||||
.WithName(name)
|
||||
.AsTeamEvent(minSize, maxSize);
|
||||
|
||||
/// <summary>
|
||||
/// Reset the ID counter for test isolation. Call this in test SetUp.
|
||||
/// </summary>
|
||||
public static void ResetIdCounter() => _idCounter = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user