/// <summary> /// Records the player score. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="playerId">The player identifier.</param> /// <param name="tournamentId">The tournament identifier.</param> /// <param name="request">The request.</param> /// <param name="cancellationToken">The cancellation token.</param> public async Task RecordPlayerScore(String accessToken, Guid playerId, Guid tournamentId, RecordPlayerTournamentScoreRequest request, CancellationToken cancellationToken) { String requestUri = $"{this.BaseAddress}/api/Player/{playerId}/Tournament/{tournamentId}/RecordScore"; try { String requestSerialised = JsonConvert.SerializeObject(request); StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json"); // Add the access token to the client headers this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); // Make the Http Call here HttpResponseMessage httpResponse = await this.HttpClient.PutAsync(requestUri, httpContent, cancellationToken); // Process the response String content = await this.HandleResponse(httpResponse, cancellationToken); // call was successful, no response data to deserialise } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception($"Error recording tournament {tournamentId} score for player.", ex); throw exception; } }
/// <summary> /// Records the player score. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="playerId">The player identifier.</param> /// <param name="tournamentId">The tournament identifier.</param> /// <param name="recordMemberTournamentScoreRequest">The record member tournament score request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task RecordPlayerScore(String accessToken, Guid playerId, Guid tournamentId, RecordPlayerTournamentScoreRequest recordMemberTournamentScoreRequest, CancellationToken cancellationToken) { await this.PlayerClient.RecordPlayerScore(accessToken, playerId, tournamentId, recordMemberTournamentScoreRequest, cancellationToken); }
/// <summary> /// Initializes a new instance of the <see cref="RecordPlayerTournamentScoreCommand" /> class. /// </summary> /// <param name="playerId">The player identifier.</param> /// <param name="tournamentId">The tournament identifier.</param> /// <param name="recordPlayerTournamentScoreRequest">The record player tournament score request.</param> /// <param name="commandId">The command identifier.</param> private RecordPlayerTournamentScoreCommand(Guid playerId, Guid tournamentId, RecordPlayerTournamentScoreRequest recordPlayerTournamentScoreRequest, Guid commandId) : base(commandId) { this.RecordPlayerTournamentScoreRequest = recordPlayerTournamentScoreRequest; this.TournamentId = tournamentId; this.PlayerId = playerId; }
public RecordPlayerTournamentScoreRequest GetRecordPlayerTournamentScoreRequest(String golfClubNumber, String measuredCourseName, String tournamentNumber) { RecordPlayerTournamentScoreRequest request = this.RecordPlayerTournamentScoreRequests .Where(x => x.Key.Item1 == tournamentNumber && x.Key.Item2 == golfClubNumber && x.Key.Item3 == measuredCourseName).Select(x => x.Value).Single(); return(request); }
public async Task PlayerController_PUT_RecordPlayerScore_Successful() { // 1. Arrange HttpClient client = this.WebApplicationFactory.CreateClient(); RecordPlayerTournamentScoreRequest registerPlayerTournamentScoreRequest = TestData.RecordPlayerTournamentScoreRequest; String uri = $"api/players/{TestData.PlayerId}/tournaments/{TestData.TournamentId}/scores"; StringContent content = Helpers.CreateStringContent(registerPlayerTournamentScoreRequest); client.DefaultRequestHeaders.Add("api-version", "2.0"); // 2. Act HttpResponseMessage response = await client.PutAsync(uri, content, CancellationToken.None); // 3. Assert response.StatusCode.ShouldBe(HttpStatusCode.OK); }
public void WhenAPlayerRecordsTheFollowingScoreForTournamentNumberForGolfClubMeasuredCourse(String tournamentNumber, String golfClubNumber, String measuredCourseName, Table table) { CreateTournamentResponse getCreateTournamentResponse = this.TestingContext.GetCreateTournamentResponse(golfClubNumber, measuredCourseName, tournamentNumber); foreach (TableRow tableRow in table.Rows) { RegisterPlayerResponse getRegisterPlayerResponse = this.TestingContext.GetRegisterPlayerResponse(tableRow["PlayerNumber"]); RecordPlayerTournamentScoreRequest recordPlayerTournamentScoreRequest = new RecordPlayerTournamentScoreRequest { HoleScores = new Dictionary <Int32, Int32>() }; for (Int32 i = 1; i <= 18; i++) { recordPlayerTournamentScoreRequest.HoleScores.Add(i, Int32.Parse(tableRow[$"Hole{i}"])); } this.TestingContext.RecordPlayerTournamentScoreRequests.Add(new Tuple <String, String, String, String>(golfClubNumber, measuredCourseName, tournamentNumber, tableRow["PlayerNumber"]), recordPlayerTournamentScoreRequest); } }
public async Task <IActionResult> RecordPlayerScore([FromRoute] Guid playerId, [FromRoute] Guid tournamentId, [FromBody] RecordPlayerTournamentScoreRequest request, CancellationToken cancellationToken) { // Get the Player Id claim from the user Claim playerIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.PlayerId, playerId.ToString()); Boolean validationResult = ClaimsHelper.ValidateRouteParameter(playerId, playerIdClaim); if (validationResult == false) { return(this.Forbid()); } // Create the command RecordPlayerTournamentScoreCommand command = RecordPlayerTournamentScoreCommand.Create(Guid.Parse(playerIdClaim.Value), tournamentId, request); // Route the command await this.CommandRouter.Route(command, cancellationToken); // return the result return(this.Ok()); }
/// <summary> /// Creates the specified record member tournament score request. /// </summary> /// <param name="playerId">The player identifier.</param> /// <param name="tournamentId">The tournament identifier.</param> /// <param name="recordPlayerTournamentScoreRequest">The record player tournament score request.</param> /// <returns></returns> public static RecordPlayerTournamentScoreCommand Create(Guid playerId, Guid tournamentId, RecordPlayerTournamentScoreRequest recordPlayerTournamentScoreRequest) { return(new RecordPlayerTournamentScoreCommand(playerId, tournamentId, recordPlayerTournamentScoreRequest, Guid.NewGuid())); }
/// <summary> /// Creates the tournament datav2. /// </summary> /// <param name="testDataGenerator">The test data generator.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private static async Task CreateTournamentDatav2(ITestDataGenerator testDataGenerator, CancellationToken cancellationToken) { foreach (GolfClubDetails golfClubDetails in Program.GolfClubs) { List <CreateTournamentRequest> requests = Program.GetCreateTournamentRequests(golfClubDetails.MeasuredCourseId); //String passwordToken = testDataGenerator.GetToken(golfClubDetails.AdminEmailAddress); foreach (CreateTournamentRequest createTournamentRequest in requests) { CreateTournamentResponse createTournamentResponse = await testDataGenerator.CreateTournament(Program.accessToken, golfClubDetails.GolfClubId, createTournamentRequest, cancellationToken); Console.WriteLine($"Tournament {createTournamentRequest.Name} created for Club {golfClubDetails.GolfClubName}"); // Get the players for this club List <PlayerDetails> playerList = Program.Players.Where(p => p.GolfClubId == golfClubDetails.GolfClubId).ToList(); foreach (PlayerDetails player in playerList) { Int32 counter = 0; ScoreResult scoreResult = ScoreResult.Under; if (counter == 0) { scoreResult = ScoreResult.Under; counter++; } else if (counter == 1) { scoreResult = ScoreResult.Buffer; counter++; } else { scoreResult = ScoreResult.Over; counter = 0; } RecordPlayerTournamentScoreRequest recordPlayerTournamentScoreRequest = new RecordPlayerTournamentScoreRequest { PlayingHandicap = player.PlayingHandicap, HoleScores = Program.GetHoleScores(player.PlayingHandicap, scoreResult) }; //String playerPasswordToken = testDataGenerator.GetToken(player.EmailAddress); await testDataGenerator.SignUpPlayerForTournament(Program.accessToken, player.PlayerId, createTournamentResponse.TournamentId, cancellationToken); await testDataGenerator.RecordPlayerScore(Program.accessToken, player.PlayerId, createTournamentResponse.TournamentId, recordPlayerTournamentScoreRequest, cancellationToken); Console.WriteLine($"Tournament Score Recorded for Player {player.EmailAddress} for Tournament {createTournamentRequest.Name} at Golf Club {golfClubDetails.GolfClubName}"); } } } }