< Summary

Information
Class: TestUtilities.CoreTestFactories
Assembly: TestUtilities
File(s): /home/runner/work/KicktippAi/KicktippAi/src/TestUtilities/CoreTestFactories.cs
Line coverage
50%
Covered lines: 36
Uncovered lines: 35
Coverable lines: 71
Total lines: 282
Line coverage: 50.7%
Branch coverage
100%
Covered branches: 28
Total branches: 28
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/KicktippAi/KicktippAi/src/TestUtilities/CoreTestFactories.cs

#LineLine coverage
 1using EHonda.KicktippAi.Core;
 2using EHonda.Optional.Core;
 3using NodaTime;
 4
 5namespace TestUtilities;
 6
 7/// <summary>
 8/// Factory methods for creating Core domain objects in tests.
 9/// Use these methods to create test instances with sensible defaults,
 10/// allowing tests to override only the properties relevant to their scenario.
 11/// </summary>
 12public static class CoreTestFactories
 13{
 14    /// <summary>
 15    /// Creates a test <see cref="Match"/> with default values.
 16    /// </summary>
 17    /// <param name="homeTeam">Home team name. Defaults to "Bayern München".</param>
 18    /// <param name="awayTeam">Away team name. Defaults to "Borussia Dortmund".</param>
 19    /// <param name="startsAt">Match start time. Defaults to 2025-03-15 15:30 UTC.</param>
 20    /// <param name="matchday">Matchday number. Defaults to 25.</param>
 21    /// <param name="isCancelled">Whether the match is cancelled. Defaults to false.</param>
 22    public static Match CreateMatch(
 23        Option<string> homeTeam = default,
 24        Option<string> awayTeam = default,
 25        Option<ZonedDateTime> startsAt = default,
 26        Option<int> matchday = default,
 27        Option<bool> isCancelled = default)
 28    {
 129        return new Match(
 130            homeTeam.Or("Bayern München"),
 131            awayTeam.Or("Borussia Dortmund"),
 132            startsAt.Or(() => Instant.FromUtc(2025, 3, 15, 15, 30).InUtc()),
 133            matchday.Or(25),
 134            isCancelled.Or(false));
 35    }
 36
 37    /// <summary>
 38    /// Creates a test <see cref="Prediction"/> with default values.
 39    /// </summary>
 40    /// <param name="homeGoals">Home team goals. Defaults to 2.</param>
 41    /// <param name="awayGoals">Away team goals. Defaults to 1.</param>
 42    /// <param name="justification">Optional prediction justification. Defaults to null.</param>
 43    public static Prediction CreatePrediction(
 44        Option<int> homeGoals = default,
 45        Option<int> awayGoals = default,
 46        NullableOption<PredictionJustification> justification = default)
 47    {
 148        return new Prediction(
 149            homeGoals.Or(2),
 150            awayGoals.Or(1),
 151            justification.Or((PredictionJustification?)null));
 52    }
 53
 54    /// <summary>
 55    /// Creates a test <see cref="PredictionJustification"/> with default values.
 56    /// </summary>
 57    /// <param name="keyReasoning">Key reasoning text. Defaults to "Default test reasoning".</param>
 58    /// <param name="contextSources">Context sources. Defaults to empty sources.</param>
 59    /// <param name="uncertainties">List of uncertainties. Defaults to empty list.</param>
 60    public static PredictionJustification CreatePredictionJustification(
 61        Option<string> keyReasoning = default,
 62        Option<PredictionJustificationContextSources> contextSources = default,
 63        Option<List<string>> uncertainties = default)
 64    {
 165        return new PredictionJustification(
 166            keyReasoning.Or("Default test reasoning"),
 167            contextSources.Or(() => CreatePredictionJustificationContextSources()),
 168            uncertainties.Or(() => []));
 69    }
 70
 71    /// <summary>
 72    /// Creates a test <see cref="PredictionJustificationContextSources"/> with default values.
 73    /// </summary>
 74    /// <param name="mostValuable">Most valuable context sources. Defaults to empty list.</param>
 75    /// <param name="leastValuable">Least valuable context sources. Defaults to empty list.</param>
 76    public static PredictionJustificationContextSources CreatePredictionJustificationContextSources(
 77        Option<List<PredictionJustificationContextSource>> mostValuable = default,
 78        Option<List<PredictionJustificationContextSource>> leastValuable = default)
 79    {
 180        return new PredictionJustificationContextSources(
 181            mostValuable.Or(() => []),
 182            leastValuable.Or(() => []));
 83    }
 84
 85    /// <summary>
 86    /// Creates a test <see cref="PredictionJustificationContextSource"/> with default values.
 87    /// </summary>
 88    /// <param name="documentName">Document name. Defaults to "test-document".</param>
 89    /// <param name="details">Details about the source. Defaults to "test details".</param>
 90    public static PredictionJustificationContextSource CreatePredictionJustificationContextSource(
 91        Option<string> documentName = default,
 92        Option<string> details = default)
 93    {
 094        return new PredictionJustificationContextSource(
 095            documentName.Or("test-document"),
 096            details.Or("test details"));
 97    }
 98
 99    /// <summary>
 100    /// Creates a test <see cref="BonusQuestion"/> with default values.
 101    /// </summary>
 102    /// <param name="text">Question text. Defaults to "Who will win the league?".</param>
 103    /// <param name="deadline">Answer deadline. Defaults to 2025-05-15 18:00 UTC.</param>
 104    /// <param name="options">Available options. Defaults to 3 options: opt-1, opt-2, opt-3.</param>
 105    /// <param name="maxSelections">Maximum selections allowed. Defaults to 1.</param>
 106    /// <param name="formFieldName">Optional form field name. Defaults to null.</param>
 107    public static BonusQuestion CreateBonusQuestion(
 108        Option<string> text = default,
 109        Option<ZonedDateTime> deadline = default,
 110        Option<List<BonusQuestionOption>> options = default,
 111        Option<int> maxSelections = default,
 112        NullableOption<string> formFieldName = default)
 113    {
 1114        var actualOptions = options.Or(() =>
 1115        [
 1116            new("opt-1", "Option 1"),
 1117            new("opt-2", "Option 2"),
 1118            new("opt-3", "Option 3")
 1119        ]);
 120
 1121        return new BonusQuestion(
 1122            text.Or("Who will win the league?"),
 1123            deadline.Or(() => Instant.FromUtc(2025, 5, 15, 18, 0).InUtc()),
 1124            actualOptions,
 1125            maxSelections.Or(1),
 1126            formFieldName.Or((string?)null));
 127    }
 128
 129    /// <summary>
 130    /// Creates a test <see cref="BonusPrediction"/> with default values.
 131    /// </summary>
 132    /// <param name="selectedOptionIds">Selected option IDs. Defaults to ["opt-1"].</param>
 133    public static BonusPrediction CreateBonusPrediction(
 134        Option<List<string>> selectedOptionIds = default)
 135    {
 1136        return new BonusPrediction(selectedOptionIds.Or(() => ["opt-1"]));
 137    }
 138
 139    /// <summary>
 140    /// Creates a test <see cref="MatchResult"/> with default values.
 141    /// </summary>
 142    /// <param name="competition">Competition name. Defaults to "1.BL".</param>
 143    /// <param name="homeTeam">Home team name. Defaults to "Bayern München".</param>
 144    /// <param name="awayTeam">Away team name. Defaults to "Borussia Dortmund".</param>
 145    /// <param name="homeGoals">Home team goals. Defaults to 2.</param>
 146    /// <param name="awayGoals">Away team goals. Defaults to 1.</param>
 147    /// <param name="outcome">Match outcome. Defaults to Win.</param>
 148    /// <param name="annotation">Optional annotation. Defaults to null.</param>
 149    public static MatchResult CreateMatchResult(
 150        Option<string> competition = default,
 151        Option<string> homeTeam = default,
 152        Option<string> awayTeam = default,
 153        NullableOption<int> homeGoals = default,
 154        NullableOption<int> awayGoals = default,
 155        Option<MatchOutcome> outcome = default,
 156        NullableOption<string> annotation = default)
 157    {
 0158        return new MatchResult(
 0159            competition.Or("1.BL"),
 0160            homeTeam.Or("Bayern München"),
 0161            awayTeam.Or("Borussia Dortmund"),
 0162            homeGoals.Or(2),
 0163            awayGoals.Or(1),
 0164            outcome.Or(MatchOutcome.Win),
 0165            annotation.Or((string?)null));
 166    }
 167
 168    /// <summary>
 169    /// Creates a test <see cref="MatchWithHistory"/> with default values.
 170    /// </summary>
 171    /// <param name="match">The match. Defaults to a new test match.</param>
 172    /// <param name="homeTeamHistory">Home team recent results. Defaults to empty list.</param>
 173    /// <param name="awayTeamHistory">Away team recent results. Defaults to empty list.</param>
 174    public static MatchWithHistory CreateMatchWithHistory(
 175        Option<Match> match = default,
 176        Option<List<MatchResult>> homeTeamHistory = default,
 177        Option<List<MatchResult>> awayTeamHistory = default)
 178    {
 1179        return new MatchWithHistory(
 1180            match.Or(() => CreateMatch()),
 1181            homeTeamHistory.Or(() => []),
 1182            awayTeamHistory.Or(() => []));
 183    }
 184
 185    /// <summary>
 186    /// Creates a test <see cref="DocumentContext"/> with default values.
 187    /// </summary>
 188    /// <param name="name">Document name. Defaults to "test-document".</param>
 189    /// <param name="content">Document content. Defaults to "test content".</param>
 190    public static DocumentContext CreateDocumentContext(
 191        Option<string> name = default,
 192        Option<string> content = default)
 193    {
 0194        return new DocumentContext(
 0195            name.Or("test-document"),
 0196            content.Or("test content"));
 197    }
 198
 199    /// <summary>
 200    /// Creates a test <see cref="TeamStanding"/> with default values.
 201    /// </summary>
 202    /// <param name="position">League position. Defaults to 1.</param>
 203    /// <param name="teamName">Team name. Defaults to "Bayern München".</param>
 204    /// <param name="gamesPlayed">Games played. Defaults to 10.</param>
 205    /// <param name="points">Total points. Defaults to 25.</param>
 206    /// <param name="goalsFor">Goals scored. Defaults to 30.</param>
 207    /// <param name="goalsAgainst">Goals conceded. Defaults to 10.</param>
 208    /// <param name="goalDifference">Goal difference. Defaults to 20.</param>
 209    /// <param name="wins">Wins. Defaults to 8.</param>
 210    /// <param name="draws">Draws. Defaults to 1.</param>
 211    /// <param name="losses">Losses. Defaults to 1.</param>
 212    public static TeamStanding CreateTeamStanding(
 213        Option<int> position = default,
 214        Option<string> teamName = default,
 215        Option<int> gamesPlayed = default,
 216        Option<int> points = default,
 217        Option<int> goalsFor = default,
 218        Option<int> goalsAgainst = default,
 219        Option<int> goalDifference = default,
 220        Option<int> wins = default,
 221        Option<int> draws = default,
 222        Option<int> losses = default)
 223    {
 0224        return new TeamStanding(
 0225            position.Or(1),
 0226            teamName.Or("Bayern München"),
 0227            gamesPlayed.Or(10),
 0228            points.Or(25),
 0229            goalsFor.Or(30),
 0230            goalsAgainst.Or(10),
 0231            goalDifference.Or(20),
 0232            wins.Or(8),
 0233            draws.Or(1),
 0234            losses.Or(1));
 235    }
 236
 237    /// <summary>
 238    /// Creates a test <see cref="HeadToHeadResult"/> with default values.
 239    /// </summary>
 240    /// <param name="league">League name. Defaults to "1.BL 2024/25".</param>
 241    /// <param name="matchday">Matchday description. Defaults to "25. Spieltag".</param>
 242    /// <param name="playedAt">Date played. Defaults to "2025-03-15".</param>
 243    /// <param name="homeTeam">Home team name. Defaults to "Bayern München".</param>
 244    /// <param name="awayTeam">Away team name. Defaults to "Borussia Dortmund".</param>
 245    /// <param name="score">Match score. Defaults to "2:1".</param>
 246    /// <param name="annotation">Optional annotation. Defaults to null.</param>
 247    public static HeadToHeadResult CreateHeadToHeadResult(
 248        Option<string> league = default,
 249        Option<string> matchday = default,
 250        Option<string> playedAt = default,
 251        Option<string> homeTeam = default,
 252        Option<string> awayTeam = default,
 253        Option<string> score = default,
 254        NullableOption<string> annotation = default)
 255    {
 0256        return new HeadToHeadResult(
 0257            league.Or("1.BL 2024/25"),
 0258            matchday.Or("25. Spieltag"),
 0259            playedAt.Or("2025-03-15"),
 0260            homeTeam.Or("Bayern München"),
 0261            awayTeam.Or("Borussia Dortmund"),
 0262            score.Or("2:1"),
 0263            annotation.Or((string?)null));
 264    }
 265
 266    /// <summary>
 267    /// Creates a test <see cref="PredictionMetadata"/> with default values.
 268    /// </summary>
 269    /// <param name="prediction">The prediction. Defaults to a new test prediction.</param>
 270    /// <param name="createdAt">Creation timestamp. Defaults to 2025-01-10 12:00 UTC.</param>
 271    /// <param name="contextDocumentNames">Context document names used. Defaults to empty list.</param>
 272    public static PredictionMetadata CreatePredictionMetadata(
 273        Option<Prediction> prediction = default,
 274        Option<DateTimeOffset> createdAt = default,
 275        Option<List<string>> contextDocumentNames = default)
 276    {
 1277        return new PredictionMetadata(
 1278            prediction.Or(() => CreatePrediction()),
 0279            createdAt.Or(() => new DateTimeOffset(2025, 1, 10, 12, 0, 0, TimeSpan.Zero)),
 0280            contextDocumentNames.Or(() => []));
 281    }
 282}

