示例#1
0
        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 <IActionResult> CreateMatchSecretary([FromRoute] Guid golfClubId,
                                                               [FromBody] CreateMatchSecretaryRequest request,
                                                               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());
            }

            CreateMatchSecretaryCommand command = CreateMatchSecretaryCommand.Create(Guid.Parse(golfClubIdClaim.Value), request);

            await this.CommandRouter.Route(command, cancellationToken);

            // return the result
            return(this.Created($"{GolfClubController.ControllerRoute}/{golfClubId}/users/{request.EmailAddress}",
                                new CreateMatchSecretaryResponse
            {
                GolfClubId = golfClubId,
                UserName = request.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 CreateMatchSecretary(String accessToken,
                                               Guid golfClubId,
                                               CreateMatchSecretaryRequest request,
                                               CancellationToken cancellationToken)
        {
            String requestUri = $"{this.BaseAddress}/api/GolfClub/{golfClubId}/CreateMatchSecretary";

            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.PutAsync(requestUri, httpContent, cancellationToken);

                // Process the response
                String content = await this.HandleResponse(httpResponse, cancellationToken);

                // call was successful, no response data to deserialise
            }
            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;
            }
        }
示例#4
0
        /// <summary>
        /// Creates the match secretary.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="claimsIdentity">The claims identity.</param>
        /// <param name="viewModel">The view model.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public async Task CreateMatchSecretary(String accessToken,
                                               ClaimsIdentity claimsIdentity,
                                               CreateGolfClubUserViewModel viewModel,
                                               CancellationToken cancellationToken)
        {
            CreateMatchSecretaryRequest createMatchSecretaryRequest = this.ModelFactory.ConvertFrom(viewModel);

            Guid golfClubId = ApiClient.GetClaimValue <Guid>(claimsIdentity, "GolfClubId");

            await this.GolfClubClient.CreateMatchSecretary(accessToken, golfClubId, createMatchSecretaryRequest, cancellationToken);
        }
示例#5
0
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <returns></returns>
        public CreateMatchSecretaryRequest ConvertFrom(CreateGolfClubUserViewModel viewModel)
        {
            CreateMatchSecretaryRequest request = new CreateMatchSecretaryRequest
            {
                ConfirmPassword = "******",
                GivenName       = viewModel.GivenName,
                FamilyName      = viewModel.FamilyName,
                MiddleName      = viewModel.MiddleName,
                EmailAddress    = viewModel.Email,
                Password        = "******",
                TelephoneNumber = viewModel.TelephoneNumber
            };

            return(request);
        }
        public void ModelFactory_ConvertFrom_CreateGolfClubUserViewModel_ConvertedSuccessfully()
        {
            ModelFactory factory = new ModelFactory();

            CreateGolfClubUserViewModel viewModel = ModelFactoryTestData.GetCreateGolfClubUserViewModel();

            CreateMatchSecretaryRequest apiRequest = factory.ConvertFrom(viewModel);

            apiRequest.MiddleName.ShouldBe(viewModel.MiddleName);
            apiRequest.ConfirmPassword.ShouldBe(ModelFactoryTestData.ConfirmPassword);
            apiRequest.EmailAddress.ShouldBe(viewModel.Email);
            apiRequest.FamilyName.ShouldBe(viewModel.FamilyName);
            apiRequest.GivenName.ShouldBe(viewModel.GivenName);
            apiRequest.Password.ShouldBe(ModelFactoryTestData.Password);
            apiRequest.TelephoneNumber.ShouldBe(viewModel.TelephoneNumber);
        }
        public void WhenIRegisterTheFollowingDetailsForAMatchSecretary(Table table)
        {
            TableRow tableRow = table.Rows.Single();

            this.TestingContext.CreateGolfClubResponse = this.TestingContext.GetCreateGolfClubResponse(tableRow["GolfClubNumber"]);

            CreateMatchSecretaryRequest createMatchSecretaryRequest = new CreateMatchSecretaryRequest
            {
                ConfirmPassword = tableRow["ConfirmPassword"],
                FamilyName      = tableRow["FamilyName"],
                GivenName       = tableRow["GivenName"],
                MiddleName      = tableRow["MiddleName"],
                EmailAddress    = tableRow["EmailAddress"],
                TelephoneNumber = tableRow["TelephoneNumber"],
                Password        = tableRow["Password"]
            };

            this.TestingContext.CreateMatchSecretaryRequest = createMatchSecretaryRequest;
        }
示例#8
0
        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);
        }
        public async Task <IActionResult> CreateMatchSecretary([FromRoute] Guid golfClubId,
                                                               [FromBody] CreateMatchSecretaryRequest request,
                                                               CancellationToken cancellationToken)
        {
            // Get the Golf Club Id claim from the user
            Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId);

            Boolean validationResult = ClaimsHelper.ValidateRouteParameter(golfClubId, golfClubIdClaim);

            if (validationResult == false)
            {
                return(this.Forbid());
            }

            CreateMatchSecretaryCommand command = CreateMatchSecretaryCommand.Create(Guid.Parse(golfClubIdClaim.Value), request);

            await this.CommandRouter.Route(command, cancellationToken);

            return(this.NoContent());
        }
 /// <summary>
 /// Creates this instance.
 /// </summary>
 /// <param name="golfClubId">The golf club identifier.</param>
 /// <param name="createMatchSecretaryRequest">The create match secretary request.</param>
 /// <returns></returns>
 public static CreateMatchSecretaryCommand Create(Guid golfClubId, CreateMatchSecretaryRequest createMatchSecretaryRequest)
 {
     return(new CreateMatchSecretaryCommand(golfClubId, createMatchSecretaryRequest, Guid.NewGuid()));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateMatchSecretaryCommand" /> class.
 /// </summary>
 /// <param name="golfClubId">The golf club identifier.</param>
 /// <param name="createMatchSecretaryRequest">The create match secretary request.</param>
 /// <param name="commandId">The command identifier.</param>
 private CreateMatchSecretaryCommand(Guid golfClubId, CreateMatchSecretaryRequest createMatchSecretaryRequest, Guid commandId) : base(commandId)
 {
     this.GolfClubId = golfClubId;
     this.CreateMatchSecretaryRequest = createMatchSecretaryRequest;
 }