Пример #1
0
        public async Task <CashflowProjectionGroup> GenerateProjectionAsync(
            List <CashflowBankAccount> accounts,
            DateTime startDate,
            DateTime endDate,
            decimal openingBalance,
            decimal threshold
            )
        {
            var cpg = this.cashflowProjectionGroupFactory.Create();

            List <CashflowProjectionTransfer> cpts = await projectionTransferGenerator.GenerateCashflowProjectionTransfersAsync(accounts, startDate, endDate);

            var tasks = new List <Task <Tuple <ICashflowProjectionMode, List <CashflowProjectionItem> > > >();

            foreach (var mode in cpg.Modes)
            {
                tasks.Add(Task.Factory.StartNew(() => {
                    var cpi = mode.GenerateAggregatedProjectionItems(cpts);
                    ApplyBalancesAndThreshold(cpi, startDate, openingBalance, threshold);
                    return(new Tuple <ICashflowProjectionMode, List <CashflowProjectionItem> >(mode, cpi));
                }));
            }


            var cpgs = await Task.WhenAll(tasks);

            foreach (var t in cpgs)
            {
                cpg.Items.Add(t.Item1, t.Item2);
            }

            //foreach (var mode in cpg.Modes)
            //{
            //    var cpi = mode.GenerateAggregatedProjectionItems(cpts);
            //    ApplyBalancesAndThreshold(cpi, startDate, openingBalance, threshold);
            //    cpg.Items.Add(mode, cpi);
            //}

            return(cpg);
        }
        public void TestSingleOccurranceTransferWithinDateRange()
        {
            List <CashflowProjectionTransfer> results;

            mockTransferFrequencyDateCalculatorFactory.Setup(s => s.GetFrequency(It.IsAny <Schedule>()))
            .Returns(mockTransferFrequencyDateCalculatorMonthly.Object);

            var testdata = new[]
            {
                new
                {   // all accounts, from elsewhere
                    TransferDate = new DateTime(2015, 7, 10),
                    StartDate    = new DateTime(2015, 7, 5),
                    EndDate      = new DateTime(2015, 10, 20),
                    FromAccount  = (BankAccount)null,
                    ToAccount    = new BankAccount()
                    {
                        BankAccountId = 2
                    },
                    CashflowAccounts = new List <CashflowBankAccount>(),
                    QtyInbound       = 1,
                    QtyOutbound      = 0,
                    Message          = "All accounts. From elsewhere. In=1, Out=0"
                },
                new
                {   // all accounts, from elsewhere
                    TransferDate = new DateTime(2015, 7, 10),
                    StartDate    = new DateTime(2015, 7, 5),
                    EndDate      = new DateTime(2015, 10, 20),
                    FromAccount  = new BankAccount()
                    {
                        BankAccountId = 2
                    },
                    ToAccount        = (BankAccount)null,
                    CashflowAccounts = new List <CashflowBankAccount>(),
                    QtyInbound       = 0,
                    QtyOutbound      = 1,
                    Message          = "All accounts. From elsewhere. In=0, Out=1"
                }
            };


            foreach (var data in testdata)
            {
                var bankAccounts = new List <BankAccount>();
                foreach (var cba in data.CashflowAccounts)
                {
                    bankAccounts.Add(cba.BankAccount);
                }


                var tds = new List <TransferDirection>()
                {
                    new TransferDirection()
                    {
                        IsInbound  = data.QtyInbound > 0,
                        IsOutbound = data.QtyOutbound > 0,
                        Transfer   = new Transfer(scheduleFactory)
                        {
                            Schedule = new Schedule(scheduleFrequencyCalculators)
                            {
                                StartDate = data.TransferDate,
                                EndDate   = data.TransferDate
                            },
                            FromBankAccount = data.FromAccount,
                            ToBankAccount   = data.ToAccount,
                            IsEnabled       = true,
                            Amount          = 100
                        }
                    }
                };

                mockTransferDirectionGenerator.Setup(s => s.GetTransferDirections(It.IsAny <List <BankAccount> >()))
                .Returns(tds);


                results = sut.GenerateCashflowProjectionTransfersAsync(data.CashflowAccounts, data.StartDate, data.EndDate).Result;

                Assert.AreEqual(results.Count(c => c.TransferDirection.IsInbound), data.QtyInbound, data.Message);

                Assert.AreEqual(results.Count(c => c.TransferDirection.IsOutbound), data.QtyOutbound, data.Message);
            }
        }