Exemple #1
0
        public async Task <TotalHoldings> GetHoldings(string userId)
        {
            var transactions = _transactionQueryService.GetTransactions(userId);

            if (transactions.Count > 0)
            {
                var latestPrice = await _stockService.LatestPrice(transactions);

                var processedHoldings = _holdingsProcessor.HoldingsCombiner(transactions, latestPrice);

                var holdingsValue = _holdingsProcessor.HoldingsValue(processedHoldings);

                var cash = _walletQueryService.GetWallet(userId);

                var holdings = new TotalHoldings()
                {
                    Cash     = cash.Cash,
                    Value    = holdingsValue,
                    Holdings = processedHoldings
                };

                return(holdings);
            }
            else
            {
                var cash = _walletQueryService.GetWallet(userId);

                var holdings = new TotalHoldings()
                {
                    Cash = cash.Cash,
                };

                return(holdings);
            }
        }
Exemple #2
0
        public async Task GetHoldings_TransactionCountIsGreaterThanZero_ReturnsHoldings()
        {
            var transactions = new List <TransactionEntity>();

            transactions.Add(new TransactionEntity()
            {
                Price = 1.00M, Quantity = 1, Stock = "v"
            });
            transactions.Add(new TransactionEntity()
            {
                Price = 5.00M, Quantity = 1, Stock = "tsla"
            });
            transactions.Add(new TransactionEntity()
            {
                Price = 10.00M, Quantity = 1, Stock = "goog"
            });

            var latestPrice = new Dictionary <string, LatestPriceModel>();

            latestPrice.Add("v", new LatestPriceModel()
            {
                Quote = new QuoteModel()
                {
                    LatestPrice = 10.00M
                }
            });
            latestPrice.Add("tsla", new LatestPriceModel()
            {
                Quote = new QuoteModel()
                {
                    LatestPrice = 50.00M
                }
            });
            latestPrice.Add("goog", new LatestPriceModel()
            {
                Quote = new QuoteModel()
                {
                    LatestPrice = 100.00M
                }
            });

            var processedHoldings = new List <Holding>();

            processedHoldings.Add(new Holding()
            {
                Stock = "v", LatestPrice = 10.00M, Quantity = 1
            });
            processedHoldings.Add(new Holding()
            {
                Stock = "tsla", LatestPrice = 50.00M, Quantity = 1
            });
            processedHoldings.Add(new Holding()
            {
                Stock = "goog", LatestPrice = 100.00M, Quantity = 1
            });

            var holdingsValue = 160.00M;

            var cash = new WalletEntity()
            {
                Cash = 100.00M
            };

            _transactionQueryService.GetTransactions(Arg.Any <string>()).Returns(transactions);

            _stockService.LatestPrice(Arg.Any <List <TransactionEntity> >()).Returns(latestPrice);

            _holdingsProcessor.HoldingsCombiner(Arg.Any <List <TransactionEntity> >(),
                                                Arg.Any <Dictionary <string, LatestPriceModel> >()).Returns(processedHoldings);

            _holdingsProcessor.HoldingsValue(Arg.Any <List <Holding> >()).Returns(holdingsValue);

            _walletQueryService.GetWallet(Arg.Any <string>()).Returns(cash);

            var result = await _sut.GetHoldings("9fefa208-5c52-4435-a3ca-70d1e9cee692");

            Assert.That(result.Holdings.Count, Is.EqualTo(3));
            Assert.That(result.Cash, Is.EqualTo(100.00M));
            Assert.That(result.Value, Is.EqualTo(160.00M));
        }