public async Task AggregateCost()
        {
            var result1 = await _aggregatePortfolioService.AggregateCost(new[] { 10, 11 }, 1);

            var result2 = await _aggregatePortfolioService.AggregateCost(new[] { 10, 11, 12 }, 1);

            var result3 = await _aggregatePortfolioService.AggregateCost(new[] { 10 }, 1);

            var result4 = await _aggregatePortfolioService.AggregateCost(new[] { 12 }, 2);

            var result5 = await _aggregatePortfolioService.AggregateCost(new[] { 12 }, 1);

            Assert.IsTrue(result1.IsSuccess);
            Assert.AreEqual(434720 * 2 + 22658 * 20 + 101840 + 106283 + 115000 + 600000 - 81840 + 22658 * 10 + 5000 + 800000,
                            result1.Result);

            Assert.IsTrue(result3.IsSuccess);
            Assert.AreEqual(434720 * 2 + 22658 * 20 + 101840 + 106283 + 115000 + 600000 - 81840, result3.Result);

            Assert.IsTrue(result4.IsSuccess);
            Assert.AreEqual(434720 + 10000 + 1100000, result4.Result);

            Assert.IsFalse(result2.IsSuccess, "Считается портфель чужого пользователя");
            Assert.IsFalse(result5.IsSuccess, "Считается портфель чужого пользователя");
        }
Esempio n. 2
0
        public async Task <OperationResult <CostWithInvestSum> > AggregatePortfolioCostWithInvestSum(
            [CurrentUserIdGlobalState] int userId,
            [Service] IAggregatePortfolioService aggregatePortfolioService,
            [Service] IBalanceService balanceService,
            IEnumerable <int> portfolioIds)
        {
            var ids  = portfolioIds.ToList();
            var cost = await aggregatePortfolioService.AggregateCost(ids, userId);

            if (!cost.IsSuccess)
            {
                return(new OperationResult <CostWithInvestSum>()
                {
                    IsSuccess = cost.IsSuccess,
                    Message = cost.Message
                });
            }

            var investSum = balanceService.GetAggregateInvestSum(ids, userId);

            return(new OperationResult <CostWithInvestSum>()
            {
                IsSuccess = true,
                Message = "Суммарная стоимость и суммарнаые инвестиции",
                Result = new CostWithInvestSum()
                {
                    Cost = cost.Result,
                    InvestSum = investSum
                }
            });
        }
Esempio n. 3
0
 public async Task <OperationResult <int> > AggregatePortfolioCost(
     [CurrentUserIdGlobalState] int userId,
     [Service] IAggregatePortfolioService aggregatePortfolioService,
     IEnumerable <int> portfolioIds)
 {
     return(await aggregatePortfolioService.AggregateCost(portfolioIds, userId));
 }
Esempio n. 4
0
        public static AllPortfoliosReport GetAllPortfoliosReport(int userId, IMarketService marketService,
                                                                 IBalanceService balanceService, IAggregatePortfolioService aggregatePortfolioService)
        {
            var allCostResult = aggregatePortfolioService.AggregateCost(new[] { 1, 2 }, userId).Result;
            var allCost       = FinanceHelpers.GetPriceDouble(allCostResult.Result);

            var paperProfitResult =
                aggregatePortfolioService.AggregatePaperProfit(new[] { 1, 2 }, userId).Result.Result;
            var allPaperProfit        = FinanceHelpers.GetPriceDouble(paperProfitResult.Value);
            var allPaperProfitPercent = paperProfitResult.Percent;

            var paymentProfitResult =
                aggregatePortfolioService.AggregatePaymentProfit(new[] { 1, 2 }, userId).Result.Result;
            var allPaymentProfit        = FinanceHelpers.GetPriceDouble(paymentProfitResult.Value);
            var allPaymentProfitPercent = paymentProfitResult.Percent;

            var allInvestSum = FinanceHelpers.GetPriceDouble(balanceService.GetAggregateInvestSum(new [] { 1, 2 }, userId));

            var balanceResult = balanceService.AggregateBalance(new[] { 1, 2 }, userId).Result;
            var allBalance    = FinanceHelpers.GetPriceDouble(balanceResult.Result);

            return(new AllPortfoliosReport()
            {
                AllCost = allCost,
                AllPaperProfit = allPaperProfit,
                AllPaperProfitPercent = allPaperProfitPercent,
                AllPaymentProfit = allPaymentProfit,
                AllPaymentProfitPercent = allPaymentProfitPercent,
                AllInvestSum = allInvestSum,
                AllUserBalance = allBalance
            });
        }