Пример #1
0
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="apiResponse">The API response.</param>
        /// <returns></returns>
        public ChartJsPieChartDataViewModel ConvertFrom(GetNumberOfMembersByHandicapCategoryReportResponse apiResponse)
        {
            List <Color> chartColors = new List <Color>();

            chartColors = new List <Color>();
            chartColors.Add(Color.Aqua);
            chartColors.Add(Color.YellowGreen);
            chartColors.Add(Color.BlueViolet);
            chartColors.Add(Color.Coral);
            chartColors.Add(Color.CadetBlue);
            chartColors.Add(Color.Crimson);
            chartColors.Add(Color.DeepSkyBlue);

            ChartJsPieChartDataViewModel viewModel = new ChartJsPieChartDataViewModel();

            ChartJsPieChartDataDataSet dataSet = new ChartJsPieChartDataDataSet();

            Int32 counter = 0;

            foreach (MembersByHandicapCategoryResponse membersByHandicapCategoryResponse in apiResponse.MembersByHandicapCategoryResponse)
            {
                Color backgroundColour = chartColors[counter];

                dataSet.BackgroundColor.Add(backgroundColour.ToHex());
                dataSet.Data.Add(membersByHandicapCategoryResponse.NumberOfMembers);
                viewModel.Labels.Add($"Category {membersByHandicapCategoryResponse.HandicapCategory}");
                counter++;
            }
            viewModel.Datasets.Add(dataSet);

            return(viewModel);
        }
Пример #2
0
        /// <summary>
        /// Gets the number of members by handicap category report.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="golfClubId">The golf club identifier.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <GetNumberOfMembersByHandicapCategoryReportResponse> GetNumberOfMembersByHandicapCategoryReport(String accessToken,
                                                                                                                          Guid golfClubId,
                                                                                                                          CancellationToken cancellationToken)
        {
            GetNumberOfMembersByHandicapCategoryReportResponse response = null;
            String requestUri = $"{this.BaseAddress}/api/Reporting/GolfClub/{golfClubId}/numberofmembersbyhandicapcategory";

            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 <GetNumberOfMembersByHandicapCategoryReportResponse>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception($"Error getting number of members by handicap category report for Golf Club {golfClubId}.", ex);

                throw exception;
            }

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

            String uri = $"api/reports/golfclubs/{TestData.GolfClubId}/numberofmembersbyhandicapcategory";

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

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

            responseObject.ShouldNotBeNull();
            responseObject.GolfClubId.ShouldBe(TestData.GolfClubId);
            responseObject.MembersByHandicapCategoryResponse.ShouldNotBeNull();
            responseObject.MembersByHandicapCategoryResponse.ShouldNotBeEmpty();
        }
        public async Task <IActionResult> GetNumberOfMembersByHandicapCategoryReport(Guid golfClubId,
                                                                                     CancellationToken cancellationToken)
        {
            GetNumberOfMembersByHandicapCategoryReportResponse reportData =
                await this.ReportingManager.GetNumberOfMembersByHandicapCategoryReport(golfClubId, cancellationToken);

            return(this.Ok(reportData));
        }
Пример #5
0
        /// <summary>
        /// Gets the number of members by handicap category report.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="claimsIdentity">The claims identity.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <ChartJsPieChartDataViewModel> GetNumberOfMembersByHandicapCategoryReport(String accessToken,
                                                                                                    ClaimsIdentity claimsIdentity,
                                                                                                    CancellationToken cancellationToken)
        {
            Guid golfClubId = ApiClient.GetClaimValue <Guid>(claimsIdentity, "GolfClubId");

            GetNumberOfMembersByHandicapCategoryReportResponse getNumberOfMembersByHandicapCategoryReportResponse = await this.ReportingClient.GetNumberOfMembersByHandicapCategoryReport(accessToken, golfClubId, cancellationToken);

            return(this.ModelFactory.ConvertFrom(getNumberOfMembersByHandicapCategoryReportResponse));
        }
