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 async Task WhenIStartTheHandicapCalculationProcessForTournamentNumberForGolfClubMeasuredCourse(String tournamentNumber, String golfClubNumber, String measuredCourseName) { CreateTournamentResponse createTournamentResponse = this.TestingContext.GetCreateTournamentResponse(golfClubNumber, measuredCourseName, tournamentNumber); String uri = $"/api/HandicapCalculation?tournamentId={createTournamentResponse.TournamentId}"; this.TestingContext.DockerHelper.HttpClient.DefaultRequestHeaders.Remove("Authorization"); this.TestingContext.DockerHelper.HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {this.TestingContext.GolfClubAdministratorToken}"); HttpResponseMessage response = await this.TestingContext.DockerHelper.HttpClient.PostAsync(uri, new StringContent(String.Empty, Encoding.UTF8, "application/json"), CancellationToken.None).ConfigureAwait(false); response.StatusCode.ShouldBe(HttpStatusCode.NoContent); }
public void WhenIRequestToProduceATournamentResultForTournamentNumberForGolfClubMeasuredCourseTheResultsAreProduced(String tournamentNumber, String golfClubNumber, String measuredCourseName) { CreateGolfClubResponse createGolfClubResponse = this.TestingContext.GetCreateGolfClubResponse(golfClubNumber); CreateTournamentResponse createTournamentResponse = this.TestingContext.GetCreateTournamentResponse(golfClubNumber, measuredCourseName, tournamentNumber); Should.NotThrow(async() => { await this.TestingContext.DockerHelper.GolfClubClient .ProduceTournamentResult(this.TestingContext.GolfClubAdministratorToken, createGolfClubResponse.GolfClubId, createTournamentResponse.TournamentId, CancellationToken.None) .ConfigureAwait(false); }); }
public async Task ThenTournamentNumberForGolfClubMeasuredCourseWillBeCreated(String tournamentNumber, String golfClubNumber, String measuredCourseName) { CreateTournamentRequest createTournamentRequest = this.TestingContext.GetCreateTournamentRequest(golfClubNumber, measuredCourseName, tournamentNumber); CreateGolfClubResponse createGolfClubResponse = this.TestingContext.GetCreateGolfClubResponse(golfClubNumber); CreateTournamentResponse createTournamentResponse = await this.TestingContext.DockerHelper.GolfClubClient .CreateTournament(this.TestingContext.GolfClubAdministratorToken, createGolfClubResponse.GolfClubId, createTournamentRequest, CancellationToken.None) .ConfigureAwait(false); createTournamentResponse.TournamentId.ShouldNotBe(Guid.Empty); this.TestingContext.CreateTournamentResponses.Add(new Tuple <String, String, String>(golfClubNumber, measuredCourseName, tournamentNumber), createTournamentResponse); }
public async Task GolfClubClient_CreateTournament_TournamentIsCreated() { // 1. Arrange HttpClient client = this.WebApplicationFactory.AddGolfClubAdministrator().CreateClient(); Func <String, String> resolver = api => "http://localhost"; IGolfClubClient golfClubClient = new GolfClubClient(resolver, client); String token = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImVhZDQyNGJjNjI5MzU0NGM4MGFmZThhMDk2MzEyNjU2IiwidHlwIjoiSldUIn0.eyJuYmYiOjE1NzAyODk3MDksImV4cCI6MTU3MDI5MzMwOSwiaXNzIjoiaHR0cDovLzE5Mi4xNjguMS4xMzI6NTAwMSIsImF1ZCI6WyJodHRwOi8vMTkyLjE2OC4xLjEzMjo1MDAxL3Jlc291cmNlcyIsIm1hbmFnZW1lbnRhcGkiLCJzZWN1cmlydHlzZXJ2aWNlYXBpIl0sImNsaWVudF9pZCI6ImdvbGZoYW5kaWNhcC50ZXN0ZGF0YWdlbmVyYXRvciIsInNjb3BlIjpbIm1hbmFnZW1lbnRhcGkiLCJzZWN1cmlydHlzZXJ2aWNlYXBpIl19.vLfs2bOMXshW93nw5TTOqd6NPGNYpcrhcom8yZoYc9WGSuYH48VqM5BdbodEukNNJmgbV9wUVgoj1uGztlFfHGFA_q6IQfd3xZln_LIxju6ZNZs8qUyRXDTGxu0dlfF8STLfBUq469SsY9eNi1hBYFyNxl963OfKqDSHAdeBg9yNlwnbky1Tnsxobu9W33fLcjH0KoutlwTFV51UFUEKCBk0w1zsjaDVZacETn74t56y0CvMS7ZSN2_yyunq4JvoUsh3xM5lQ-gl23eQyo6l4QE4wukCS7U_Zr2dg8-EF63VKiCH-ZD49M76TD9kIIge-XIgHqa2Xf3S-FpLxXfEqw"; // 2. Act CreateTournamentResponse createTournamentResponse = await golfClubClient.CreateTournament(token, TestData.GolfClubId, TestData.CreateTournamentRequest, CancellationToken.None); // 3. Assert createTournamentResponse.TournamentId.ShouldNotBe(Guid.Empty); }
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); }); }
public void WhenIRequestToCancelTheTournamentNumberForGolfClubMeasuredCourseTheTournamentIsCancelled(String tournamentNumber, String golfClubNumber, String measuredCourseName) { CreateGolfClubResponse createGolfClubResponse = this.TestingContext.GetCreateGolfClubResponse(golfClubNumber); CreateTournamentResponse createTournamentResponse = this.TestingContext.GetCreateTournamentResponse(golfClubNumber, measuredCourseName, tournamentNumber); CancelTournamentRequest cancelTournamentRequest = new CancelTournamentRequest { CancellationReason = "Test Cancel" }; Should.NotThrow(async() => { await this.TestingContext.DockerHelper.GolfClubClient.CancelTournament(this.TestingContext.GolfClubAdministratorToken, createGolfClubResponse.GolfClubId, createTournamentResponse.TournamentId, cancelTournamentRequest, CancellationToken.None).ConfigureAwait(false); }); }
public async Task WhenTheProcessCompletesSuccessfullyForTournamentNumberForGolfClubMeasuredCourse(String tournamentNumber, String golfClubNumber, String measuredCourseName) { CreateTournamentResponse createTournamentResponse = this.TestingContext.GetCreateTournamentResponse(golfClubNumber, measuredCourseName, tournamentNumber); await Retry.For(async() => { String uri = $"/api/HandicapCalculation?tournamentId={createTournamentResponse.TournamentId}"; this.TestingContext.DockerHelper.HttpClient.DefaultRequestHeaders.Remove("Authorization"); this.TestingContext.DockerHelper.HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {this.TestingContext.GolfClubAdministratorToken}"); HttpResponseMessage response = await this.TestingContext.DockerHelper.HttpClient.GetAsync(uri, CancellationToken.None).ConfigureAwait(false); response.StatusCode.ShouldBe(HttpStatusCode.OK); String responseData = await response.Content.ReadAsStringAsync(); responseData.Contains("Completed").ShouldBeTrue(); }); }
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); } }
/// <summary> /// Creates the tournament. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="golfClubId">The golf club identifier.</param> /// <param name="request">The request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <CreateTournamentResponse> CreateTournament(String accessToken, Guid golfClubId, CreateTournamentRequest request, CancellationToken cancellationToken) { CreateTournamentResponse response = null; String requestUri = $"{this.BaseAddress}/api/golfclubs/{golfClubId}/tournaments"; 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.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 <CreateTournamentResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception($"Error creating the new tournament {request.Name}.", ex); throw exception; } return(response); }
/// <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}"); } } } }