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

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

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

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

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

            Assert.IsTrue(result1.IsSuccess);
            Assert.AreEqual(34720 * 2 + 26580 * 2 + 20000 + 6283 - 100000 + 26580, result1.Result.Value);
            Assert.AreEqual(
                FinanceHelpers.DivWithOneDigitRound(34720 * 2 + 26580 * 2 + 20000 + 6283 - 100000 + 26580, 3000000),
                result1.Result.Percent);

            Assert.IsTrue(result3.IsSuccess);
            Assert.AreEqual(34720 * 2 + 26580 * 2 + 20000 + 6283 - 100000, result3.Result.Value);
            Assert.AreEqual(
                FinanceHelpers.DivWithOneDigitRound(34720 * 2 + 26580 * 2 + 20000 + 6283 - 100000, 2000000),
                result3.Result.Percent);

            Assert.IsTrue(result4.IsSuccess);
            Assert.AreEqual(34720, result4.Result.Value);
            Assert.AreEqual(FinanceHelpers.DivWithOneDigitRound(34720, 1500000), result4.Result.Percent);

            Assert.IsFalse(result2.IsSuccess, "Считается портфель чужого пользователя");
            Assert.IsFalse(result5.IsSuccess, "Считается портфель чужого пользователя");
        }
Esempio n. 2
0
 public async Task <OperationResult <ValuePercent> > AggregatePortfolioPaperProfit(
     [CurrentUserIdGlobalState] int userId,
     [Service] IAggregatePortfolioService aggregatePortfolioService,
     IEnumerable <int> portfolioIds)
 {
     return(await aggregatePortfolioService.AggregatePaperProfit(portfolioIds, userId));
 }
Esempio n. 3
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
            });
        }