Methods/Properties

CreateMatch(EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<NodaTime.ZonedDateTime>, EHonda.Optional.Core.Option<int>, EHonda.Optional.Core.Option<bool>)
CreatePrediction(EHonda.Optional.Core.Option<int>, EHonda.Optional.Core.Option<int>, EHonda.Optional.Core.NullableOption<EHonda.KicktippAi.Core.PredictionJustification>)
CreatePredictionJustification(EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<EHonda.KicktippAi.Core.PredictionJustificationContextSources>, EHonda.Optional.Core.Option<System.Collections.Generic.List<string>>)
CreatePredictionJustificationContextSources(EHonda.Optional.Core.Option<System.Collections.Generic.List<EHonda.KicktippAi.Core.PredictionJustificationContextSource>>, EHonda.Optional.Core.Option<System.Collections.Generic.List<EHonda.KicktippAi.Core.PredictionJustificationContextSource>>)
CreatePredictionJustificationContextSource(EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<string>)
CreateBonusQuestion(EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<NodaTime.ZonedDateTime>, EHonda.Optional.Core.Option<System.Collections.Generic.List<EHonda.KicktippAi.Core.BonusQuestionOption>>, EHonda.Optional.Core.Option<int>, EHonda.Optional.Core.NullableOption<string>)
CreateBonusPrediction(EHonda.Optional.Core.Option<System.Collections.Generic.List<string>>)
CreateMatchResult(EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.NullableOption<int>, EHonda.Optional.Core.NullableOption<int>, EHonda.Optional.Core.Option<EHonda.KicktippAi.Core.MatchOutcome>, EHonda.Optional.Core.NullableOption<string>)
CreateMatchWithHistory(EHonda.Optional.Core.Option<EHonda.KicktippAi.Core.Match>, EHonda.Optional.Core.Option<System.Collections.Generic.List<EHonda.KicktippAi.Core.MatchResult>>, EHonda.Optional.Core.Option<System.Collections.Generic.List<EHonda.KicktippAi.Core.MatchResult>>)
CreateDocumentContext(EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<string>)
CreateTeamStanding(EHonda.Optional.Core.Option<int>, EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<int>, EHonda.Optional.Core.Option<int>, EHonda.Optional.Core.Option<int>, EHonda.Optional.Core.Option<int>, EHonda.Optional.Core.Option<int>, EHonda.Optional.Core.Option<int>, EHonda.Optional.Core.Option<int>, EHonda.Optional.Core.Option<int>)
CreateHeadToHeadResult(EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.Option<string>, EHonda.Optional.Core.NullableOption<string>)
CreatePredictionMetadata(EHonda.Optional.Core.Option<EHonda.KicktippAi.Core.Prediction>, EHonda.Optional.Core.Option<System.DateTimeOffset>, EHonda.Optional.Core.Option<System.Collections.Generic.List<string>>)