public async Task <GetMembersHandicapListReportResponse> GetMembersHandicapListReport(String accessToken, Guid golfClubId, CancellationToken cancellationToken) { GetMembersHandicapListReportResponse response = null; String requestUri = $"{this.BaseAddress}/api/Reporting/GolfClub/{golfClubId}/membershandicaplist"; try { // 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.GetAsync(requestUri, 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 <GetMembersHandicapListReportResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception($"Error getting members handicap list report for Golf Club {golfClubId}.", ex); throw exception; } return(response); }
public async Task <IActionResult> GetMemberHandicapList(Guid golfClubId, CancellationToken cancellationToken) { GetMembersHandicapListReportResponse response = await this.ReportingManager.GetMembersHandicapListReport(golfClubId, cancellationToken); return(this.Ok(response)); }
public async Task ReportingController_GET_GetMemberHandicapList_MemberHandicapListReturned() { // 1. Arrange HttpClient client = this.WebApplicationFactory.CreateClient(); String uri = $"api/reports/golfclubs/{TestData.GolfClubId}/membershandicaplist"; 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(); GetMembersHandicapListReportResponse responseObject = JsonConvert.DeserializeObject <GetMembersHandicapListReportResponse>(responseAsJson); responseObject.ShouldNotBeNull(); responseObject.GolfClubId.ShouldBe(TestData.GolfClubId); responseObject.MembersHandicapListReportResponse.ShouldNotBeNull(); responseObject.MembersHandicapListReportResponse.ShouldNotBeEmpty(); }
public async Task ReportingManager_GetMembersHandicapListReport_NoMembers_ReportDataReturned() { String databaseName = Guid.NewGuid().ToString("N"); ManagementAPIReadModel context = this.GetContext(databaseName); List <PlayerHandicapListReporting> reportingData = new List <PlayerHandicapListReporting>(); Func <ManagementAPIReadModel> contextResolver = () => { return(context); }; ReportingManager reportingManager = new ReportingManager(contextResolver); GetMembersHandicapListReportResponse reportData = await reportingManager.GetMembersHandicapListReport(GolfClubTestData.AggregateId, CancellationToken.None); reportData.GolfClubId.ShouldBe(GolfClubTestData.AggregateId); reportData.MembersHandicapListReportResponse.Count.ShouldBe(reportingData.Count); }
public async Task ReportingClient_GetMembersHandicapListReport_ReportDataReturned() { // 1. Arrange HttpClient client = this.WebApplicationFactory.AddGolfClubAdministrator().CreateClient(); Func <String, String> resolver = api => "http://localhost"; IReportingClient reportingClient = new ReportingClient(resolver, client); String token = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImVhZDQyNGJjNjI5MzU0NGM4MGFmZThhMDk2MzEyNjU2IiwidHlwIjoiSldUIn0.eyJuYmYiOjE1NzAyODk3MDksImV4cCI6MTU3MDI5MzMwOSwiaXNzIjoiaHR0cDovLzE5Mi4xNjguMS4xMzI6NTAwMSIsImF1ZCI6WyJodHRwOi8vMTkyLjE2OC4xLjEzMjo1MDAxL3Jlc291cmNlcyIsIm1hbmFnZW1lbnRhcGkiLCJzZWN1cmlydHlzZXJ2aWNlYXBpIl0sImNsaWVudF9pZCI6ImdvbGZoYW5kaWNhcC50ZXN0ZGF0YWdlbmVyYXRvciIsInNjb3BlIjpbIm1hbmFnZW1lbnRhcGkiLCJzZWN1cmlydHlzZXJ2aWNlYXBpIl19.vLfs2bOMXshW93nw5TTOqd6NPGNYpcrhcom8yZoYc9WGSuYH48VqM5BdbodEukNNJmgbV9wUVgoj1uGztlFfHGFA_q6IQfd3xZln_LIxju6ZNZs8qUyRXDTGxu0dlfF8STLfBUq469SsY9eNi1hBYFyNxl963OfKqDSHAdeBg9yNlwnbky1Tnsxobu9W33fLcjH0KoutlwTFV51UFUEKCBk0w1zsjaDVZacETn74t56y0CvMS7ZSN2_yyunq4JvoUsh3xM5lQ-gl23eQyo6l4QE4wukCS7U_Zr2dg8-EF63VKiCH-ZD49M76TD9kIIge-XIgHqa2Xf3S-FpLxXfEqw"; // 2. Act GetMembersHandicapListReportResponse getMembersHandicapListReport = await reportingClient.GetMembersHandicapListReport(token, TestData.PlayerId, CancellationToken.None); // 3. Assert getMembersHandicapListReport.GolfClubId.ShouldBe(TestData.GolfClubId); getMembersHandicapListReport.MembersHandicapListReportResponse.ShouldNotBeEmpty(); }
public async Task ReportingManager_GetMembersHandicapListReport_ReportDataReturned() { String databaseName = Guid.NewGuid().ToString("N"); ManagementAPIReadModel context = this.GetContext(databaseName); List <PlayerHandicapListReporting> reportingData = new List <PlayerHandicapListReporting>(); reportingData.Add(new PlayerHandicapListReporting { PlayerId = Guid.NewGuid(), GolfClubId = GolfClubTestData.AggregateId, HandicapCategory = 1, PlayerName = "Test Player 1", ExactHandicap = 5.4m, PlayingHandicap = 5 }); reportingData.Add(new PlayerHandicapListReporting { PlayerId = Guid.NewGuid(), GolfClubId = GolfClubTestData.AggregateId, HandicapCategory = 2, PlayerName = "Test Player 2", ExactHandicap = 12.8m, PlayingHandicap = 13 }); await context.PlayerHandicapListReporting.AddRangeAsync(reportingData, CancellationToken.None); await context.SaveChangesAsync(CancellationToken.None); Func <ManagementAPIReadModel> contextResolver = () => { return(context); }; ReportingManager reportingManager = new ReportingManager(contextResolver); GetMembersHandicapListReportResponse reportData = await reportingManager.GetMembersHandicapListReport(GolfClubTestData.AggregateId, CancellationToken.None); reportData.GolfClubId.ShouldBe(GolfClubTestData.AggregateId); reportData.MembersHandicapListReportResponse.ShouldNotBeEmpty(); reportData.MembersHandicapListReportResponse.Count.ShouldBe(reportingData.Count); }
/// <summary> /// Gets the members handicap list report. /// </summary> /// <param name="golfClubId">The golf club identifier.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <GetMembersHandicapListReportResponse> GetMembersHandicapListReport(Guid golfClubId, CancellationToken cancellationToken) { Guard.ThrowIfInvalidGuid(golfClubId, nameof(golfClubId)); GetMembersHandicapListReportResponse response = new GetMembersHandicapListReportResponse(); using (ManagementAPIReadModel context = this.ReadModelResolver()) { List <PlayerHandicapListReporting> reportData = context.PlayerHandicapListReporting.Where(p => p.GolfClubId == golfClubId).ToList(); response.GolfClubId = golfClubId; reportData.ForEach(f => response.MembersHandicapListReportResponse.Add(new MembersHandicapListReportResponse { GolfClubId = f.GolfClubId, PlayerId = f.PlayerId, HandicapCategory = f.HandicapCategory, ExactHandicap = f.ExactHandicap, PlayingHandicap = f.PlayingHandicap, PlayerName = f.PlayerName })); } return(response); }