Exemplo n.º 1
0
        /// <summary>
        ///     Obtains the data required for the expenditure chart.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>The response object.</returns>
        public async Task <GetExpenditureChartDataResponse> GetExpenditureChartData(
            GetExpenditureChartDataRequest request)
        {
            return(await Orchestrate(async delegate {
                var expenditure = await expenditureRepository.GetExpenditureForUserForMonth(request.UserId);
                var data = expenditureDataTransformer.GetRollingExpenditureSum(expenditure);

                return assembler.NewGetExpenditureChartDataResponse(data, request.RequestReference);
            }, request));
        }
        public void SetUp()
        {
            errorHelper                = Substitute.For <IErrorHelper>();
            assembler                  = Substitute.For <IChartAssembler>();
            billRepository             = Substitute.For <IBillRepository>();
            billDataTransformer        = Substitute.For <IBillDataTransformer>();
            expenditureRepository      = Substitute.For <IExpenditureRepository>();
            expenditureDataTransformer = Substitute.For <IExpenditureDataTransformer>();

            validGetBillCategoryChartDataRequest = new GetBillCategoryChartDataRequest
            {
                UserId   = Guid.NewGuid(),
                Username = "******"
            };

            validGetBillPeriodChartDataRequest = new GetBillPeriodChartDataRequest
            {
                UserId   = Guid.NewGuid(),
                Username = "******"
            };

            validGetExpenditureChartDataRequest =
                new GetExpenditureChartDataRequest {
                Month = 1, UserId = Guid.NewGuid(), Username = "******"
            };

            validBills       = new List <BillDataModel>();
            validExpenditure = new List <ExpenditureDataModel>();

            invalidGetBillPeriodChartDataRequest   = new GetBillPeriodChartDataRequest();
            invalidGetBillCategoryChartDataRequest = new GetBillCategoryChartDataRequest();
            invalidGetExpenditureChartDataRequest  = new GetExpenditureChartDataRequest();

            billRepository.GetBillsForUser(validGetBillCategoryChartDataRequest.UserId).Returns(validBills);
            billRepository.GetBillsForUser(validGetBillPeriodChartDataRequest.UserId).Returns(validBills);
            billRepository.GetBillsForUser(Guid.Empty).Throws(new Exception("TEST"));

            expenditureRepository.GetExpenditureForUserForMonth(validGetExpenditureChartDataRequest.UserId)
            .Returns(validExpenditure);
            expenditureRepository.GetExpenditureForUserForMonth(Guid.Empty).Throws(new Exception("TEST"));

            validData = new List <KeyValuePair <string, int> > {
                new KeyValuePair <string, int>("TEST", 1)
            };

            billDataTransformer.GetBillCategoryChartData(validBills).Returns(validData);
            billDataTransformer.GetBillPeriodChartData(validBills).Returns(validData);

            expenditureDataTransformer.GetRollingExpenditureSum(validExpenditure)
            .Returns(
                new List <KeyValuePair <DateTime, double> >
            {
                new KeyValuePair <DateTime, double>(DateTime.Now, 1.0)
            });

            validGetBillPeriodChartDataResponse = new GetBillPeriodChartDataResponse {
                Data = validData
            };
            validGetBillCategoryChartDataResponse = new GetBillCategoryChartDataResponse {
                Data = validData
            };
            validGetExpenditureChartDataResponse =
                new GetExpenditureChartDataResponse
            {
                Data = new List <KeyValuePair <DateTime, double> >
                {
                    new KeyValuePair <DateTime, double>(DateTime.Now, 1.0)
                }
            };

            assembler.NewGetExpenditureChartDataResponse(Arg.Any <IList <KeyValuePair <DateTime, double> > >(), Arg.Any <Guid>()).Returns(validGetExpenditureChartDataResponse);
            assembler.NewGetBillCategoryChartDataResponse(validData, Arg.Any <Guid>()).Returns(validGetBillCategoryChartDataResponse);
            assembler.NewGetBillPeriodChartDataResponse(validData, Arg.Any <Guid>()).Returns(validGetBillPeriodChartDataResponse);

            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,
                billRepository,
                billDataTransformer,
                expenditureRepository,
                expenditureDataTransformer,
                errorHelper);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Sends an HTTP GET request to obtain data for the expenditure chart.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <returns>
 /// The response object.
 /// </returns>
 public async Task <GetExpenditureChartDataResponse> GetExpenditureChartData(
     GetExpenditureChartDataRequest request)
 {
     return(await Get <GetExpenditureChartDataResponse>(request.FormatRequestUri(), request.Username));
 }
Exemplo n.º 4
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);
        }
        public async Task <IHttpActionResult> GetExpenditureChartData([FromUri] GetExpenditureChartDataRequest request)
        {
            var response = await orchestrator.GetExpenditureChartData(request);

            return(Ok(response));
        }