public void TournamentAggregate_ProduceResult_ResultIsProduced()
        {
            TournamentAggregate tournamentAggregate = TournamentTestData.GetCompletedTournamentAggregateWithCSSCalculatedAggregate(20, 15, 23, 16, 0, 5);

            tournamentAggregate.ProduceResult();

            tournamentAggregate.HasResultBeenProduced.ShouldBeTrue();

            List <PlayerScoreRecordDataTransferObject> scores = tournamentAggregate.GetScores();

            scores.Any(s => s.Last9HolesScore == 0).ShouldBeFalse();
            scores.Any(s => s.Last6HolesScore == 0).ShouldBeFalse();
            scores.Any(s => s.Last3HolesScore == 0).ShouldBeFalse();
            scores.Any(s => s.TournamentDivision == 0).ShouldBeFalse();
            scores.Any(s => s.Position == 0).ShouldBeFalse();
            scores.Any(s => s.MeasuredCourseId == Guid.Empty).ShouldBeFalse();
            scores.Any(s => s.PlayerId == Guid.Empty).ShouldBeFalse();
            scores.Any(s => s.NetScore == 0).ShouldBeFalse();
            scores.Any(s => s.GrossScore == 0).ShouldBeFalse();
            scores.Any(s => s.PlayingHandicap < 0).ShouldBeFalse();
            scores.Any(s => s.PlayingHandicap > 36).ShouldBeFalse();
            scores.Any(s => s.TournamentId == Guid.Empty).ShouldBeFalse();
            scores.Any(s => s.ScoreDate == DateTime.MinValue).ShouldBeFalse();
            scores.Any(s => s.GolfClubId == Guid.Empty).ShouldBeFalse();
            scores.Any(s => s.HandicapCategory == 0).ShouldBeFalse();
            scores.Any(s => s.HoleScores.Count() != 18).ShouldBeFalse();
            scores.Any(s => s.CSS == 0).ShouldBeFalse();
        }
        public void TournamentAggregate_CalculateCSS_CSSAlreadyCalculated_ErrorThrown()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCompletedTournamentAggregate(1, 2, 7, 20, 5, 5);

            aggregate.CalculateCSS();

            Should.Throw <InvalidOperationException>(() => { aggregate.CalculateCSS(); });
        }
        public void TournamentAggregate_CompleteTournament_InvalidData_ErrorThrown(Boolean validCompleteDate)
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentWithScoresRecordedAggregate();

            DateTime completeDateTime = validCompleteDate ? TournamentTestData.CompletedDateTime : DateTime.MinValue;

            Should.Throw <ArgumentNullException>(() => { aggregate.CompleteTournament(completeDateTime); });
        }
        public void TournamentAggregate_GetScores_ScoresReturned()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentWithScoresRecordedAggregate();

            List <PlayerScoreRecordDataTransferObject> scores = aggregate.GetScores();

            scores.ShouldNotBeNull();
            scores.Count.ShouldBe(1);
        }
        public void TournamentAggregate_CompleteTournament_TournamentComplete()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentWithScoresRecordedAggregate();

            aggregate.CompleteTournament(TournamentTestData.CompletedDateTime);

            aggregate.HasBeenCompleted.ShouldBeTrue();
            aggregate.CompletedDateTime.ShouldBe(TournamentTestData.CompletedDateTime);
        }
        public void TournamentAggregate_CancelTournament_InvalidData_ErrorThrown(Boolean validCancellationDate,
                                                                                 String cancellationReason)
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentWithScoresRecordedAggregate();

            DateTime cancellationDateTime = validCancellationDate ? TournamentTestData.CancelledDateTime : DateTime.MinValue;

            Should.Throw <ArgumentNullException>(() => { aggregate.CancelTournament(cancellationDateTime, cancellationReason); });
        }
        public void TournamentAggregate_CancelTournament_TournamentComplete()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentWithScoresRecordedAggregate();

            aggregate.CancelTournament(TournamentTestData.CancelledDateTime, TournamentTestData.CancellationReason);

            aggregate.HasBeenCancelled.ShouldBeTrue();
            aggregate.CancelledDateTime.ShouldBe(TournamentTestData.CancelledDateTime);
            aggregate.CancelledReason.ShouldBe(TournamentTestData.CancellationReason);
        }
        public void TournamentAggregate_RecordPlayerScore_TournamentNotCreated_ErrorThrown()
        {
            TournamentAggregate aggregate = TournamentTestData.GetEmptyTournamentAggregate();

            Should.Throw <InvalidOperationException>(() =>
            {
                aggregate.RecordPlayerScore(TournamentTestData.PlayerId,
                                            TournamentTestData.PlayingHandicap,
                                            TournamentTestData.HoleScores);
            });
        }
        public void TournamentAggregate_RecordPlayerScore_InvalidData_NotAllHoleScores_ErrorThrown()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentAggregateWithPlayerSignedUp();

            Should.Throw <InvalidDataException>(() =>
            {
                aggregate.RecordPlayerScore(TournamentTestData.PlayerId,
                                            TournamentTestData.PlayingHandicap,
                                            TournamentTestData.HoleScoresNotAllPresent);
            });
        }
        public void TournamentAggregate_RecordPlayerScore_InvalidData_NegativeHoleScores_ErrorThrown(Int32 holeNumber)
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentAggregateWithPlayerSignedUp();

            Should.Throw <InvalidDataException>(() =>
            {
                aggregate.RecordPlayerScore(TournamentTestData.PlayerId,
                                            TournamentTestData.PlayingHandicap,
                                            TournamentTestData.HoleScoresNegativeScore(holeNumber));
            });
        }
        public void TournamentAggregate_RecordPlayerScore_InvalidData_ErrorThrown(Boolean validPlayerId,
                                                                                  Int32 playingHandicap,
                                                                                  Boolean validHoleScores,
                                                                                  Type exceptionType)
        {
            TournamentAggregate aggregate = TournamentTestData.GetEmptyTournamentAggregate();

            Guid playerId = validPlayerId ? TournamentTestData.PlayerId : Guid.Empty;
            Dictionary <Int32, Int32> holeScores = validHoleScores ? TournamentTestData.HoleScores : null;

            Should.Throw(() => { aggregate.RecordPlayerScore(playerId, playingHandicap, holeScores); }, exceptionType);
        }
        public void TournamentAggregate_CreateTournament_TournamentAlreadyCreated_ErrorThrown()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentAggregate();

            Should.Throw <InvalidOperationException>(() =>
            {
                aggregate.CreateTournament(TournamentTestData.TournamentDate,
                                           TournamentTestData.GolfClubId,
                                           TournamentTestData.MeasuredCourseId,
                                           TournamentTestData.MeasuredCourseSSS,
                                           TournamentTestData.Name,
                                           TournamentTestData.PlayerCategoryEnum,
                                           TournamentTestData.TournamentFormatEnum);
            });
        }
        public void TournamentAggregate_CalculateCSS_CSSCalculated(Int32 category1Scores,
                                                                   Int32 category2Scores,
                                                                   Int32 category3Scores,
                                                                   Int32 category4Scores,
                                                                   Int32 category5Scores,
                                                                   Int32 bufferorbetter,
                                                                   Int32 expectedAdjustment,
                                                                   Int32 expectedCSS)
        {
            TournamentAggregate aggregate =
                TournamentTestData.GetCompletedTournamentAggregate(category1Scores, category2Scores, category3Scores, category4Scores, category5Scores, bufferorbetter);

            aggregate.CalculateCSS();

            aggregate.Adjustment.ShouldBe(expectedAdjustment);
            aggregate.CSS.ShouldBe(expectedCSS);
            aggregate.GetScores().All(s => s.IsPublished).ShouldBeTrue();
        }
        public void TournamentAggregate_CreateTournament_InvalidData_ErrorThrown(Boolean validTournamentDate,
                                                                                 Boolean validGolfClubId,
                                                                                 Boolean validMeasuredCourseId,
                                                                                 Int32 measuredCourseSSS,
                                                                                 String name,
                                                                                 PlayerCategory memberCategory,
                                                                                 TournamentFormat tournamentFormat,
                                                                                 Type exceptionType)
        {
            TournamentAggregate aggregate = TournamentTestData.GetEmptyTournamentAggregate();

            DateTime tournamentDate   = validTournamentDate ? TournamentTestData.TournamentDate : DateTime.MinValue;
            Guid     golfClubId       = validGolfClubId ? TournamentTestData.GolfClubId : Guid.Empty;
            Guid     measuredCourseId = validMeasuredCourseId ? TournamentTestData.MeasuredCourseId : Guid.Empty;

            Should.Throw(() => { aggregate.CreateTournament(tournamentDate, golfClubId, measuredCourseId, measuredCourseSSS, name, memberCategory, tournamentFormat); },
                         exceptionType);
        }
