public void GolfClubAggregate_AddTournamentDivision_NullTournamentDivision_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();
            TournamentDivisionDataTransferObject tournamentDivision = null;

            Should.Throw <ArgumentNullException>(() => { aggregate.AddTournamentDivision(tournamentDivision); });
        }
        public void GolfClubAggregate_GetMeasuredCourse_MeasuredCourseWithHolesReturned()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();

            MeasuredCourseDataTransferObject measuredCourseDataTransferObject = GolfClubTestData.GetMeasuredCourseToAdd();

            MeasuredCourseDataTransferObject measuredCourse = aggregate.GetMeasuredCourse(measuredCourseDataTransferObject.MeasuredCourseId);

            measuredCourse.ShouldNotBeNull();
            measuredCourse.Name.ShouldBe(measuredCourseDataTransferObject.Name);
            measuredCourse.StandardScratchScore.ShouldBe(measuredCourseDataTransferObject.StandardScratchScore);
            measuredCourse.TeeColour.ShouldBe(measuredCourseDataTransferObject.TeeColour);
            measuredCourse.Holes.Count.ShouldBe(measuredCourseDataTransferObject.Holes.Count);

            IOrderedEnumerable <HoleDataTransferObject> resultHoles = measuredCourse.Holes.OrderBy(m => m.HoleNumber);

            foreach (HoleDataTransferObject holeDataTransferObject in resultHoles)
            {
                HoleDataTransferObject orignalHole = measuredCourseDataTransferObject.Holes.Single(h => h.HoleNumber == holeDataTransferObject.HoleNumber);

                holeDataTransferObject.HoleNumber.ShouldBe(orignalHole.HoleNumber);
                holeDataTransferObject.LengthInMeters.ShouldBe(orignalHole.LengthInMeters);
                holeDataTransferObject.LengthInYards.ShouldBe(orignalHole.LengthInYards);
                holeDataTransferObject.Par.ShouldBe(orignalHole.Par);
                holeDataTransferObject.StrokeIndex.ShouldBe(orignalHole.StrokeIndex);
            }
        }
        public void GolfClubAggregate_AddTournamentDivision_DivisionAdded()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();
            TournamentDivisionDataTransferObject tournamentDivision = GolfClubTestData.GetTournamentDivision1();

            Should.NotThrow(() => { aggregate.AddTournamentDivision(tournamentDivision); });
        }
        public void GolfClubAggregate_GetMeasuredCourse_MeasuredCourseNotFound_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();

            MeasuredCourseDataTransferObject measuredCourseDataTransferObject = GolfClubTestData.GetMeasuredCourseToAdd();

            Should.Throw <NotFoundException>(() => { aggregate.GetMeasuredCourse(GolfClubTestData.InvalidMeasuredCourseId); });
        }
        public void GolfClubAggregate_AddTournamentDivision_DuplicateDivision_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();
            TournamentDivisionDataTransferObject tournamentDivision = GolfClubTestData.GetTournamentDivision1();

            aggregate.AddTournamentDivision(tournamentDivision);

            Should.Throw <InvalidOperationException>(() => { aggregate.AddTournamentDivision(tournamentDivision); });
        }
        public void GolfClubAggregate_GetMeasuredCourses_MeasuredCoursesReturned()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();

            MeasuredCourseDataTransferObject measuredCourseDataTransferObject = GolfClubTestData.GetMeasuredCourseToAdd();

            List <MeasuredCourseDataTransferObject> measuredCourses = aggregate.GetMeasuredCourses();

            measuredCourses.ShouldNotBeEmpty();
            measuredCourses.First().MeasuredCourseId.ShouldBe(measuredCourseDataTransferObject.MeasuredCourseId);
            measuredCourses.First().Name.ShouldBe(measuredCourseDataTransferObject.Name);
            measuredCourses.First().TeeColour.ShouldBe(measuredCourseDataTransferObject.TeeColour);
            measuredCourses.First().StandardScratchScore.ShouldBe(measuredCourseDataTransferObject.StandardScratchScore);
        }
        public void GolfClubAggregate_AddTournamentDivision_InvalidDivisionData_ErrorThrown(Int32 division,
                                                                                            Int32 startHandicap,
                                                                                            Int32 endHandicap,
                                                                                            Type exceptionType)
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();
            TournamentDivisionDataTransferObject tournamentDivision = new TournamentDivisionDataTransferObject
            {
                Division      = division,
                EndHandicap   = endHandicap,
                StartHandicap = startHandicap
            };

            Should.Throw(() => { aggregate.AddTournamentDivision(tournamentDivision); }, exceptionType);
        }
        public void GolfClubAggregate_AddTournamentDivision_DivisionStartHandicapClashesWithExistingRange_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();
            TournamentDivisionDataTransferObject tournamentDivision = GolfClubTestData.GetTournamentDivision1();

            aggregate.AddTournamentDivision(tournamentDivision);

            TournamentDivisionDataTransferObject tournamentDivisionInvalid = new TournamentDivisionDataTransferObject
            {
                Division      = 2,
                EndHandicap   = 12,
                StartHandicap = GolfClubTestData.GetTournamentDivision1().StartHandicap
            };

            Should.Throw <InvalidDataException>(() => { aggregate.AddTournamentDivision(tournamentDivisionInvalid); });
        }
コード例 #9
0
        public void TournamentCommandHandler_HandleCommand_CreateTournamentCommand_CommandHandled()
        {
            Mock <IAggregateRepository <GolfClubAggregate> > golfClubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >();

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

            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.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); });
        }
        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); });
        }