コード例 #1
0
        private static void Test1()
        {
            var portfolio = new AssetPortfolio();

            portfolio.Add(new Stock("ABC", "USD", 200, 4));
            portfolio.Add(new Stock("DDW", "USD", 100, 10));
            Assert(AreEqual(portfolio.Value("USD"), 1800), " Test1 Failed, Expected Value:" + "\t" + 1800 + ",\t" + "Actual Value: \t" + portfolio.Value("USD") + "\n");
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: sercantimocin/OOPPractice2
        private static void Test1()
        {
            var portfolio = new AssetPortfolio(new ExchangeRateService());

            portfolio.Add(new Stock("ABC", 200, 4, Currency.USD));
            portfolio.Add(new Stock("DDW", 100, 10, Currency.USD));
            Assert(AreEqual(portfolio.Value(), 1800),
                   " Test1 Failed, Expected Value:" + "\t" + 1800 + ",\t" + "Actual Value: \t" + portfolio.Value() + "\n");
        }
コード例 #3
0
        public AssetPortfolio Consolidate()
        {
            AssetPortfolio ap = new AssetPortfolio(ExchangeRates, $"consolidated  {Name}");

            foreach (KeyValuePair <Asset, List <Asset> > asset in _symbols)
            {
                Asset newAsset = asset.Key.Consolidate(asset.Value);
                ap.Add(newAsset);
            }
            return(ap);
        }
コード例 #4
0
        private static void Test2()
        {
            var assetPortfolio = new AssetPortfolio()
            {
                Portfolio = new List <IAsset>()
                {
                    new Stock("ABC", "USD", 3, 2),
                    new Stock("ABC", "USD", 5, 1),
                    new Stock("ABC", "EUR", 10, 2),
                    new Currency("EUR", 100),
                    new Currency("EUR", 100),
                    new Currency("USD", 300),
                }
            };

            PrintPortfolio(assetPortfolio.Portfolio, "Your initial Portfolio: ");
            assetPortfolio.Consolidate();
            PrintPortfolio(assetPortfolio.ConsolidatedPortfolio.Values.ToList(), "Your consolidated portfolio: ");

            Console.WriteLine($"The value of your portfolio in USD is: {string.Format("{0:N2}", assetPortfolio.Value("USD"))}");
            Console.WriteLine($"The value of your portfolio in GBP is: {string.Format("{0:N2}", assetPortfolio.Value("GBP"))}");
            Console.WriteLine($"The value of your portfolio in EUR is: {string.Format("{0:N2}", assetPortfolio.Value("EUR"))}");
        }