| | | 1 | | using EHonda.KicktippAi.Core; |
| | | 2 | | using EHonda.Optional.Core; |
| | | 3 | | using NodaTime; |
| | | 4 | | |
| | | 5 | | namespace 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> |
| | | 12 | | public 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 | | { |
| | 1 | 29 | | return new Match( |
| | 1 | 30 | | homeTeam.Or("Bayern München"), |
| | 1 | 31 | | awayTeam.Or("Borussia Dortmund"), |
| | 1 | 32 | | startsAt.Or(() => Instant.FromUtc(2025, 3, 15, 15, 30).InUtc()), |
| | 1 | 33 | | matchday.Or(25), |
| | 1 | 34 | | 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 | | { |
| | 1 | 48 | | return new Prediction( |
| | 1 | 49 | | homeGoals.Or(2), |
| | 1 | 50 | | awayGoals.Or(1), |
| | 1 | 51 | | 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 | | { |
| | 1 | 65 | | return new PredictionJustification( |
| | 1 | 66 | | keyReasoning.Or("Default test reasoning"), |
| | 1 | 67 | | contextSources.Or(() => CreatePredictionJustificationContextSources()), |
| | 1 | 68 | | 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 | | { |
| | 1 | 80 | | return new PredictionJustificationContextSources( |
| | 1 | 81 | | mostValuable.Or(() => []), |
| | 1 | 82 | | 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 | | { |
| | 0 | 94 | | return new PredictionJustificationContextSource( |
| | 0 | 95 | | documentName.Or("test-document"), |
| | 0 | 96 | | 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 | | { |
| | 1 | 114 | | var actualOptions = options.Or(() => |
| | 1 | 115 | | [ |
| | 1 | 116 | | new("opt-1", "Option 1"), |
| | 1 | 117 | | new("opt-2", "Option 2"), |
| | 1 | 118 | | new("opt-3", "Option 3") |
| | 1 | 119 | | ]); |
| | | 120 | | |
| | 1 | 121 | | return new BonusQuestion( |
| | 1 | 122 | | text.Or("Who will win the league?"), |
| | 1 | 123 | | deadline.Or(() => Instant.FromUtc(2025, 5, 15, 18, 0).InUtc()), |
| | 1 | 124 | | actualOptions, |
| | 1 | 125 | | maxSelections.Or(1), |
| | 1 | 126 | | 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 | | { |
| | 1 | 136 | | 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 | | { |
| | 0 | 158 | | return new MatchResult( |
| | 0 | 159 | | competition.Or("1.BL"), |
| | 0 | 160 | | homeTeam.Or("Bayern München"), |
| | 0 | 161 | | awayTeam.Or("Borussia Dortmund"), |
| | 0 | 162 | | homeGoals.Or(2), |
| | 0 | 163 | | awayGoals.Or(1), |
| | 0 | 164 | | outcome.Or(MatchOutcome.Win), |
| | 0 | 165 | | 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 | | { |
| | 1 | 179 | | return new MatchWithHistory( |
| | 1 | 180 | | match.Or(() => CreateMatch()), |
| | 1 | 181 | | homeTeamHistory.Or(() => []), |
| | 1 | 182 | | 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 | | { |
| | 0 | 194 | | return new DocumentContext( |
| | 0 | 195 | | name.Or("test-document"), |
| | 0 | 196 | | 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 | | { |
| | 0 | 224 | | return new TeamStanding( |
| | 0 | 225 | | position.Or(1), |
| | 0 | 226 | | teamName.Or("Bayern München"), |
| | 0 | 227 | | gamesPlayed.Or(10), |
| | 0 | 228 | | points.Or(25), |
| | 0 | 229 | | goalsFor.Or(30), |
| | 0 | 230 | | goalsAgainst.Or(10), |
| | 0 | 231 | | goalDifference.Or(20), |
| | 0 | 232 | | wins.Or(8), |
| | 0 | 233 | | draws.Or(1), |
| | 0 | 234 | | 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 | | { |
| | 0 | 256 | | return new HeadToHeadResult( |
| | 0 | 257 | | league.Or("1.BL 2024/25"), |
| | 0 | 258 | | matchday.Or("25. Spieltag"), |
| | 0 | 259 | | playedAt.Or("2025-03-15"), |
| | 0 | 260 | | homeTeam.Or("Bayern München"), |
| | 0 | 261 | | awayTeam.Or("Borussia Dortmund"), |
| | 0 | 262 | | score.Or("2:1"), |
| | 0 | 263 | | 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 | | { |
| | 1 | 277 | | return new PredictionMetadata( |
| | 1 | 278 | | prediction.Or(() => CreatePrediction()), |
| | 0 | 279 | | createdAt.Or(() => new DateTimeOffset(2025, 1, 10, 12, 0, 0, TimeSpan.Zero)), |
| | 0 | 280 | | contextDocumentNames.Or(() => [])); |
| | | 281 | | } |
| | | 282 | | } |