/// <summary> /// Registers the player. /// </summary> /// <param name="request">The request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <RegisterPlayerResponse> RegisterPlayer(RegisterPlayerRequest request, CancellationToken cancellationToken) { RegisterPlayerResponse response = null; String requestUri = $"{this.BaseAddress}/api/Player"; try { String requestSerialised = JsonConvert.SerializeObject(request); StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json"); // Make the Http Call here HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken); // Process the response String content = await this.HandleResponse(httpResponse, cancellationToken); // call was successful so now deserialise the body to the response object response = JsonConvert.DeserializeObject <RegisterPlayerResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception($"Error creating the new player {request.GivenName} {request.FamilyName}.", ex); throw exception; } return(response); }
public async Task GivenTheFollowingPlayersHaveRegistered(Table table) { foreach (TableRow tableRow in table.Rows) { Int32 age = Int32.Parse(tableRow["Age"]); RegisterPlayerRequest registerPlayerRequest = new RegisterPlayerRequest { DateOfBirth = DateTime.Now.AddYears(age * -1), FamilyName = tableRow["FamilyName"], GivenName = tableRow["GivenName"], MiddleName = tableRow["MiddleName"], EmailAddress = tableRow["EmailAddress"], ExactHandicap = Decimal.Parse(tableRow["ExactHandicap"]), Gender = tableRow["Gender"], }; this.TestingContext.RegisterPlayerRequests.Add(tableRow["PlayerNumber"], registerPlayerRequest); RegisterPlayerResponse registerPlayerResponse = await this.TestingContext.DockerHelper.PlayerClient.RegisterPlayer(registerPlayerRequest, CancellationToken.None).ConfigureAwait(false); this.TestingContext.RegisterPlayerResponses.Add(tableRow["PlayerNumber"], registerPlayerResponse); } }
public async Task ThenTheNewExactHandicapForPlayerNumberIsAdjustedTo(String playerNumber, Decimal exactHandicap) { RegisterPlayerResponse registerPlayerResponse = this.TestingContext.GetRegisterPlayerResponse(playerNumber); GetPlayerResponse player = await this.TestingContext.DockerHelper.PlayerClient.GetPlayer(this.TestingContext.PlayerToken, registerPlayerResponse.PlayerId, CancellationToken.None).ConfigureAwait(false); player.ExactHandicap.ShouldBe(exactHandicap); }
public async Task WhenIRequestANumberOfScoresReportForPlayerNumberWithTheLastScores(String playerNumber, Int32 numberOfScores) { RegisterPlayerResponse registerPlayerResponse = this.TestingContext.GetRegisterPlayerResponse(playerNumber); this.TestingContext.GetPlayerScoresResponse = await this.TestingContext.DockerHelper.ReportingClient.GetPlayerScores(this.TestingContext.GolfClubAdministratorToken, registerPlayerResponse.PlayerId, numberOfScores, CancellationToken.None).ConfigureAwait(false); }
public void ThenThePlayerRegistrationForPlayerNumberShouldBeSuccessful(String playerNumber) { Should.NotThrow(async() => { RegisterPlayerResponse registerPlayerResponse = await this.TestingContext.DockerHelper.PlayerClient.RegisterPlayer(this.TestingContext.RegisterPlayerRequest, CancellationToken.None).ConfigureAwait(false); this.TestingContext.RegisterPlayerResponse = registerPlayerResponse; this.TestingContext.RegisterPlayerResponses.Add(playerNumber, registerPlayerResponse); }); }
/// <summary> /// Creates the player datav2. /// </summary> /// <param name="testDataGenerator">The test data generator.</param> /// <param name="numberPlayersPerClub">The number players per club.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private static async Task CreatePlayerDatav2(ITestDataGenerator testDataGenerator, Int32 lastClub, Int32 numberPlayersPerClub, CancellationToken cancellationToken) { Int32 clubCounter = lastClub + 1; foreach (GolfClubDetails golfClubDetails in Program.GolfClubs) { for (Int32 i = 0; i < numberPlayersPerClub; i++) { RegisterPlayerRequest registerPlayerRequest = new RegisterPlayerRequest { DateOfBirth = DateTime.Now.AddYears(-30), EmailAddress = $"player{i}.{clubCounter}@testplayer.co.uk", ExactHandicap = i, GivenName = $"Club {clubCounter}", Gender = "M", FamilyName = $"Test Player {i}", MiddleName = null }; RegisterPlayerResponse registerPlayerResponse = await testDataGenerator.RegisterPlayer(registerPlayerRequest, cancellationToken); Console.WriteLine($"Created Player {registerPlayerRequest.GivenName} {registerPlayerRequest.FamilyName}"); //String token = await testDataGenerator.GetToken(TokenType.Password, // "developerClient", // "developerClient", // registerPlayerRequest.EmailAddress, // "123456", // new List<String> // { // "openid", // "profile", // "managementapi" // }); await testDataGenerator.RequestClubMembership(Program.accessToken, registerPlayerResponse.PlayerId, golfClubDetails.GolfClubId, cancellationToken); Console.WriteLine($"Player {registerPlayerRequest.GivenName} {registerPlayerRequest.FamilyName} membership requested"); Program.Players.Add(new PlayerDetails { GolfClubId = golfClubDetails.GolfClubId, PlayerId = registerPlayerResponse.PlayerId, PlayingHandicap = Convert.ToInt32(registerPlayerRequest.ExactHandicap), // TODO: Rounding EmailAddress = registerPlayerRequest.EmailAddress }); } clubCounter++; } }
public async Task WhenPlayerNumberSignsUpToPlayInTournamentNumberForGolfClubMeasuredCourse(String playerNumber, String tournamentNumber, String golfClubNumber, String measuredCourseName) { RegisterPlayerResponse getRegisterPlayerResponse = this.TestingContext.GetRegisterPlayerResponse(playerNumber); CreateTournamentResponse getCreateTournamentResponse = this.TestingContext.GetCreateTournamentResponse(golfClubNumber, measuredCourseName, tournamentNumber); await this.TestingContext.DockerHelper.PlayerClient .SignInForTournament(this.TestingContext.PlayerToken, getRegisterPlayerResponse.PlayerId, getCreateTournamentResponse.TournamentId, CancellationToken.None).ConfigureAwait(false); }
public void ThenEachMemberHasTheCorrectHandicapOnTheReport() { foreach (KeyValuePair <String, RegisterPlayerRequest> registerPlayerRequest in this.TestingContext.RegisterPlayerRequests) { RegisterPlayerResponse registerPlayerResponse = this.TestingContext.RegisterPlayerResponses[registerPlayerRequest.Key]; MembersHandicapListReportResponse playerHandicapEntry = this.TestingContext.GetMembersHandicapListReportResponse.MembersHandicapListReportResponse.SingleOrDefault(x => x.PlayerId == registerPlayerResponse .PlayerId); playerHandicapEntry.ShouldNotBeNull(); playerHandicapEntry.ExactHandicap.ShouldBe(registerPlayerRequest.Value.ExactHandicap); } }
public async Task PlayerClient_RegisterPlayer_PlayerCreated() { // 1. Arrange HttpClient client = this.WebApplicationFactory.CreateClient(); Func <String, String> resolver = api => "http://localhost"; IPlayerClient playerClient = new PlayerClient(resolver, client); // 2. Act RegisterPlayerResponse registerPlayerResponse = await playerClient.RegisterPlayer(TestData.RegisterPlayerRequest, CancellationToken.None); // 3. Assert registerPlayerResponse.PlayerId.ShouldNotBe(Guid.Empty); }
public void WhenIRequestMembershipOfClubNumberForPlayerNumberTheRequestIsSuccessful(String clubNumber, String playerNumber) { CreateGolfClubResponse createGolfClubResponse = this.TestingContext.GetCreateGolfClubResponse(clubNumber); RegisterPlayerResponse registerPlayerResponse = this.TestingContext.GetRegisterPlayerResponse(playerNumber); Should.NotThrow(async() => { await this.TestingContext.DockerHelper.PlayerClient.RequestClubMembership(this.TestingContext.PlayerToken, registerPlayerResponse.PlayerId, createGolfClubResponse.GolfClubId, CancellationToken.None).ConfigureAwait(false); }); }
public IEnumerator RegisterPlayer(Action <RegisterPlayerResponse> onRegisterPlayerResponse, Action <string> onError) { RegisterPlayerRequest request = new RegisterPlayerRequest(); yield return(SyncPost( request, responseText => { onRegisterPlayerResponse(RegisterPlayerResponse.FromJSON(responseText)); }, onError )); }
public async Task WhenIRequestAListOfMyMembershipsAsPlayer(String playerNumber) { RegisterPlayerResponse registerPlayerResponse = this.TestingContext.GetRegisterPlayerResponse(playerNumber); await Retry.For(async() => { List <ClubMembershipResponse> getClubMembershipResponses = await this .TestingContext.DockerHelper.PlayerClient .GetPlayerMemberships(this.TestingContext.PlayerToken, registerPlayerResponse.PlayerId, CancellationToken.None).ConfigureAwait(false); if (getClubMembershipResponses.Count == 0) { throw new Exception(); } this.TestingContext.GetGolfClubMembershipResponseList = getClubMembershipResponses; }).ConfigureAwait(false); }
public async Task ThenPlayerNumberIsRecordedAsSignedUpForTournamentNumberForGolfClubMeasuredCourse(String playerNumber, String tournamentNumber, String golfClubNumber, String measuredCourseName) { RegisterPlayerResponse getRegisterPlayerResponse = this.TestingContext.GetRegisterPlayerResponse(playerNumber); CreateTournamentResponse getCreateTournamentResponse = this.TestingContext.GetCreateTournamentResponse(golfClubNumber, measuredCourseName, tournamentNumber); await Retry.For(async() => { List <SignedUpTournamentResponse> response = await this .TestingContext.DockerHelper.PlayerClient .GetTournamentsSignedUpFor(this.TestingContext.PlayerToken, getRegisterPlayerResponse.PlayerId, CancellationToken.None).ConfigureAwait(false); List <SignedUpTournamentResponse> tournamentSignUp = response.Where(s => s.TournamentId == getCreateTournamentResponse.TournamentId).ToList(); tournamentSignUp.ShouldNotBeNull(); tournamentSignUp.ShouldNotBeEmpty(); tournamentSignUp.Count.ShouldBe(1); }); }
/// <summary> /// Registers the player. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task RegisterPlayer(RegistrationViewModel viewModel, CancellationToken cancellationToken) { // Translate the view model into the api request RegisterPlayerRequest apiRequest = new RegisterPlayerRequest { DateOfBirth = viewModel.DateOfBirth, Gender = viewModel.Gender == 0 ? "M" : "F", EmailAddress = viewModel.EmailAddress, MiddleName = viewModel.MiddleName, ExactHandicap = decimal.Parse(viewModel.ExactHandicap), FamilyName = viewModel.LastName, GivenName = viewModel.FirstName }; RegisterPlayerResponse apiResponse = await this.PlayerClient.RegisterPlayer(apiRequest, cancellationToken); // Set the result in the view model viewModel.PlayerId = apiResponse.PlayerId; }
public void ThenTheScoresRecordedByThePlayersAreRecordedAgainstTournamentNumberForGolfClubMeasuredCourse(String tournamentNumber, String golfClubNumber, String measuredCourseName) { CreateTournamentResponse getCreateTournamentResponse = this.TestingContext.GetCreateTournamentResponse(golfClubNumber, measuredCourseName, tournamentNumber); List <KeyValuePair <Tuple <String, String, String, String>, RecordPlayerTournamentScoreRequest> > filtered = this.TestingContext.RecordPlayerTournamentScoreRequests .Where(x => x.Key.Item1 == golfClubNumber && x.Key.Item2 == measuredCourseName && x.Key.Item3 == tournamentNumber).ToList(); foreach (KeyValuePair <Tuple <String, String, String, String>, RecordPlayerTournamentScoreRequest> keyValuePair in filtered) { RegisterPlayerResponse getRegisterPlayerResponse = this.TestingContext.GetRegisterPlayerResponse(keyValuePair.Key.Item4); Should.NotThrow(async() => { await this.TestingContext.DockerHelper.PlayerClient .RecordPlayerScore(this.TestingContext.PlayerToken, getRegisterPlayerResponse.PlayerId, getCreateTournamentResponse.TournamentId, keyValuePair.Value, CancellationToken.None).ConfigureAwait(false); }); } }
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 GivenTheFollowingPlayersAreClubMembersOfTheFollowingGolfClubs(Table table) { foreach (TableRow tableRow in table.Rows) { RegisterPlayerRequest registerPlayerRequest = this.TestingContext.GetRegisterPlayerRequest(tableRow["PlayerNumber"]); RegisterPlayerResponse registerPlayerResponse = this.TestingContext.GetRegisterPlayerResponse(tableRow["PlayerNumber"]); CreateGolfClubResponse golfClubResponse = this.TestingContext.GetCreateGolfClubResponse(tableRow["GolfClubNumber"]); this.TestingContext.PlayerToken = await this.TestingContext.DockerHelper.GetToken(TokenType.Password, "golfhandicap.mobile", "golfhandicap.mobile", registerPlayerRequest.EmailAddress, "123456").ConfigureAwait(false); await this.TestingContext.DockerHelper.PlayerClient.RequestClubMembership(this.TestingContext.PlayerToken, registerPlayerResponse.PlayerId, golfClubResponse.GolfClubId, CancellationToken.None).ConfigureAwait(false); } }
public async Task ThenTheFollowingScoresAreReturnedForPlayer(String playerNumber, Table table) { await Retry.For(async() => { RegisterPlayerResponse registerPlayerResponse = this.TestingContext.GetRegisterPlayerResponse(playerNumber); this.TestingContext.GetPlayerScoresResponse = await this.TestingContext.DockerHelper.ReportingClient.GetPlayerScores(this.TestingContext.GolfClubAdministratorToken, registerPlayerResponse.PlayerId, table.RowCount, CancellationToken.None).ConfigureAwait(false); this.TestingContext.GetPlayerScoresResponse.Scores.Count.ShouldBe(table.RowCount); foreach (TableRow tableRow in table.Rows) { PlayerScoreResponse score = this.TestingContext.GetPlayerScoresResponse.Scores.SingleOrDefault(x => x.TournamentName == tableRow["TournamentName"] && x.TournamentDate == this.CalculateTournamentDate(tableRow)); score.ShouldNotBeNull(); } }); }
public async Task WhenIRequestThePlayerDetailsForPlayerNumber(String playerNumber) { RegisterPlayerResponse registerPlayerResponse = this.TestingContext.GetRegisterPlayerResponse(playerNumber); this.TestingContext.GetPlayerResponse = await this.TestingContext.DockerHelper.PlayerClient.GetPlayer(this.TestingContext.PlayerToken, registerPlayerResponse.PlayerId, CancellationToken.None).ConfigureAwait(false); }