public async Task GolfClubController_GET_GetGolfClub_IncludeMembers_GolfClubIsReturned() { // 1. Arrange HttpClient client = this.WebApplicationFactory.AddGolfClubAdministrator().CreateClient(); CreateGolfClubRequest createGolfClubRequest = TestData.CreateGolfClubRequest; String uri = $"api/golfclubs/{TestData.GolfClubId.ToString()}?includeMembers=true"; client.DefaultRequestHeaders.Add("api-version", "2.0"); // 2. Act HttpResponseMessage response = await client.GetAsync(uri, CancellationToken.None); // 3. Assert response.StatusCode.ShouldBe(HttpStatusCode.OK); String responseAsJson = await response.Content.ReadAsStringAsync(); responseAsJson.ShouldNotBeNullOrEmpty(); GetGolfClubResponse responseObject = JsonConvert.DeserializeObject <GetGolfClubResponse>(responseAsJson); responseObject.ShouldNotBeNull(); responseObject.Id.ShouldBe(TestData.GolfClubId); responseObject.GolfClubMembershipDetailsResponseList.ShouldNotBeNull(); responseObject.MeasuredCourses.ShouldBeNull(); responseObject.Users.ShouldBeNull(); }
public async Task GolfClubController_GET_GetGolfClubList_GolfClubIsReturned() { // 1. Arrange HttpClient client = this.WebApplicationFactory.CreateClient(); CreateGolfClubRequest createGolfClubRequest = TestData.CreateGolfClubRequest; String uri = $"api/golfclubs"; client.DefaultRequestHeaders.Add("api-version", "2.0"); // 2. Act HttpResponseMessage response = await client.GetAsync(uri, CancellationToken.None); // 3. Assert response.StatusCode.ShouldBe(HttpStatusCode.OK); String responseAsJson = await response.Content.ReadAsStringAsync(); responseAsJson.ShouldNotBeNullOrEmpty(); List <GetGolfClubResponse> responseObject = JsonConvert.DeserializeObject <List <GetGolfClubResponse> >(responseAsJson); responseObject.ShouldNotBeNull(); responseObject.ShouldNotBeEmpty(); }
public async Task GolfClubController_POST_CreateGolfClub_GolfClubIdIsReturned() { // 1. Arrange HttpClient client = this.WebApplicationFactory.AddGolfClubAdministrator().CreateClient(); CreateGolfClubRequest createGolfClubRequest = TestData.CreateGolfClubRequest; String uri = "api/golfclubs/"; StringContent content = Helpers.CreateStringContent(createGolfClubRequest); 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(); CreateGolfClubResponse responseObject = JsonConvert.DeserializeObject <CreateGolfClubResponse>(responseAsJson); responseObject.ShouldNotBeNull(); responseObject.GolfClubId.ShouldBe(TestData.GolfClubId); }
public async Task <IActionResult> CreateGolfClub([FromBody] CreateGolfClubRequest request, CancellationToken cancellationToken) { if (ClaimsHelper.IsPasswordToken(this.User) == false) { return(this.Forbid()); } // Get the user id (subject) for the user Claim subjectIdClaim = ClaimsHelper.GetUserClaim(this.User, JwtClaimTypes.Subject); // Get the Golf Club Id claim from the user Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId); Guid golfClubId = Guid.Parse(golfClubIdClaim.Value); Guid securityUserId = Guid.Parse(subjectIdClaim.Value); // Create the command CreateGolfClubCommand command = CreateGolfClubCommand.Create(golfClubId, securityUserId, request); // Route the command await this.CommandRouter.Route(command, cancellationToken); // return the result return(this.Created($"{GolfClubController.ControllerRoute}/{golfClubId}", new CreateGolfClubResponsev2 { GolfClubId = golfClubId })); }
public async Task WhenICreateAGolfClubWithTheFollowingDetails(Table table) { TableRow tableRow = table.Rows.Single(); CreateGolfClubRequest createGolfClubRequest = new CreateGolfClubRequest { EmailAddress = tableRow["EmailAddress"], AddressLine1 = tableRow["AddressLine1"], AddressLine2 = tableRow["AddressLine2"], Name = tableRow["GolfClubName"], PostalCode = tableRow["PostalCode"], Region = tableRow["Region"], TelephoneNumber = tableRow["TelephoneNumber"], Town = tableRow["Town"], Website = tableRow["WebSite"], }; this.TestingContext.CreateGolfClubRequest = createGolfClubRequest; this.TestingContext.CreateGolfClubResponse = await this.TestingContext.DockerHelper.GolfClubClient.CreateGolfClub(this.TestingContext.GolfClubAdministratorToken, createGolfClubRequest, CancellationToken.None).ConfigureAwait(false); this.TestingContext.CreateGolfClubResponses.Add(tableRow["GolfClubNumber"], this.TestingContext.CreateGolfClubResponse); }
/// <summary> /// Creates the golf club. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="viewModel">The view model.</param> /// <param name="cancellationToken">The cancellation token.</param> public async Task CreateGolfClub(String accessToken, CreateGolfClubViewModel viewModel, CancellationToken cancellationToken) { // Translate view model to request CreateGolfClubRequest createGolfClubRequest = this.ModelFactory.ConvertFrom(viewModel); await this.GolfClubClient.CreateGolfClub(accessToken, createGolfClubRequest, cancellationToken); }
/// <summary> /// Converts from. /// </summary> /// <param name="viewModel">The view model.</param> /// <returns></returns> public CreateGolfClubRequest ConvertFrom(CreateGolfClubViewModel viewModel) { CreateGolfClubRequest createGolfClubRequest = new CreateGolfClubRequest { AddressLine1 = viewModel.AddressLine1, Region = viewModel.Region, Town = viewModel.Town, Website = viewModel.Website, Name = viewModel.Name, TelephoneNumber = viewModel.TelephoneNumber, EmailAddress = viewModel.EmailAddress, AddressLine2 = viewModel.AddressLine2, PostalCode = viewModel.PostalCode, TournamentDivisions = new List <TournamentDivisionRequest>() }; return(createGolfClubRequest); }
public async Task GolfClubClient_CreateGolfClub_GolfClubIsCreated() { // 1. Arrange HttpClient client = this.WebApplicationFactory.AddGolfClubAdministrator().CreateClient(); Func <String, String> resolver = api => "http://localhost"; IGolfClubClient golfClubClient = new GolfClubClient(resolver, client); CreateGolfClubRequest createGolfClubRequest = TestData.CreateGolfClubRequest; String token = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImVhZDQyNGJjNjI5MzU0NGM4MGFmZThhMDk2MzEyNjU2IiwidHlwIjoiSldUIn0.eyJuYmYiOjE1NzAyODk3MDksImV4cCI6MTU3MDI5MzMwOSwiaXNzIjoiaHR0cDovLzE5Mi4xNjguMS4xMzI6NTAwMSIsImF1ZCI6WyJodHRwOi8vMTkyLjE2OC4xLjEzMjo1MDAxL3Jlc291cmNlcyIsIm1hbmFnZW1lbnRhcGkiLCJzZWN1cmlydHlzZXJ2aWNlYXBpIl0sImNsaWVudF9pZCI6ImdvbGZoYW5kaWNhcC50ZXN0ZGF0YWdlbmVyYXRvciIsInNjb3BlIjpbIm1hbmFnZW1lbnRhcGkiLCJzZWN1cmlydHlzZXJ2aWNlYXBpIl19.vLfs2bOMXshW93nw5TTOqd6NPGNYpcrhcom8yZoYc9WGSuYH48VqM5BdbodEukNNJmgbV9wUVgoj1uGztlFfHGFA_q6IQfd3xZln_LIxju6ZNZs8qUyRXDTGxu0dlfF8STLfBUq469SsY9eNi1hBYFyNxl963OfKqDSHAdeBg9yNlwnbky1Tnsxobu9W33fLcjH0KoutlwTFV51UFUEKCBk0w1zsjaDVZacETn74t56y0CvMS7ZSN2_yyunq4JvoUsh3xM5lQ-gl23eQyo6l4QE4wukCS7U_Zr2dg8-EF63VKiCH-ZD49M76TD9kIIge-XIgHqa2Xf3S-FpLxXfEqw"; // 2. Act CreateGolfClubResponse createGolfClubResponse = await golfClubClient.CreateGolfClub(token, createGolfClubRequest, CancellationToken.None); // 3. Assert createGolfClubResponse.GolfClubId.ShouldBe(TestData.GolfClubId); }
public void ModelFactory_ConvertFrom_CreateGolfClubViewModel_ConvertedSuccessfully() { ModelFactory factory = new ModelFactory(); CreateGolfClubViewModel viewModel = ModelFactoryTestData.GetCreateGolfClubViewModel(); CreateGolfClubRequest request = factory.ConvertFrom(viewModel); request.AddressLine1.ShouldBe(viewModel.AddressLine1); request.Region.ShouldBe(viewModel.Region); request.Town.ShouldBe(viewModel.Town); request.Website.ShouldBe(viewModel.Website); request.Name.ShouldBe(viewModel.Name); request.TelephoneNumber.ShouldBe(viewModel.TelephoneNumber); request.EmailAddress.ShouldBe(viewModel.EmailAddress); request.AddressLine2.ShouldBe(viewModel.AddressLine2); request.PostalCode.ShouldBe(viewModel.PostalCode); request.TournamentDivisions.ShouldBeEmpty(); }
public async Task <IActionResult> CreateGolfClub([FromBody] CreateGolfClubRequest request, CancellationToken cancellationToken) { if (ClaimsHelper.IsPasswordToken(this.User) == false) { return(this.Forbid()); } // Get the user id (subject) for the user Claim subjectIdClaim = ClaimsHelper.GetUserClaim(this.User, JwtClaimTypes.Subject, null); // Get the Golf Club Id claim from the user Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId); // Create the command CreateGolfClubCommand command = CreateGolfClubCommand.Create(Guid.Parse(golfClubIdClaim.Value), Guid.Parse(subjectIdClaim.Value), request); // Route the command await this.CommandRouter.Route(command, cancellationToken); // return the result return(this.Created($"api/golfclub/{command.Response}", command.Response)); }
public async Task GivenTheFollowingGolfClubsExist(Table table) { foreach (TableRow tableRow in table.Rows) { RegisterClubAdministratorRequest registerClubAdministratorRequest = this.TestingContext.GetRegisterClubAdministratorRequest(tableRow["GolfClubNumber"]); this.TestingContext.GolfClubAdministratorToken = await this.TestingContext.DockerHelper.GetToken(TokenType.Password, "golfhandicap.mobile", "golfhandicap.mobile", registerClubAdministratorRequest.EmailAddress, registerClubAdministratorRequest.Password).ConfigureAwait(false); ; CreateGolfClubRequest createGolfClubRequest = new CreateGolfClubRequest { AddressLine1 = tableRow["AddressLine1"], EmailAddress = tableRow["EmailAddress"], TelephoneNumber = tableRow["TelephoneNumber"], Name = tableRow["GolfClubName"], AddressLine2 = tableRow["AddressLine2"], PostalCode = tableRow["PostalCode"], Region = tableRow["Region"], Town = tableRow["Town"], Website = tableRow["WebSite"] }; this.TestingContext.CreateGolfClubRequests.Add(tableRow["GolfClubNumber"], createGolfClubRequest); CreateGolfClubResponse createGolfClubResponse = await this.TestingContext.DockerHelper.GolfClubClient.CreateGolfClub(this.TestingContext.GolfClubAdministratorToken, createGolfClubRequest, CancellationToken.None).ConfigureAwait(false); this.TestingContext.CreateGolfClubResponses.Add(tableRow["GolfClubNumber"], createGolfClubResponse); } }
/// <summary> /// Creates the golf club. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="request">The request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <CreateGolfClubResponse> CreateGolfClub(String accessToken, CreateGolfClubRequest request, CancellationToken cancellationToken) { CreateGolfClubResponse response = null; String requestUri = $"{this.BaseAddress}/api/golfclubs"; 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 <CreateGolfClubResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception($"Error creating the new golf club {request.Name}.", ex); throw exception; } return(response); }
/// <summary> /// Creates the golf club datav2. /// </summary> /// <param name="testDataGenerator">The test data generator.</param> /// <param name="numberOfGolfClubs">The number of golf clubs.</param> /// <param name="lastClubCount">The last club count.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private static async Task CreateGolfClubDatav2(ITestDataGenerator testDataGenerator, Int32 numberOfGolfClubs, Int32 lastClubCount, CancellationToken cancellationToken) { List <Task> tasks = new List <Task>(); Int32 startIndex = 0 + lastClubCount; Int32 endIndex = numberOfGolfClubs + lastClubCount; for (Int32 i = startIndex; i < endIndex; i++) { RegisterClubAdministratorRequest registerClubAdministratorRequest = new RegisterClubAdministratorRequest { EmailAddress = $"clubadministrator@testgolfclub{i}.co.uk", ConfirmPassword = "******", Password = "******", TelephoneNumber = "1234567890", FamilyName = $"Admin {i}", GivenName = "Club" }; await testDataGenerator.RegisterGolfClubAdministrator(registerClubAdministratorRequest, cancellationToken); String clubAdministratorToken = await testDataGenerator.GetToken(TokenType.Password, "developerClient", "developerClient", registerClubAdministratorRequest.EmailAddress, registerClubAdministratorRequest.Password, new List <String> { "openid", "profile", "managementapi" }); CreateGolfClubRequest createGolfClubRequest = new CreateGolfClubRequest { AddressLine1 = "Address Line 1", AddressLine2 = "Address Line 2", EmailAddress = $"contactus@testgolfclub{i}.co.uk", TelephoneNumber = "1234567890", Name = $"Test Golf Club {i}", PostalCode = "TE57 1NG", Region = "TestRegion", Town = "TestTown", Website = string.Empty }; CreateGolfClubResponse createGolfClubResponse = await testDataGenerator.CreateGolfClub(clubAdministratorToken, createGolfClubRequest, cancellationToken); await testDataGenerator.AddMeasuredCourseToGolfClub(Program.accessToken, createGolfClubResponse.GolfClubId, Program.AddMeasuredCourseToClubRequest, cancellationToken); AddTournamentDivisionToGolfClubRequest division1 = new AddTournamentDivisionToGolfClubRequest { Division = 1, StartHandicap = -10, EndHandicap = 7 }; await testDataGenerator.AddTournamentDivision(Program.accessToken, createGolfClubResponse.GolfClubId, division1, cancellationToken); AddTournamentDivisionToGolfClubRequest division2 = new AddTournamentDivisionToGolfClubRequest { Division = 2, StartHandicap = 6, EndHandicap = 12 }; await testDataGenerator.AddTournamentDivision(Program.accessToken, createGolfClubResponse.GolfClubId, division2, cancellationToken); AddTournamentDivisionToGolfClubRequest division3 = new AddTournamentDivisionToGolfClubRequest { Division = 3, StartHandicap = 13, EndHandicap = 21 }; await testDataGenerator.AddTournamentDivision(Program.accessToken, createGolfClubResponse.GolfClubId, division3, cancellationToken); AddTournamentDivisionToGolfClubRequest division4 = new AddTournamentDivisionToGolfClubRequest { Division = 4, StartHandicap = 22, EndHandicap = 28 }; await testDataGenerator.AddTournamentDivision(Program.accessToken, createGolfClubResponse.GolfClubId, division4, cancellationToken); Program.GolfClubs.Add(new GolfClubDetails { AdminEmailAddress = registerClubAdministratorRequest.EmailAddress, AdminPassword = registerClubAdministratorRequest.Password, GolfClubId = createGolfClubResponse.GolfClubId, MeasuredCourseId = Program.AddMeasuredCourseToClubRequest.MeasuredCourseId, GolfClubName = createGolfClubRequest.Name }); } }
/// <summary> /// Creates this instance. /// </summary> /// <param name="golfClubId">The golf club identifier.</param> /// <param name="securityUserId">The security user identifier.</param> /// <param name="createGolfClubRequest">The create golf club request.</param> /// <returns></returns> public static CreateGolfClubCommand Create(Guid golfClubId, Guid securityUserId, CreateGolfClubRequest createGolfClubRequest) { return(new CreateGolfClubCommand(golfClubId, securityUserId, createGolfClubRequest, Guid.NewGuid())); }
/// <summary> /// Initializes a new instance of the <see cref="CreateGolfClubCommand" /> class. /// </summary> /// <param name="golfClubId">The golf club identifier.</param> /// <param name="securityUserId">The security user identifier.</param> /// <param name="createGolfClubRequest">The create golf club request.</param> /// <param name="commandId">The command identifier.</param> private CreateGolfClubCommand(Guid golfClubId, Guid securityUserId, CreateGolfClubRequest createGolfClubRequest, Guid commandId) : base(commandId) { this.GolfClubId = golfClubId; this.CreateGolfClubRequest = createGolfClubRequest; this.SecurityUserId = securityUserId; }
/// <summary> /// Creates the golf club. /// </summary> /// <param name="accessToken">The password token.</param> /// <param name="createGolfClubRequest">The create golf club request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <CreateGolfClubResponse> CreateGolfClub(String accessToken, CreateGolfClubRequest createGolfClubRequest, CancellationToken cancellationToken) { return(await this.GolfClubClient.CreateGolfClub(accessToken, createGolfClubRequest, cancellationToken)); }