public async Task GolfClubController_POST_RequestClubMembership_MembershipIdReturned() { // 1. Arrange HttpClient client = this.WebApplicationFactory.AddPlayer().CreateClient(); String uri = $"api/golfclubs/{TestData.GolfClubId}/players/{TestData.PlayerId}"; client.DefaultRequestHeaders.Add("api-version", "2.0"); StringContent content = new StringContent(String.Empty); // 2. Act HttpResponseMessage response = await client.PostAsync(uri, content, CancellationToken.None); // 3. Assert response.StatusCode.ShouldBe(HttpStatusCode.Created); String responseAsJson = await response.Content.ReadAsStringAsync(); responseAsJson.ShouldNotBeNullOrEmpty(); RequestClubMembershipResponse responseObject = JsonConvert.DeserializeObject <RequestClubMembershipResponse>(responseAsJson); responseObject.GolfClubId.ShouldBe(TestData.GolfClubId); responseObject.PlayerId.ShouldBe(TestData.PlayerId); responseObject.MembershipId.ShouldBe(Guid.Empty); }
/// <summary> /// Requests the club membership. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="playerId">The player identifier.</param> /// <param name="golfClubId">The golf club identifier.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <RequestClubMembershipResponse> RequestClubMembership(String accessToken, Guid playerId, Guid golfClubId, CancellationToken cancellationToken) { RequestClubMembershipResponse response = null; String requestUri = $"{this.BaseAddress}/api/golfclubs/{golfClubId}/players/{playerId}"; try { StringContent httpContent = new StringContent(string.Empty, 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 <RequestClubMembershipResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception("Error requesting Golf Club membership.", ex); throw exception; } return(response); }
public async Task PlayerClient_RequestClubMembership_MembershipRequested() { // 1. Arrange HttpClient client = this.WebApplicationFactory.AddPlayer().CreateClient(); Func <String, String> resolver = api => "http://localhost"; IPlayerClient playerClient = new PlayerClient(resolver, client); String token = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImVhZDQyNGJjNjI5MzU0NGM4MGFmZThhMDk2MzEyNjU2IiwidHlwIjoiSldUIn0.eyJuYmYiOjE1NzAyODk3MDksImV4cCI6MTU3MDI5MzMwOSwiaXNzIjoiaHR0cDovLzE5Mi4xNjguMS4xMzI6NTAwMSIsImF1ZCI6WyJodHRwOi8vMTkyLjE2OC4xLjEzMjo1MDAxL3Jlc291cmNlcyIsIm1hbmFnZW1lbnRhcGkiLCJzZWN1cmlydHlzZXJ2aWNlYXBpIl0sImNsaWVudF9pZCI6ImdvbGZoYW5kaWNhcC50ZXN0ZGF0YWdlbmVyYXRvciIsInNjb3BlIjpbIm1hbmFnZW1lbnRhcGkiLCJzZWN1cmlydHlzZXJ2aWNlYXBpIl19.vLfs2bOMXshW93nw5TTOqd6NPGNYpcrhcom8yZoYc9WGSuYH48VqM5BdbodEukNNJmgbV9wUVgoj1uGztlFfHGFA_q6IQfd3xZln_LIxju6ZNZs8qUyRXDTGxu0dlfF8STLfBUq469SsY9eNi1hBYFyNxl963OfKqDSHAdeBg9yNlwnbky1Tnsxobu9W33fLcjH0KoutlwTFV51UFUEKCBk0w1zsjaDVZacETn74t56y0CvMS7ZSN2_yyunq4JvoUsh3xM5lQ-gl23eQyo6l4QE4wukCS7U_Zr2dg8-EF63VKiCH-ZD49M76TD9kIIge-XIgHqa2Xf3S-FpLxXfEqw"; // 2. Act RequestClubMembershipResponse requestClubMembershipResponse = await playerClient.RequestClubMembership(token, TestData.PlayerId, TestData.GolfClubId, CancellationToken.None); // 3. Assert requestClubMembershipResponse.PlayerId.ShouldBe(TestData.PlayerId); requestClubMembershipResponse.GolfClubId.ShouldBe(TestData.GolfClubId); requestClubMembershipResponse.MembershipId.ShouldBe(Guid.Empty); }