public void PlayerAggregate_Register_NoMiddleName_PlayerRegistered(String middleName)
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetEmptyPlayerAggregate();

            Decimal exactHandicap    = PlayerTestData.ExactHandicapCat1;
            Int32   playingHandicap  = PlayerTestData.PlayingHandicapCat1;
            Int32   handicapCategory = PlayerTestData.HandicapCategoryCat1;


            playerAggregate.Register(PlayerTestData.FirstName,
                                     middleName,
                                     PlayerTestData.LastName,
                                     PlayerTestData.Gender,
                                     PlayerTestData.DateOfBirth,
                                     exactHandicap,
                                     PlayerTestData.EmailAddress);

            playerAggregate.FirstName.ShouldBe(PlayerTestData.FirstName);
            playerAggregate.MiddleName.ShouldBe(middleName);
            playerAggregate.LastName.ShouldBe(PlayerTestData.LastName);
            playerAggregate.Gender.ShouldBe(PlayerTestData.Gender);
            playerAggregate.DateOfBirth.ShouldBe(PlayerTestData.DateOfBirth);
            playerAggregate.ExactHandicap.ShouldBe(exactHandicap);
            playerAggregate.EmailAddress.ShouldBe(PlayerTestData.EmailAddress);
            playerAggregate.PlayingHandicap.ShouldBe(playingHandicap);
            playerAggregate.HandicapCategory.ShouldBe(handicapCategory);
            playerAggregate.FullName.ShouldBe(PlayerTestData.FullNameEmptyMiddleName);
        }
        public void PlayerAggregate_Register_PlayerRegistered(Int32 category)
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetEmptyPlayerAggregate();

            Decimal exactHandicap    = 0;
            Int32   playingHandicap  = 0;
            Int32   handicapCategory = 0;

            switch (category)
            {
            case 1:
                exactHandicap    = PlayerTestData.ExactHandicapCat1;
                playingHandicap  = PlayerTestData.PlayingHandicapCat1;
                handicapCategory = PlayerTestData.HandicapCategoryCat1;
                break;

            case 2:
                exactHandicap    = PlayerTestData.ExactHandicapCat2;
                playingHandicap  = PlayerTestData.PlayingHandicapCat2;
                handicapCategory = PlayerTestData.HandicapCategoryCat2;
                break;

            case 3:
                exactHandicap    = PlayerTestData.ExactHandicapCat3;
                playingHandicap  = PlayerTestData.PlayingHandicapCat3;
                handicapCategory = PlayerTestData.HandicapCategoryCat3;
                break;

            case 4:
                exactHandicap    = PlayerTestData.ExactHandicapCat4;
                playingHandicap  = PlayerTestData.PlayingHandicapCat4;
                handicapCategory = PlayerTestData.HandicapCategoryCat4;
                break;

            case 5:
                exactHandicap    = PlayerTestData.ExactHandicapCat5;
                playingHandicap  = PlayerTestData.PlayingHandicapCat5;
                handicapCategory = PlayerTestData.HandicapCategoryCat5;
                break;
            }

            playerAggregate.Register(PlayerTestData.FirstName,
                                     PlayerTestData.MiddleName,
                                     PlayerTestData.LastName,
                                     PlayerTestData.Gender,
                                     PlayerTestData.DateOfBirth,
                                     exactHandicap,
                                     PlayerTestData.EmailAddress);

            playerAggregate.FirstName.ShouldBe(PlayerTestData.FirstName);
            playerAggregate.MiddleName.ShouldBe(PlayerTestData.MiddleName);
            playerAggregate.LastName.ShouldBe(PlayerTestData.LastName);
            playerAggregate.Gender.ShouldBe(PlayerTestData.Gender);
            playerAggregate.DateOfBirth.ShouldBe(PlayerTestData.DateOfBirth);
            playerAggregate.ExactHandicap.ShouldBe(exactHandicap);
            playerAggregate.EmailAddress.ShouldBe(PlayerTestData.EmailAddress);
            playerAggregate.PlayingHandicap.ShouldBe(playingHandicap);
            playerAggregate.HandicapCategory.ShouldBe(handicapCategory);
            playerAggregate.FullName.ShouldBe(PlayerTestData.FullName);
        }
        public void PlayerAggregate_CreateSecurityUser_SecurityUserCreated()
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetRegisteredPlayerAggregate();

            playerAggregate.CreateSecurityUser(PlayerTestData.SecurityUserId);

            playerAggregate.SecurityUserId.ShouldBe(PlayerTestData.SecurityUserId);
            playerAggregate.HasSecurityUserBeenCreated.ShouldBeTrue();
        }
        public void PlayerAggregate_AdjustHandicap_PlayerNotRegistered_ErrorThrown()
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetEmptyPlayerAggregate();

            Should.Throw <InvalidOperationException>(() => playerAggregate.AdjustHandicap(PlayerTestData.HandicapAdjustment,
                                                                                          PlayerTestData.TournamentId,
                                                                                          PlayerTestData.GolfClubId,
                                                                                          PlayerTestData.MeasuredCourseId,
                                                                                          PlayerTestData.ScoreDate));
        }
        public void PlayerAggregate_AdjustHandicap_HandicapIncrease_HandicapAdjusted()
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetRegisteredPlayerAggregate();

            playerAggregate.AdjustHandicap(PlayerTestData.HandicapAdjustmentIncrease, PlayerTestData.TournamentId, PlayerTestData.GolfClubId, PlayerTestData.MeasuredCourseId,
                                           PlayerTestData.ScoreDate);

            playerAggregate.ExactHandicap.ShouldBe(PlayerTestData.NewExactHandicapIncreased);
            playerAggregate.PlayingHandicap.ShouldBe(PlayerTestData.NewPlayingHandicapIncreased);
        }
        public void PlayerAggregate_AdjustHandicap_HandicapAdjustmentIsZero_HandicapNotAdjusted()
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetRegisteredPlayerAggregate();

            playerAggregate.AdjustHandicap(PlayerTestData.HandicapAdjustmentNoChange, PlayerTestData.TournamentId, PlayerTestData.GolfClubId, PlayerTestData.MeasuredCourseId,
                                           PlayerTestData.ScoreDate);

            playerAggregate.ExactHandicap.ShouldBe(PlayerTestData.ExactHandicap);
            playerAggregate.PlayingHandicap.ShouldBe(PlayerTestData.PlayingHandicap);
        }
        public void PlayerAggregate_Register_PlayerAlreadyRegistered_ErrorThrown()
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetRegisteredPlayerAggregate();

            Should.Throw <InvalidOperationException>(() =>
            {
                playerAggregate.Register(PlayerTestData.FirstName,
                                         PlayerTestData.MiddleName,
                                         PlayerTestData.LastName,
                                         PlayerTestData.Gender,
                                         PlayerTestData.DateOfBirth,
                                         PlayerTestData.ExactHandicapCat1,
                                         PlayerTestData.EmailAddress);
            });
        }
        public void PlayerAggregate_Register_InvalidData(String firstName,
                                                         String lastName,
                                                         String gender,
                                                         Boolean dateOfBirthInFuture,
                                                         Decimal exactHandicap,
                                                         String emailAddress,
                                                         Type exceptionType)
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetEmptyPlayerAggregate();

            DateTime dateOfBirth = dateOfBirthInFuture ? DateTime.Now.AddYears(5) : PlayerTestData.DateOfBirth;

            Should.Throw(() => { playerAggregate.Register(firstName, PlayerTestData.MiddleName, lastName, gender, dateOfBirth, exactHandicap, emailAddress); },
                         exceptionType);
        }
        public void PlayerAggregate_Register_PlayerRegistered_HandicapEdgeCase_HighEnd(Int32 category, Decimal highendValue)
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetEmptyPlayerAggregate();

            Decimal exactHandicap    = 0;
            Int32   handicapCategory = 0;

            switch (category)
            {
            case 1:
                exactHandicap    = highendValue;
                handicapCategory = PlayerTestData.HandicapCategoryCat1;
                break;

            case 2:
                exactHandicap    = highendValue;
                handicapCategory = PlayerTestData.HandicapCategoryCat2;
                break;

            case 3:
                exactHandicap    = highendValue;
                handicapCategory = PlayerTestData.HandicapCategoryCat3;
                break;

            case 4:
                exactHandicap    = highendValue;
                handicapCategory = PlayerTestData.HandicapCategoryCat4;
                break;

            case 5:
                exactHandicap    = highendValue;
                handicapCategory = PlayerTestData.HandicapCategoryCat5;
                break;
            }

            playerAggregate.Register(PlayerTestData.FirstName,
                                     PlayerTestData.MiddleName,
                                     PlayerTestData.LastName,
                                     PlayerTestData.Gender,
                                     PlayerTestData.DateOfBirth,
                                     exactHandicap,
                                     PlayerTestData.EmailAddress);

            playerAggregate.HandicapCategory.ShouldBe(handicapCategory);
        }
        public void PlayerCommandHandler_HandleCommand_RegisterPlayerCommand_CommandHandled()
        {
            Mock <IAggregateRepository <PlayerAggregate> > playerRepository = new Mock <IAggregateRepository <PlayerAggregate> >();

            playerRepository.Setup(c => c.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(PlayerTestData.GetEmptyPlayerAggregate());
            Mock <ISecurityService> oAuth2SecurityService = new Mock <ISecurityService>();

            oAuth2SecurityService
            .Setup(o => o.RegisterUser(It.IsAny <RegisterUserRequest>(), CancellationToken.None))
            .ReturnsAsync(PlayerTestData.GetRegisterUserResponse());
            Mock <IAggregateRepository <GolfClubAggregate> > clubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >();

            clubRepository.Setup(c => c.GetLatestVersion(It.IsAny <Guid>(), CancellationToken.None))
            .ReturnsAsync(GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse());

            PlayerCommandHandler handler = new PlayerCommandHandler(playerRepository.Object, oAuth2SecurityService.Object, clubRepository.Object);

            RegisterPlayerCommand command = PlayerTestData.GetRegisterPlayerCommand();

            Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); });
        }
        public void PlayerAggregate_AdjustHandicap_InvalidData_ErrorThrown(Boolean validAdjustment, Boolean validTournamentId, Boolean validGolfClubId,
                                                                           Boolean validMeasuredCourseId, Boolean validScoreDate, Type exceptionType)
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetRegisteredPlayerAggregate();

            HandicapAdjustmentDataTransferObject handicapAdjustment = validAdjustment
                ? PlayerTestData.HandicapAdjustment
                : null;

            Guid     tournamentId     = validTournamentId ? PlayerTestData.TournamentId : Guid.Empty;
            Guid     golfClubId       = validGolfClubId ? PlayerTestData.GolfClubId : Guid.Empty;
            Guid     measuredCourseId = validMeasuredCourseId ? PlayerTestData.MeasuredCourseId : Guid.Empty;
            DateTime scoreDate        = validScoreDate ? PlayerTestData.ScoreDate: DateTime.MinValue;

            Should.Throw(() =>
            {
                playerAggregate.AdjustHandicap(handicapAdjustment,
                                               tournamentId,
                                               golfClubId,
                                               measuredCourseId,
                                               scoreDate);
            }, exceptionType);
        }
        public void PlayerAggregate_CreateSecurityUser_SecurityUserAlreadyAdded_ErrorThrown()
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetRegisteredPlayerAggregateWithSecurityUserCreated();

            Should.Throw <InvalidOperationException>(() => { playerAggregate.CreateSecurityUser(PlayerTestData.SecurityUserId); });
        }
        public void PlayerAggregate_CreateSecurityUser_PlayerNotRegistered_ErrorThrown()
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetEmptyPlayerAggregate();

            Should.Throw <InvalidOperationException>(() => { playerAggregate.CreateSecurityUser(PlayerTestData.SecurityUserId); });
        }
        public void PlayerAggregate_CreateSecurityUser_InvalidData_ErrorThrown()
        {
            PlayerAggregate playerAggregate = PlayerTestData.GetRegisteredPlayerAggregate();

            Should.Throw <ArgumentNullException>(() => { playerAggregate.CreateSecurityUser(Guid.Empty); });
        }