コード例 #15
0
        public void TournamentCommandHandler_HandleCommand_CompleteTournamentCommand_WithScores_CommandHandled()
        {
            Mock <IAggregateRepository <GolfClubAggregate> > golfClubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >();

            Mock <IAggregateRepository <TournamentAggregate> > tournamentRepository = new Mock <IAggregateRepository <TournamentAggregate> >();

            tournamentRepository.Setup(t => t.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(TournamentTestData.GetCreatedTournamentWithScoresRecordedAggregate);

            Mock <ITournamentApplicationService> tournamentApplicationService = new Mock <ITournamentApplicationService>();

            TournamentCommandHandler handler = new TournamentCommandHandler(golfClubRepository.Object,
                                                                            tournamentRepository.Object,
                                                                            tournamentApplicationService.Object);

            CompleteTournamentCommand command = TournamentTestData.GetCompleteTournamentCommand();

            Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); });
        }
        public static TournamentAggregate GetCompletedTournamentAggregate(Int32 category1Scores = 1, Int32 category2Scores  = 2, Int32 category3Scores = 7,
                                                                          Int32 category4Scores = 20, Int32 category5Scores = 5, Int32 bufferorbetter  = 5)
        {
            TournamentAggregate aggregate = TournamentAggregate.Create(TournamentTestData.AggregateId);

            aggregate.CreateTournament(TournamentTestData.TournamentDate, TournamentTestData.GolfClubId, TournamentTestData.MeasuredCourseId, TournamentTestData.MeasuredCourseSSS, TournamentTestData.Name, TournamentTestData.PlayerCategoryEnum, TournamentTestData.TournamentFormatEnum);

            List <GeneratedPlayerScore> scoresToRecord = TournamentTestData.GenerateScores(category1Scores, category2Scores, category3Scores, category4Scores, category5Scores, bufferorbetter);

            foreach (GeneratedPlayerScore playerScoreForTest in scoresToRecord)
            {
                aggregate.SignUpForTournament(playerScoreForTest.PlayerId);
                aggregate.RecordPlayerScore(playerScoreForTest.PlayerId, playerScoreForTest.Handicap, playerScoreForTest.HoleScores);
            }

            aggregate.CompleteTournament(TournamentTestData.CompletedDateTime);

            return(aggregate);
        }
        public void TournamentAggregate_CreateTournament_TournamentCreated()
        {
            TournamentAggregate aggregate = TournamentTestData.GetEmptyTournamentAggregate();

            aggregate.CreateTournament(TournamentTestData.TournamentDate,
                                       TournamentTestData.GolfClubId,
                                       TournamentTestData.MeasuredCourseId,
                                       TournamentTestData.MeasuredCourseSSS,
                                       TournamentTestData.Name,
                                       TournamentTestData.PlayerCategoryEnum,
                                       TournamentTestData.TournamentFormatEnum);

            aggregate.TournamentDate.ShouldBe(TournamentTestData.TournamentDate);
            aggregate.GolfClubId.ShouldBe(TournamentTestData.GolfClubId);
            aggregate.MeasuredCourseId.ShouldBe(TournamentTestData.MeasuredCourseId);
            aggregate.MeasuredCourseSSS.ShouldBe(TournamentTestData.MeasuredCourseSSS);
            aggregate.Name.ShouldBe(TournamentTestData.Name);
            aggregate.PlayerCategory.ShouldBe(TournamentTestData.PlayerCategoryEnum);
            aggregate.Format.ShouldBe(TournamentTestData.TournamentFormatEnum);
            aggregate.HasBeenCreated.ShouldBeTrue();
        }
