public async Task GolfClubController_POST_CreateMatchSecretary_MatchSecretaryIsReturned() { // 1. Arrange HttpClient client = this.WebApplicationFactory.AddGolfClubAdministrator().CreateClient(); CreateMatchSecretaryRequest createMatchSecretaryRequest = TestData.CreateMatchSecretaryRequest; String uri = $"api/golfclubs/{TestData.GolfClubId}/users"; client.DefaultRequestHeaders.Add("api-version", "2.0"); StringContent content = Helpers.CreateStringContent(createMatchSecretaryRequest); // 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(); CreateMatchSecretaryResponse responseObject = JsonConvert.DeserializeObject <CreateMatchSecretaryResponse>(responseAsJson); responseObject.GolfClubId.ShouldBe(TestData.GolfClubId); responseObject.UserName.ShouldNotBeNullOrEmpty(); }
public async Task GolfClubClient_CreateMatchSecretary_MatchSecretaryIsCreated() { // 1. Arrange HttpClient client = this.WebApplicationFactory.AddGolfClubAdministrator().CreateClient(); Func <String, String> resolver = api => "http://localhost"; IGolfClubClient golfClubClient = new GolfClubClient(resolver, client); CreateMatchSecretaryRequest createMatchSecretaryRequest = TestData.CreateMatchSecretaryRequest; String token = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImVhZDQyNGJjNjI5MzU0NGM4MGFmZThhMDk2MzEyNjU2IiwidHlwIjoiSldUIn0.eyJuYmYiOjE1NzAyODk3MDksImV4cCI6MTU3MDI5MzMwOSwiaXNzIjoiaHR0cDovLzE5Mi4xNjguMS4xMzI6NTAwMSIsImF1ZCI6WyJodHRwOi8vMTkyLjE2OC4xLjEzMjo1MDAxL3Jlc291cmNlcyIsIm1hbmFnZW1lbnRhcGkiLCJzZWN1cmlydHlzZXJ2aWNlYXBpIl0sImNsaWVudF9pZCI6ImdvbGZoYW5kaWNhcC50ZXN0ZGF0YWdlbmVyYXRvciIsInNjb3BlIjpbIm1hbmFnZW1lbnRhcGkiLCJzZWN1cmlydHlzZXJ2aWNlYXBpIl19.vLfs2bOMXshW93nw5TTOqd6NPGNYpcrhcom8yZoYc9WGSuYH48VqM5BdbodEukNNJmgbV9wUVgoj1uGztlFfHGFA_q6IQfd3xZln_LIxju6ZNZs8qUyRXDTGxu0dlfF8STLfBUq469SsY9eNi1hBYFyNxl963OfKqDSHAdeBg9yNlwnbky1Tnsxobu9W33fLcjH0KoutlwTFV51UFUEKCBk0w1zsjaDVZacETn74t56y0CvMS7ZSN2_yyunq4JvoUsh3xM5lQ-gl23eQyo6l4QE4wukCS7U_Zr2dg8-EF63VKiCH-ZD49M76TD9kIIge-XIgHqa2Xf3S-FpLxXfEqw"; // 2. Act CreateMatchSecretaryResponse createMatchSecretaryResponse = await golfClubClient.CreateMatchSecretary(token, TestData.GolfClubId, createMatchSecretaryRequest, CancellationToken.None); // 3. Assert createMatchSecretaryResponse.GolfClubId.ShouldBe(TestData.GolfClubId); createMatchSecretaryResponse.UserName.ShouldBe(createMatchSecretaryRequest.EmailAddress); }
/// <summary> /// Creates the match secretary. /// </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 <CreateMatchSecretaryResponse> CreateMatchSecretary(String accessToken, Guid golfClubId, CreateMatchSecretaryRequest request, CancellationToken cancellationToken) { CreateMatchSecretaryResponse response = null; String requestUri = $"{this.BaseAddress}/api/golfclubs/{golfClubId}/users"; 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 <CreateMatchSecretaryResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception("Error creating the new match secretary.", ex); throw exception; } return(response); }