コード例 #1
0
        /// <summary>
        ///     Builds and sends an HTTP request for the data required to produce the bill period chart.
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <param name="username">The username.</param>
        /// <returns>
        ///     The response object.
        /// </returns>
        public async Task <OrchestratorResponseWrapper <IList <KeyValuePair <TimePeriod, int> > > > GetBillPeriodChartData(
            Guid userId,
            string username)
        {
            var response = new OrchestratorResponseWrapper <IList <KeyValuePair <TimePeriod, int> > >();

            try
            {
                var request     = assembler.NewGetBillPeriodChartDataRequest(userId, username);
                var apiResponse = await dataAccess.GetBillPeriodChartData(request);

                if (!apiResponse.Success)
                {
                    response.AddErrors(apiResponse.Errors);
                    return(response);
                }

                response.Model = assembler.AssembleTimePeriodList(apiResponse.Data);
            }
            catch (Exception ex)
            {
                var err = errorHelper.Create(ex, username, GetType(), "GetBillPeriodChartData");
                response.AddError(err);
            }

            return(response);
        }
コード例 #2
0
        public void SetUp()
        {
            assembler     = Substitute.For <IChartAssembler>();
            dataAccess    = Substitute.For <IChartDataAccess>();
            validUserId   = Guid.NewGuid();
            invalidUserId = Guid.Empty;
            validUsername = "******";

            validGetBillCategoryChartDataRequest = new GetBillCategoryChartDataRequest
            {
                UserId   = validUserId,
                Username = validUsername
            };

            invalidGetBillCategoryChartDataRequest = new GetBillCategoryChartDataRequest();

            validGetBillCategoryChartDataResponse = new GetBillCategoryChartDataResponse
            {
                Data =
                    new List
                    <
                        KeyValuePair <string, int> >()
            };

            invalidGetBillPeriodChartDataResponse = new GetBillPeriodChartDataResponse
            {
                Errors =
                {
                    new ResponseErrorWrapper
                        ()
                }
            };

            validGetBillPeriodChartDataRequest = new GetBillPeriodChartDataRequest
            {
                UserId   = validUserId,
                Username = validUsername
            };

            invalidGetBillPeriodChartDataRequest = new GetBillPeriodChartDataRequest();

            validGetBillPeriodChartDataResponse = new GetBillPeriodChartDataResponse
            {
                Data =
                    new List
                    <
                        KeyValuePair <string, int> >()
            };

            invalidGetBillPeriodChartDataResponse = new GetBillPeriodChartDataResponse
            {
                Errors =
                {
                    new ResponseErrorWrapper
                        ()
                }
            };
            invalidGetBillCategoryChartDataResponse = new GetBillCategoryChartDataResponse
            {
                Errors =
                {
                    new ResponseErrorWrapper
                        ()
                }
            };

            validGetExpenditureChartDataRequest =
                new GetExpenditureChartDataRequest {
                Month = 1, UserId = validUserId, Username = validUsername
            };

            invalidGetExpenditureChartDataRequest =
                new GetExpenditureChartDataRequest {
                Month = 1, UserId = invalidUserId, Username = string.Empty
            };

            validGetExpenditureChartDataResponse =
                new GetExpenditureChartDataResponse {
                Data = new List <KeyValuePair <DateTime, double> >()
            };

            invalidGetExpenditureChartDataResponse =
                new GetExpenditureChartDataResponse {
                Errors = { new ResponseErrorWrapper() }
            };

            assembler.NewGetBillCategoryChartDataRequest(invalidUserId, validUsername)
            .Returns(invalidGetBillCategoryChartDataRequest);
            assembler.NewGetBillCategoryChartDataRequest(validUserId, validUsername)
            .Returns(validGetBillCategoryChartDataRequest);
            assembler.NewGetBillCategoryChartDataRequest(validUserId, string.Empty)
            .Throws(new Exception("TEST EXCEPTION"));

            dataAccess.GetBillCategoryChartData(validGetBillCategoryChartDataRequest)
            .Returns(validGetBillCategoryChartDataResponse);
            dataAccess.GetBillCategoryChartData(invalidGetBillCategoryChartDataRequest)
            .Returns(invalidGetBillCategoryChartDataResponse);

            assembler.NewGetBillPeriodChartDataRequest(invalidUserId, validUsername)
            .Returns(invalidGetBillPeriodChartDataRequest);
            assembler.NewGetBillPeriodChartDataRequest(validUserId, validUsername)
            .Returns(validGetBillPeriodChartDataRequest);
            assembler.NewGetBillPeriodChartDataRequest(validUserId, string.Empty)
            .Throws(new Exception("TEST EXCEPTION"));


            assembler.NewGetExpenditureChartDataRequest(1, invalidUserId, validUsername)
            .Returns(invalidGetExpenditureChartDataRequest);
            assembler.NewGetExpenditureChartDataRequest(1, validUserId, validUsername)
            .Returns(validGetExpenditureChartDataRequest);
            assembler.NewGetExpenditureChartDataRequest(-1, invalidUserId, string.Empty)
            .Throws(new Exception("TEST EXCEPTION"));

            dataAccess.GetBillPeriodChartData(validGetBillPeriodChartDataRequest)
            .Returns(validGetBillPeriodChartDataResponse);
            dataAccess.GetBillPeriodChartData(invalidGetBillPeriodChartDataRequest)
            .Returns(invalidGetBillPeriodChartDataResponse);

            dataAccess.GetExpenditureChartData(validGetExpenditureChartDataRequest)
            .Returns(validGetExpenditureChartDataResponse);
            dataAccess.GetExpenditureChartData(invalidGetExpenditureChartDataRequest)
            .Returns(invalidGetExpenditureChartDataResponse);

            errorHelper = Substitute.For <IErrorHelper>();

            errorHelper.Create(Arg.Any <Exception>(), Arg.Any <string>(), Arg.Any <Type>(), Arg.Any <string>())
            .Returns(new ResponseErrorWrapper());
            errorHelper.Create(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <Type>(), Arg.Any <string>())
            .Returns(new ResponseErrorWrapper());

            orchestrator = new ChartOrchestrator(assembler, dataAccess, errorHelper);
        }