/// <summary>
        /// Registers the golf club administrator.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <RegisterClubAdministratorResponse> RegisterGolfClubAdministrator(RegisterClubAdministratorRequest request,
                                                                                            CancellationToken cancellationToken)
        {
            RegisterClubAdministratorResponse response = null;

            String requestUri = $"{this.BaseAddress}/api/golfclubadministrators";

            try
            {
                String requestSerialised = JsonConvert.SerializeObject(request);

                StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");

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

                throw exception;
            }

            return(response);
        }
        public async Task GolfClubAdministratorController_POST_GolfClubAdministrator_GolfClubAdministratorIsReturned()
        {
            // 1. Arrange
            HttpClient client = this.WebApplicationFactory.CreateClient();

            RegisterClubAdministratorRequest registerClubAdministratorRequest = TestData.RegisterClubAdministratorRequest;
            String        uri     = "api/golfclubadministrators/";
            StringContent content = Helpers.CreateStringContent(registerClubAdministratorRequest);

            client.DefaultRequestHeaders.Add("api-version", "2.0");
            // 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();

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

            responseObject.ShouldNotBeNull();
            responseObject.GolfClubAdministratorId.ShouldBe(TestData.GolfClubAdministratorUserId);
        }
Exemple #3
0
        public async Task GolfClubAdministratorClient_RegisterGolfClubAdministrator_GolfClubAdministratorIsCreated()
        {
            // 1. Arrange
            HttpClient                   client   = this.WebApplicationFactory.CreateClient();
            Func <String, String>        resolver = api => "http://localhost";
            IGolfClubAdministratorClient golfClubAdministratorClient = new GolfClubAdministratorClient(resolver, client);

            RegisterClubAdministratorRequest registerClubAdministratorRequest = TestData.RegisterClubAdministratorRequest;

            // 2. Act
            RegisterClubAdministratorResponse registerClubAdministratorResponse = await golfClubAdministratorClient.RegisterGolfClubAdministrator(registerClubAdministratorRequest, CancellationToken.None);

            // 3. Assert
            registerClubAdministratorResponse.GolfClubAdministratorId.ShouldBe(TestData.GolfClubAdministratorUserId);
        }