Ejemplo n.º 1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ChartOrchestrator" /> class.
        /// </summary>
        /// <param name="assembler">The assembler.</param>
        /// <param name="dataAccess">The data access.</param>
        /// <param name="errorHelper">The error helper.</param>
        /// <exception cref="System.ArgumentNullException">
        ///     Exception thrown if the assembler, error helper or data access are null.
        /// </exception>
        public ChartOrchestrator(IChartAssembler assembler, IChartDataAccess dataAccess, IErrorHelper errorHelper)
        {
            if (assembler == null)
            {
                throw new ArgumentNullException(nameof(assembler));
            }

            if (dataAccess == null)
            {
                throw new ArgumentNullException(nameof(dataAccess));
            }

            if (errorHelper == null)
            {
                throw new ArgumentNullException(nameof(errorHelper));
            }

            this.assembler   = assembler;
            this.dataAccess  = dataAccess;
            this.errorHelper = errorHelper;
        }
Ejemplo n.º 2
0
 public void TearDown()
 {
     orchestrator = null;
     assembler    = null;
     dataAccess   = null;
 }
Ejemplo n.º 3
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);
        }