public async Task Ball_Points_Are_Not_Negative(int homePoints, int guestPoints, bool expected) { var set = new SetEntity { HomeBallPoints = homePoints, GuestBallPoints = guestPoints }; var sv = new SingleSetValidator(set, (new TenantContext(), new SetRuleEntity(1))); var factResult = await sv.CheckAsync(SingleSetValidator.FactId.BallPointsNotNegative, CancellationToken.None); Assert.Multiple(() => { Assert.AreEqual(expected, factResult.Success); Assert.IsNotNull(factResult.Message); Assert.IsNull(factResult.Exception); }); }
public async Task Disallow_Tie_In_Regular_Sets(int homePoints, int guestPoints, bool expected) { var set = new SetEntity { HomeBallPoints = homePoints, GuestBallPoints = guestPoints, IsTieBreak = false }; var sv = new SingleSetValidator(set, (new TenantContext(), new SetRuleEntity(1) { PointsDiffToWinRegular = 2, PointsDiffToWinTiebreak = 2 })); var factResult = await sv.CheckAsync(SingleSetValidator.FactId.TieIsAllowed, CancellationToken.None); Assert.Multiple(() => { Assert.AreEqual(expected, factResult.Success); Assert.IsNotNull(factResult.Message); Assert.IsNull(factResult.Exception); }); }
[TestCase(15, 14, true, true)] // only points to win are checked here public async Task Num_Of_BallPoints_To_Win_Is_Reached(int homePoints, int guestPoints, bool isTieBreak, bool expected) { var set = new SetEntity { HomeBallPoints = homePoints, GuestBallPoints = guestPoints, IsTieBreak = isTieBreak }; var sv = new SingleSetValidator(set, (new TenantContext(), new SetRuleEntity(1) { NumOfPointsToWinRegular = 25, NumOfPointsToWinTiebreak = 15 })); var factResult = await sv.CheckAsync(SingleSetValidator.FactId.NumOfPointsToWinReached, CancellationToken.None); Assert.Multiple(() => { Assert.AreEqual(expected, factResult.Success); Assert.IsNotNull(factResult.Message); Assert.IsNull(factResult.Exception); }); }
public async Task TieBreak_Win_Reached_With_TwoOrMore_Points_Ahead(int homePoints, int guestPoints, bool isTieBreak, bool expected) { // regular sets are ignored var set = new SetEntity { HomeBallPoints = homePoints, GuestBallPoints = guestPoints, IsTieBreak = isTieBreak }; var sv = new SingleSetValidator(set, (new TenantContext(), new SetRuleEntity(1) { NumOfPointsToWinRegular = 25, PointsDiffToWinRegular = 2, NumOfPointsToWinTiebreak = 15, PointsDiffToWinTiebreak = 2 })); var factResult = await sv.CheckAsync(SingleSetValidator.FactId.TieBreakWinReachedWithTwoPlusPointsAhead, CancellationToken.None); Assert.Multiple(() => { Assert.AreEqual(expected, factResult.Success); Assert.IsNotNull(factResult.Message); Assert.IsNull(factResult.Exception); }); }
public async Task Regular_Win_Reached_With_One_Point_Ahead(int homePoints, int guestPoints, bool isTieBreak, bool expected) { // tie-break is ignored var set = new SetEntity { HomeBallPoints = homePoints, GuestBallPoints = guestPoints, IsTieBreak = isTieBreak }; var sv = new SingleSetValidator(set, (new OrganizationContext(), new SetRuleEntity(1) { NumOfPointsToWinRegular = 25, PointsDiffToWinRegular = 1, NumOfPointsToWinTiebreak = 15, PointsDiffToWinTiebreak = 1 })); var factResult = await sv.CheckAsync(SingleSetValidator.FactId.RegularWinReachedWithOnePointAhead, CancellationToken.None); Assert.Multiple(() => { Assert.AreEqual(expected, factResult.Success); Assert.IsNotNull(factResult.Message); Assert.IsNull(factResult.Exception); }); }
public void Check_FieldName_Of_Facts() { var fv = new SingleSetValidator(new SetEntity(), (new TenantContext(), new SetRuleEntity())); foreach (var fact in fv.Facts) { switch (fact.Id) { case SingleSetValidator.FactId.BallPointsNotNegative: case SingleSetValidator.FactId.TieIsAllowed: case SingleSetValidator.FactId.NumOfPointsToWinReached: case SingleSetValidator.FactId.RegularWinReachedWithOnePointAhead: case SingleSetValidator.FactId.TieBreakWinReachedWithOnePointAhead: case SingleSetValidator.FactId.RegularWinReachedWithTwoPlusPointsAhead: case SingleSetValidator.FactId.TieBreakWinReachedWithTwoPlusPointsAhead: Assert.IsTrue(fact.FieldNames.Count() == 2); break; } } }