/// <summary> /// Gets the measured courses. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="golfClubId">The golf club identifier.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <List <MeasuredCourseListResponse> > GetMeasuredCourses(String accessToken, Guid golfClubId, CancellationToken cancellationToken) { List <MeasuredCourseListResponse> response = new List <MeasuredCourseListResponse>(); String requestUri = $"{this.BaseAddress}/api/golfclubs/{golfClubId}?includeMeasuredCourses=true"; try { // Add the access token to the client headers this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); // Make the Http Call here StringContent httpContent = new StringContent(string.Empty, Encoding.UTF8, "application/json"); HttpResponseMessage httpResponse = await this.HttpClient.GetAsync(requestUri, cancellationToken); // Process the response String content = await this.HandleResponse(httpResponse, cancellationToken); // call was successful so now deserialise the body to the response object GetGolfClubResponse getGolfClubResponse = JsonConvert.DeserializeObject <GetGolfClubResponse>(content); response = getGolfClubResponse.MeasuredCourses; } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception("Error requesting Golf Club measured courses.", ex); throw exception; } return(response); }
public async Task RegisterPlayer(String golfClubName, TableRow tableRow) { String clientToken = await this.GetToken(TokenType.Client, "golfhandicap.testdatagenerator", "golfhandicap.testdatagenerator").ConfigureAwait(false);; Func <String, String> baseAddressResolver = (address) => { return($"http://127.0.0.1:{this.ManagementAPIPort}"); }; HttpClient httpClient = new HttpClient(); IPlayerClient playerClient = new PlayerClient(baseAddressResolver, httpClient); List <GetGolfClubResponse> golfClubList = await playerClient.GetGolfClubList(clientToken, Guid.Empty, CancellationToken.None).ConfigureAwait(false);; GetGolfClubResponse golfClub = golfClubList.SingleOrDefault(g => g.Name == golfClubName); if (golfClub != null) { DateTime dateOfBirth = DateTime.Now.AddYears(Int32.Parse(tableRow["Age"]) * -1).AddDays(-1); RegisterPlayerRequest registerPlayerRequest = new RegisterPlayerRequest { DateOfBirth = dateOfBirth, EmailAddress = tableRow["EmailAddress"], Gender = tableRow["Gender"], ExactHandicap = Decimal.Parse(tableRow["ExactHandicap"]), FamilyName = tableRow["FamilyName"], GivenName = tableRow["GivenName"], }; var registerPlayerResponse = await playerClient.RegisterPlayer(registerPlayerRequest, CancellationToken.None).ConfigureAwait(false); await playerClient.RequestClubMembership(clientToken, registerPlayerResponse.PlayerId, golfClub.Id, CancellationToken.None).ConfigureAwait(false); } }
/// <summary> /// Gets the golf club user list. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="golfClubId">The golf club identifier.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <List <GolfClubUserResponse> > GetGolfClubUserList(String accessToken, Guid golfClubId, CancellationToken cancellationToken) { List <GolfClubUserResponse> response = null; String requestUri = $"{this.BaseAddress}/api/golfclubs/{golfClubId}?includeUsers=true"; try { // 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.GetAsync(requestUri, cancellationToken); // Process the response String content = await this.HandleResponse(httpResponse, cancellationToken); // call was successful so now deserialise the body to the response object GetGolfClubResponse getGolfClubResponse = JsonConvert.DeserializeObject <GetGolfClubResponse>(content); response = getGolfClubResponse.Users; } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception("Error getting a golf club users list.", ex); throw exception; } return(response); }
public void ThenTheGolfClubDataWillBeReturned() { GetGolfClubResponse response = this.TestingContext.GetGolfClubResponse; response.ShouldNotBeNull(); response.Name.ShouldBe("Test Golf Club 1"); }
/// <summary> /// Gets the golf club. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="claimsIdentity">The claims identity.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <UpdateGolfClubViewModel> GetGolfClub(String accessToken, ClaimsIdentity claimsIdentity, CancellationToken cancellationToken) { Guid golfClubId = ApiClient.GetClaimValue <Guid>(claimsIdentity, "GolfClubId"); GetGolfClubResponse getGolfClubResponse = await this.GolfClubClient.GetSingleGolfClub(accessToken, golfClubId, cancellationToken); return(this.ModelFactory.ConvertFrom(getGolfClubResponse)); }
public async Task <IActionResult> GetGolfClub([FromRoute] Guid golfClubId, CancellationToken cancellationToken) { // Get the Golf Club Id claim from the user Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId, golfClubId.ToString()); Boolean validationResult = ClaimsHelper.ValidateRouteParameter(golfClubId, golfClubIdClaim); if (validationResult == false) { return(this.Forbid()); } GetGolfClubResponse golfClub = await this.Manager.GetGolfClub(Guid.Parse(golfClubIdClaim.Value), cancellationToken); return(this.Ok(golfClub)); }
/// <summary> /// Converts from. /// </summary> /// <param name="apiResponse">The API response.</param> /// <returns></returns> public UpdateGolfClubViewModel ConvertFrom(GetGolfClubResponse apiResponse) { UpdateGolfClubViewModel viewModel = new UpdateGolfClubViewModel { Region = apiResponse.Region, Town = apiResponse.Town, Website = apiResponse.Website, EmailAddress = apiResponse.EmailAddress, Name = apiResponse.Name, TelephoneNumber = apiResponse.TelephoneNumber, AddressLine1 = apiResponse.AddressLine1, AddressLine2 = apiResponse.AddressLine2, PostalCode = apiResponse.PostalCode, Id = apiResponse.Id }; return(viewModel); }
public void ModelFactory_ConvertFrom_GetGolfClubResponse_ConvertedSuccessfully() { ModelFactory factory = new ModelFactory(); GetGolfClubResponse apiResponse = ModelFactoryTestData.GetGetGolfClubResponse(); UpdateGolfClubViewModel viewModel = factory.ConvertFrom(apiResponse); viewModel.AddressLine1.ShouldBe(apiResponse.AddressLine1); viewModel.Region.ShouldBe(apiResponse.Region); viewModel.Town.ShouldBe(apiResponse.Town); viewModel.Website.ShouldBe(apiResponse.Website); viewModel.Name.ShouldBe(apiResponse.Name); viewModel.TelephoneNumber.ShouldBe(apiResponse.TelephoneNumber); viewModel.EmailAddress.ShouldBe(apiResponse.EmailAddress); viewModel.AddressLine2.ShouldBe(apiResponse.AddressLine2); viewModel.PostalCode.ShouldBe(apiResponse.PostalCode); viewModel.Id.ShouldBe(apiResponse.Id); }
public async Task GolfClubClient_GetGolfClub_GolfClubListReturned() { // 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 GetGolfClubResponse getGolfClubResponse = await golfClubClient.GetGolfClub(token, TestData.GolfClubId, CancellationToken.None); // 3. Assert getGolfClubResponse.Id.ShouldBe(TestData.GolfClubId); getGolfClubResponse.Users.ShouldBeNull(); getGolfClubResponse.MeasuredCourses.ShouldBeNull(); getGolfClubResponse.GolfClubMembershipDetailsResponseList.ShouldBeNull(); }