-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor scheduling of fixtures in namespace TournamentManager.Plan (#…
…131) * Initial commit * Changing internal components in TournamentManager * Implement new round-robin classes * Seprate MatchCreater and MatchScheduler * Continue refactoring * IRoundRobinSystem type parameters are IEquatable struct * Add logging to ExcludeMatchDates * Add RefereeAssigner classes * MatchCreator type parameters are IEquatable struct * ParticipantCombination type parameters are IEquatable struct * Refactor MatchCreator and MatchScheduler * MatchScheduler will sets the planned date / time to null, if no available date within a target period can be found * Add more unit tests * Add RefereeType to new TournamentContext.RefereeRuleSet * Improve performance for creating fixtures with MatchScheduler * Planned matches of a tournament are cached for faster checks of available dates * Extend debug logging * Update tenant settings for development to include RefereeRuleSet Update MatchScheduler * Add MatchEntityListExtensions * Add ability to find next and previous matches in the list * Add unit tests * MatchScheduler: Make the time periods of turns consecutive without gaps Adjust time periods for turns in the round so that the start date of the next turn is the end date of the previous turn plus 1 day. * Replace AppDb references with IAppDb * Add 2nd trial if MatchScheduler can't find available match dates * Add unit tests for AvailableMatchDates * Change MatchRepository.GetMatches(...) to async * Change TournamentCreator and MatchScheduler to use async database queries * Add OnBeforeSave and OnAfterSave events to MatchScheduler * Add unit tests for MatchScheduler (91% coverage)
- Loading branch information
Showing
77 changed files
with
3,248 additions
and
1,096 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
TournamentManager/TournamentManager.Tests/ExtensionMethods/MatchEntityListExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using NUnit.Framework; | ||
using FluentAssertions; | ||
using TournamentManager.DAL.EntityClasses; | ||
using TournamentManager.ExtensionMethods; | ||
|
||
namespace TournamentManager.Tests.ExtensionMethods; | ||
|
||
[TestFixture] | ||
public class MatchEntityListExtensionTests | ||
{ | ||
private readonly List<MatchEntity> _matches = new() | ||
{ | ||
new MatchEntity {Id = 1, HomeTeamId = 1, GuestTeamId = 2, PlannedStart = DateTime.UtcNow.AddDays(-1), PlannedEnd = DateTime.UtcNow.AddDays(-1).AddHours(2), VenueId = 1}, | ||
new MatchEntity {Id = 2, HomeTeamId = 1, GuestTeamId = 3, PlannedStart = DateTime.UtcNow.AddDays(-1), PlannedEnd = DateTime.UtcNow.AddDays(-1).AddHours(2), VenueId = 1}, | ||
new MatchEntity {Id = 3, HomeTeamId = 2, GuestTeamId = 3, PlannedStart = DateTime.UtcNow.AddDays(-1), PlannedEnd = DateTime.UtcNow.AddDays(-1).AddHours(2), VenueId = 1}, | ||
new MatchEntity {Id = 4, HomeTeamId = 1, GuestTeamId = 4, PlannedStart = DateTime.UtcNow.AddDays(-1), PlannedEnd = DateTime.UtcNow.AddDays(-1).AddHours(2), VenueId = 1}, | ||
new MatchEntity {Id = 5, HomeTeamId = 4, GuestTeamId = 2, PlannedStart = DateTime.UtcNow.AddDays(-1), PlannedEnd = DateTime.UtcNow.AddDays(-1).AddHours(2), VenueId = 1}, | ||
new MatchEntity {Id = 6, HomeTeamId = 3, GuestTeamId = 4, PlannedStart = DateTime.UtcNow.AddDays(-1), PlannedEnd = DateTime.UtcNow.AddDays(-1).AddHours(2), VenueId = 1}, | ||
new MatchEntity {Id = 7, HomeTeamId = 1, GuestTeamId = 5, PlannedStart = DateTime.UtcNow.AddDays(-1), PlannedEnd = DateTime.UtcNow.AddDays(-1).AddHours(2), VenueId = 1}, | ||
new MatchEntity {Id = 8, HomeTeamId = 2, GuestTeamId = 5, PlannedStart = DateTime.UtcNow.AddDays(-1), PlannedEnd = DateTime.UtcNow.AddDays(-1).AddHours(2), VenueId = 1}, | ||
new MatchEntity {Id = 9, HomeTeamId = 3, GuestTeamId = 5, PlannedStart = DateTime.UtcNow.AddDays(-1), PlannedEnd = DateTime.UtcNow.AddDays(-1).AddHours(2), VenueId = 1}, | ||
new MatchEntity {Id = 10, HomeTeamId = 4, GuestTeamId = 5, PlannedStart = DateTime.UtcNow.AddDays(-1), PlannedEnd = DateTime.UtcNow.AddDays(-1).AddHours(2), VenueId = 1}, | ||
new MatchEntity {Id = 11, HomeTeamId = 10, GuestTeamId = 11, PlannedStart = null, PlannedEnd = null, VenueId = null}, | ||
new MatchEntity {Id = 12, HomeTeamId = 12, GuestTeamId = 10, PlannedStart = null, PlannedEnd = DateTime.UtcNow, VenueId = null}, | ||
new MatchEntity {Id = 13, HomeTeamId = 11, GuestTeamId = 13, PlannedStart = DateTime.UtcNow, PlannedEnd = null, VenueId = null} | ||
}; | ||
|
||
[TestCase(1, -1, 0, false, 0)] | ||
[TestCase(1, -1, 5, false, 3)] | ||
[TestCase(1, 2, 5, false, 5)] | ||
[TestCase(10, 13, 12, false, 0)] | ||
[TestCase(10, 13, 12, true, 2)] | ||
public void Previous_Matches_Relative_To_Index_Should_Be_Found(long team1, long team2, int startIndex, bool includeUndefined, int expected) | ||
{ | ||
var teamIds = new[] {team1, team2}; | ||
var matches = _matches.GetPreviousMatches(startIndex, teamIds, includeUndefined).ToList(); | ||
|
||
Assert.That(matches.Count, Is.EqualTo(expected)); | ||
|
||
} | ||
|
||
[TestCase(-1)] | ||
[TestCase(13)] | ||
public void Invalid_StartIndex_For_Previous_Should_Throw(int startIndex) | ||
{ | ||
var teamIds = new long[] { 1 }; | ||
|
||
Assert.That(() => _matches.GetPreviousMatches(startIndex, teamIds, true).ToList(), Throws.TypeOf<ArgumentOutOfRangeException>()); | ||
} | ||
|
||
[TestCase(1, -1, 12, false, 0)] | ||
[TestCase(1, -1, 0, false, 3)] | ||
[TestCase(1, 2, 1, false, 5)] | ||
[TestCase(10, 13, 0, false, 0)] | ||
[TestCase(10, 13, 0, true, 3)] | ||
public void Next_Matches_Relative_To_Index_Should_Be_Found(long team1, long team2, int startIndex, bool includeUndefined, int expected) | ||
{ | ||
var teamIds = new[] { team1, team2 }; | ||
var matches = _matches.GetNextMatches(startIndex, teamIds, includeUndefined).ToList(); | ||
|
||
Assert.That(matches.Count, Is.EqualTo(expected)); | ||
} | ||
|
||
[TestCase(-1)] | ||
[TestCase(13)] | ||
public void Invalid_StartIndex_For_Next_Should_Throw(int startIndex) | ||
{ | ||
var teamIds = new long[] { 1 }; | ||
|
||
Assert.That(() => _matches.GetNextMatches(startIndex, teamIds, true).ToList(), Throws.TypeOf<ArgumentOutOfRangeException>()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.