Пример #1
0
 public void SetUp()
 {
     assembler           = new ChartAssembler();
     validTimePeriodData = new List <KeyValuePair <string, int> > {
         new KeyValuePair <string, int>("1", 1)
     };
     validUserId   = Guid.NewGuid();
     validUsername = "******";
 }
 public void TearDown()
 {
     orchestrator               = null;
     assembler                  = null;
     billRepository             = null;
     billDataTransformer        = null;
     expenditureRepository      = null;
     expenditureDataTransformer = null;
 }
 public void SetUp()
 {
     assembler = new ChartAssembler();
     validData = new List <KeyValuePair <string, int> > {
         new KeyValuePair <string, int>("TEST", 1)
     };
     validGuid    = Guid.NewGuid();
     validExpData =
         new List <KeyValuePair <DateTime, double> > {
         new KeyValuePair <DateTime, double>(DateTime.Today, 1.0)
     };
 }
Пример #4
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;
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChartOrchestrator"/> class.
        /// </summary>
        /// <param name="assembler">
        /// The assembler.
        /// </param>
        /// <param name="billRepository">
        /// The bill repository.
        /// </param>
        /// <param name="billDataTransformer">
        /// The bill data transformer.
        /// </param>
        /// <param name="expenditureRepository">
        /// The expenditure Repository.
        /// </param>
        /// <param name="expenditureDataTransformer">
        /// The expenditure Data Transformer.
        /// </param>
        /// <param name="errorHelper">
        /// The error helper.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// Exception thrown if the assembler, repository or transformer are null.
        /// </exception>
        public ChartOrchestrator(
            IChartAssembler assembler,
            IBillRepository billRepository,
            IBillDataTransformer billDataTransformer,
            IExpenditureRepository expenditureRepository,
            IExpenditureDataTransformer expenditureDataTransformer,
            IErrorHelper errorHelper) : base(errorHelper)
        {
            if (assembler == null)
            {
                throw new ArgumentNullException(nameof(assembler));
            }

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

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

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

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

            this.assembler                  = assembler;
            this.billRepository             = billRepository;
            this.billDataTransformer        = billDataTransformer;
            this.expenditureDataTransformer = expenditureDataTransformer;
            this.expenditureRepository      = expenditureRepository;
        }
        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);
        }
 public void TearDown()
 {
     assembler    = null;
     validData    = null;
     validExpData = null;
 }
Пример #8
0
 public void TearDown()
 {
     orchestrator = null;
     assembler    = null;
     dataAccess   = null;
 }
Пример #9
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);
        }
Пример #10
0
 public void TearDown()
 {
     assembler           = null;
     validTimePeriodData = null;
 }