Пример #6
0
        public async Task ReportingManager_GetNumberOfMembersByHandicapCategoryReport_NoMembers_ReportDataReturned()
        {
            String databaseName = Guid.NewGuid().ToString("N");
            ManagementAPIReadModel        context         = this.GetContext(databaseName);
            Func <ManagementAPIReadModel> contextResolver = () => { return(context); };

            ReportingManager reportingManager = new ReportingManager(contextResolver);

            GetNumberOfMembersByHandicapCategoryReportResponse reportData = await reportingManager.GetNumberOfMembersByHandicapCategoryReport(GolfClubTestData.AggregateId, CancellationToken.None);

            reportData.GolfClubId.ShouldBe(GolfClubTestData.AggregateId);
            reportData.MembersByHandicapCategoryResponse.ShouldBeEmpty();
        }
        public void ModelFactory_ConvertFrom_GetNumberOfMembersByHandicapCategoryReportResponse_ConvertedSuccessfully()
        {
            ModelFactory factory = new ModelFactory();

            GetNumberOfMembersByHandicapCategoryReportResponse apiResponse = ModelFactoryTestData.GetNumberOfMembersByHandicapCategoryReportResponse();

            ChartJsPieChartDataViewModel viewModel = factory.ConvertFrom(apiResponse);

            viewModel.Labels.ShouldNotBeEmpty();
            viewModel.Datasets.ShouldNotBeEmpty();
            viewModel.Datasets.Count.ShouldBe(1);
            foreach (MembersByHandicapCategoryResponse membersByHandicapCategoryResponse in apiResponse.MembersByHandicapCategoryResponse)
            {
                viewModel.Labels.ShouldContain($"Category {membersByHandicapCategoryResponse.HandicapCategory}");
                viewModel.Datasets.First().Data.ShouldContain(membersByHandicapCategoryResponse.NumberOfMembers);
            }
        }
        public async Task ReportingClient_GetNumberOfMembersByHandicapCategoryReport_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
            GetNumberOfMembersByHandicapCategoryReportResponse getNumberOfMembersByHandicapCategoryReport =
                await reportingClient.GetNumberOfMembersByHandicapCategoryReport(token, TestData.PlayerId, CancellationToken.None);

            // 3. Assert
            getNumberOfMembersByHandicapCategoryReport.GolfClubId.ShouldBe(TestData.GolfClubId);
            getNumberOfMembersByHandicapCategoryReport.MembersByHandicapCategoryResponse.ShouldNotBeEmpty();
        }
        /// <summary>
        /// Gets the number of members by handicap category report.
        /// </summary>
        /// <param name="golfClubId">The golf club identifier.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <GetNumberOfMembersByHandicapCategoryReportResponse> GetNumberOfMembersByHandicapCategoryReport(Guid golfClubId,
                                                                                                                          CancellationToken cancellationToken)
        {
            Guard.ThrowIfInvalidGuid(golfClubId, nameof(golfClubId));

            GetNumberOfMembersByHandicapCategoryReportResponse response = new GetNumberOfMembersByHandicapCategoryReportResponse();

            using (ManagementAPIReadModel context = this.ReadModelResolver())
            {
                response.GolfClubId = golfClubId;
                List <IGrouping <Int32, GolfClubMembershipReporting> > groupedData = await context.GolfClubMembershipReporting.Where(g => g.GolfClubId == golfClubId).GroupBy(g => g.HandicapCategory).ToListAsync(cancellationToken);

                foreach (IGrouping <Int32, GolfClubMembershipReporting> golfClubMembershipReportings in groupedData)
                {
                    response.MembersByHandicapCategoryResponse.Add(new MembersByHandicapCategoryResponse
                    {
                        HandicapCategory = golfClubMembershipReportings.Key,
                        NumberOfMembers  = golfClubMembershipReportings.Count()
                    });
                }
            }

            return(response);
        }
