Example #1
0
        public async Task GolfClubController_POST_AddMeasuredCourseToGolfClub_MeasuredCourseIdIsReturned()
        {
            // 1. Arrange
            HttpClient client = this.WebApplicationFactory.CreateClient();

            AddMeasuredCourseToClubRequest addMeasuredCourseToClubRequest = TestData.AddMeasuredCourseToClubRequest;
            String uri = $"api/golfclubs/{TestData.GolfClubId}/measuredcourses";

            client.DefaultRequestHeaders.Add("api-version", "2.0");
            StringContent content = Helpers.CreateStringContent(addMeasuredCourseToClubRequest);

            // 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();

            AddMeasuredCourseToClubResponse responseObject = JsonConvert.DeserializeObject <AddMeasuredCourseToClubResponse>(responseAsJson);

            responseObject.GolfClubId.ShouldBe(TestData.GolfClubId);
            responseObject.MeasuredCourseId.ShouldNotBe(Guid.Empty);
        }
Example #2
0
        public async Task GolfClubClient_AddMeasuredCourseToGolfClub_MeasuredCourseIsCreated()
        {
            // 1. Arrange
            HttpClient            client         = this.WebApplicationFactory.AddGolfClubAdministrator().CreateClient();
            Func <String, String> resolver       = api => "http://localhost";
            IGolfClubClient       golfClubClient = new GolfClubClient(resolver, client);

            AddMeasuredCourseToClubRequest addMeasuredCourseToClubRequest = TestData.AddMeasuredCourseToClubRequest;

            String token =
                "eyJhbGciOiJSUzI1NiIsImtpZCI6ImVhZDQyNGJjNjI5MzU0NGM4MGFmZThhMDk2MzEyNjU2IiwidHlwIjoiSldUIn0.eyJuYmYiOjE1NzAyODk3MDksImV4cCI6MTU3MDI5MzMwOSwiaXNzIjoiaHR0cDovLzE5Mi4xNjguMS4xMzI6NTAwMSIsImF1ZCI6WyJodHRwOi8vMTkyLjE2OC4xLjEzMjo1MDAxL3Jlc291cmNlcyIsIm1hbmFnZW1lbnRhcGkiLCJzZWN1cmlydHlzZXJ2aWNlYXBpIl0sImNsaWVudF9pZCI6ImdvbGZoYW5kaWNhcC50ZXN0ZGF0YWdlbmVyYXRvciIsInNjb3BlIjpbIm1hbmFnZW1lbnRhcGkiLCJzZWN1cmlydHlzZXJ2aWNlYXBpIl19.vLfs2bOMXshW93nw5TTOqd6NPGNYpcrhcom8yZoYc9WGSuYH48VqM5BdbodEukNNJmgbV9wUVgoj1uGztlFfHGFA_q6IQfd3xZln_LIxju6ZNZs8qUyRXDTGxu0dlfF8STLfBUq469SsY9eNi1hBYFyNxl963OfKqDSHAdeBg9yNlwnbky1Tnsxobu9W33fLcjH0KoutlwTFV51UFUEKCBk0w1zsjaDVZacETn74t56y0CvMS7ZSN2_yyunq4JvoUsh3xM5lQ-gl23eQyo6l4QE4wukCS7U_Zr2dg8-EF63VKiCH-ZD49M76TD9kIIge-XIgHqa2Xf3S-FpLxXfEqw";

            // 2. Act
            AddMeasuredCourseToClubResponse addMeasuredCourseToClubResponse =
                await golfClubClient.AddMeasuredCourseToGolfClub(token, TestData.GolfClubId, addMeasuredCourseToClubRequest, CancellationToken.None);

            // 3. Assert
            addMeasuredCourseToClubResponse.GolfClubId.ShouldBe(TestData.GolfClubId);
            addMeasuredCourseToClubResponse.MeasuredCourseId.ShouldNotBe(Guid.Empty);
        }
        /// <summary>
        /// Adds the measured course to golf club.
        /// </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 <AddMeasuredCourseToClubResponse> AddMeasuredCourseToGolfClub(String accessToken,
                                                                                        Guid golfClubId,
                                                                                        AddMeasuredCourseToClubRequest request,
                                                                                        CancellationToken cancellationToken)
        {
            AddMeasuredCourseToClubResponse response = null;

            String requestUri = $"{this.BaseAddress}/api/golfclubs/{golfClubId}/measuredcourses";

            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 <AddMeasuredCourseToClubResponse>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception("Error Adding a measured course to Golf Club.", ex);

                throw exception;
            }

            return(response);
        }