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); } }
/// <summary> /// Handles the command. /// </summary> /// <param name="command">The command.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private async Task HandleCommand(CreateTournamentCommand command, CancellationToken cancellationToken) { // Rehydrate the aggregate TournamentAggregate tournament = await this.TournamentRepository.GetLatestVersion(command.TournamentId, cancellationToken); // Get the club to validate the input GolfClubAggregate club = await this.GolfClubRepository.GetLatestVersion(command.GolfClubId, cancellationToken); // bug #29 fixes (throw exception if club not created) if (!club.HasBeenCreated) { throw new NotFoundException($"No created golf club found with Id {command.GolfClubId}"); } // Club is valid, now check the measured course, this will throw exception if not found MeasuredCourseDataTransferObject measuredCourse = club.GetMeasuredCourse(command.CreateTournamentRequest.MeasuredCourseId); tournament.CreateTournament(command.CreateTournamentRequest.TournamentDate, command.GolfClubId, command.CreateTournamentRequest.MeasuredCourseId, measuredCourse.StandardScratchScore, command.CreateTournamentRequest.Name, (PlayerCategory)command.CreateTournamentRequest.MemberCategory, (TournamentFormat)command.CreateTournamentRequest.Format); // Save the changes await this.TournamentRepository.SaveChanges(tournament, cancellationToken); // Setup the response command.Response = new CreateTournamentResponse { TournamentId = command.TournamentId }; }
public void GolfClubAggregate_GetMeasuredCourse_MeasuredCourseNotFound_ErrorThrown() { GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse(); MeasuredCourseDataTransferObject measuredCourseDataTransferObject = GolfClubTestData.GetMeasuredCourseToAdd(); Should.Throw <NotFoundException>(() => { aggregate.GetMeasuredCourse(GolfClubTestData.InvalidMeasuredCourseId); }); }