コード例 #18
0
        public void TournamentCommandHandler_HandleCommand_CreateTournamentCommand_ClubNotFound_ErrorThrown()
        {
            // test added as part of bug #29 fixes
            Mock <IAggregateRepository <GolfClubAggregate> > golfClubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >();

            golfClubRepository.Setup(c => c.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(GolfClubTestData.GetEmptyGolfClubAggregate);

            Mock <IAggregateRepository <TournamentAggregate> > tournamentRepository = new Mock <IAggregateRepository <TournamentAggregate> >();

            tournamentRepository.Setup(t => t.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(TournamentTestData.GetEmptyTournamentAggregate);

            Mock <ITournamentApplicationService> tournamentApplicationService = new Mock <ITournamentApplicationService>();

            TournamentCommandHandler handler = new TournamentCommandHandler(golfClubRepository.Object,
                                                                            tournamentRepository.Object,
                                                                            tournamentApplicationService.Object);

            CreateTournamentCommand command = TournamentTestData.GetCreateTournamentCommand();

            Should.Throw <NotFoundException>(async() => { await handler.Handle(command, CancellationToken.None); });
        }
        public void TournamentAggregate_CompleteTournament_TournamentAlreadyCompleted_ErrorThrown()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCompletedTournamentAggregate(1, 2, 7, 20, 5, 5);

            Should.Throw <InvalidOperationException>(() => { aggregate.CompleteTournament(TournamentTestData.CompletedDateTime); });
        }
        public void TournamentAggregate_CancelTournament_TournamentAlreadyCancelled_ErrorThrown()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCancelledTournamentAggregate();

            Should.Throw <InvalidOperationException>(() => { aggregate.CancelTournament(TournamentTestData.CancelledDateTime, TournamentTestData.CancellationReason); });
        }
        public void TournamentAggregate_RecordPlayerScore_PlayerScoreRecorded()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentAggregateWithPlayerSignedUp();

            Should.NotThrow(() => { aggregate.RecordPlayerScore(TournamentTestData.PlayerId, TournamentTestData.PlayingHandicap, TournamentTestData.HoleScores); });
        }
        public void TournamentAggregate_CompleteTournament_TournamentNotCreated_ErrorThrown()
        {
            TournamentAggregate aggregate = TournamentTestData.GetEmptyTournamentAggregate();

            Should.Throw <InvalidOperationException>(() => { aggregate.CompleteTournament(TournamentTestData.CompletedDateTime); });
        }
        public void TournamentAggregate_CalculateCSS_TournamentNotCompleted_ErrorThrown()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentWithScoresRecordedAggregate();

            Should.Throw <InvalidOperationException>(() => { aggregate.CalculateCSS(); });
        }
        public void TournamentAggregate_CalculateCSS_TournamentNotCreated_ErrorThrown()
        {
            TournamentAggregate aggregate = TournamentTestData.GetEmptyTournamentAggregate();

            Should.Throw <InvalidOperationException>(() => { aggregate.CalculateCSS(); });
        }
        public void TournamentAggregate_ProduceResult_UnsupportedFormat_ErrorThrown()
        {
            TournamentAggregate tournamentAggregate = TournamentTestData.GetCompletedTournamentAggregateWithCSSCalculatedAggregate(20, 15, 23, 16, 0, 5, TournamentFormat.Stableford);

            Should.Throw <NotSupportedException>(() => tournamentAggregate.ProduceResult());
        }
        public void TournamentAggregate_ProduceResult_CSSNotCalculated_ErrorThrown()
        {
            TournamentAggregate tournamentAggregate = TournamentTestData.GetCompletedTournamentAggregate(20, 15, 23, 16, 0, 5);

            Should.Throw <InvalidOperationException>(() => tournamentAggregate.ProduceResult());
        }
        public void TournamentAggregate_SignUpForTournament_PlayerAlreadySignedUp_ErrorThrown()
        {
            TournamentAggregate tournament = TournamentTestData.GetCreatedTournamentAggregateWithPlayerSignedUp();

            Should.Throw <InvalidOperationException>(() => { tournament.SignUpForTournament(TournamentTestData.PlayerId); });
        }
        public void TournamentAggregate_SignUpForTournament_TournamentNotCreated_ErrorThrown()
        {
            TournamentAggregate tournament = TournamentTestData.GetEmptyTournamentAggregate();

            Should.Throw <InvalidOperationException>(() => { tournament.SignUpForTournament(TournamentTestData.PlayerId); });
        }
        public void TournamentAggregate_SignUpForTournament_PlayerSignedUp()
        {
            TournamentAggregate tournament = TournamentTestData.GetCreatedTournamentAggregate();

            tournament.SignUpForTournament(TournamentTestData.PlayerId);
        }