Пример #10
0
        public async Task ReportingManager_GetNumberOfMembersByHandicapCategoryReport_ReportDataReturned()
        {
            String databaseName            = Guid.NewGuid().ToString("N");
            ManagementAPIReadModel context = this.GetContext(databaseName);

            List <GolfClubMembershipReporting> reportingData = new List <GolfClubMembershipReporting>();

            reportingData.Add(new GolfClubMembershipReporting
            {
                DateJoined       = DateTime.Now,
                DateOfBirth      = DateTime.Now.AddYears(-20),
                PlayerId         = Guid.NewGuid(),
                GolfClubId       = GolfClubTestData.AggregateId,
                GolfClubName     = GolfClubTestData.Name,
                HandicapCategory = 1,
                PlayerGender     = "M",
                PlayerName       = "Test Player 1"
            });

            reportingData.Add(new GolfClubMembershipReporting
            {
                DateJoined       = DateTime.Now,
                DateOfBirth      = DateTime.Now.AddYears(-25),
                PlayerId         = Guid.NewGuid(),
                GolfClubId       = GolfClubTestData.AggregateId,
                GolfClubName     = GolfClubTestData.Name,
                HandicapCategory = 2,
                PlayerGender     = "M",
                PlayerName       = "Test Player 2"
            });

            reportingData.Add(new GolfClubMembershipReporting
            {
                DateJoined       = DateTime.Now,
                DateOfBirth      = DateTime.Now.AddYears(-25),
                PlayerId         = Guid.NewGuid(),
                GolfClubId       = GolfClubTestData.AggregateId,
                GolfClubName     = GolfClubTestData.Name,
                HandicapCategory = 2,
                PlayerGender     = "M",
                PlayerName       = "Test Player 3"
            });

            reportingData.Add(new GolfClubMembershipReporting
            {
                DateJoined       = DateTime.Now,
                DateOfBirth      = DateTime.Now.AddYears(-25),
                PlayerId         = Guid.NewGuid(),
                GolfClubId       = GolfClubTestData.AggregateId,
                GolfClubName     = GolfClubTestData.Name,
                HandicapCategory = 3,
                PlayerGender     = "M",
                PlayerName       = "Test Player 4"
            });

            reportingData.Add(new GolfClubMembershipReporting
            {
                DateJoined       = DateTime.Now,
                DateOfBirth      = DateTime.Now.AddYears(-25),
                PlayerId         = Guid.NewGuid(),
                GolfClubId       = GolfClubTestData.AggregateId,
                GolfClubName     = GolfClubTestData.Name,
                HandicapCategory = 3,
                PlayerGender     = "M",
                PlayerName       = "Test Player 5"
            });

            reportingData.Add(new GolfClubMembershipReporting
            {
                DateJoined       = DateTime.Now,
                DateOfBirth      = DateTime.Now.AddYears(-25),
                PlayerId         = Guid.NewGuid(),
                GolfClubId       = GolfClubTestData.AggregateId,
                GolfClubName     = GolfClubTestData.Name,
                HandicapCategory = 3,
                PlayerGender     = "M",
                PlayerName       = "Test Player 6"
            });

            await context.GolfClubMembershipReporting.AddRangeAsync(reportingData, CancellationToken.None);

            await context.SaveChangesAsync(CancellationToken.None);

            Func <ManagementAPIReadModel> contextResolver = () => { return(context); };

            ReportingManager reportingManager = new ReportingManager(contextResolver);

            GetNumberOfMembersByHandicapCategoryReportResponse reportData = await reportingManager.GetNumberOfMembersByHandicapCategoryReport(GolfClubTestData.AggregateId, CancellationToken.None);

            reportData.GolfClubId.ShouldBe(GolfClubTestData.AggregateId);
            reportData.MembersByHandicapCategoryResponse.ShouldNotBeEmpty();
            reportData.MembersByHandicapCategoryResponse.Where(q => q.HandicapCategory == 1).Single().NumberOfMembers.ShouldBe(1);
            reportData.MembersByHandicapCategoryResponse.Where(q => q.HandicapCategory == 2).Single().NumberOfMembers.ShouldBe(2);
            reportData.MembersByHandicapCategoryResponse.Where(q => q.HandicapCategory == 3).Single().NumberOfMembers.ShouldBe(3);
        }