Пример #1
0
        static void Main(string[] args)
        {
            KyungraeWrestlingCareer kyungraeWrestling = new KyungraeWrestlingCareer();

            Chris   chris   = new Chris();
            Amanda  amanda  = new Amanda();
            Enrique enrique = new Enrique();
            Biniam  biniam  = new Biniam();
            Karina  karina  = new Karina();

            kyungraeWrestling.RegisterObserver(chris);
            kyungraeWrestling.RegisterObserver(amanda);
            kyungraeWrestling.RegisterObserver(enrique);
            kyungraeWrestling.RegisterObserver(biniam);
            kyungraeWrestling.RegisterObserver(karina);


            kyungraeWrestling.SendMatchResult();

            chris.Results.ForEach(x => Console.WriteLine(x.Score));
            amanda.Results.ForEach(x => Console.WriteLine(x.Score));
            enrique.Results.ForEach(x => Console.WriteLine(x.Score));
            biniam.Results.ForEach(x => Console.WriteLine(x.Score));
            karina.Results.ForEach(x => Console.WriteLine(x.Score));
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Chris c = new Chris();
            c.Weight = 25;

            MessageBox.Show(c.Weight.ToString());
        }
Пример #3
0
        static void Main(string[] args)
        {
            // Console.WriteLine("Hello World!");
            //   Tim tim = new Tim(20, 900, "Timbo");
            Tim tim = new Tim("Tim", 24, 20, 900);

            System.Console.WriteLine(tim.Name);
            System.Console.WriteLine(tim.Orders);
            System.Console.WriteLine(tim.CalculateTime());

            Chris chris = new Chris(400, "Chris", 30);

            System.Console.WriteLine(chris.CalculateTime());
            System.Console.WriteLine(chris.EatDoritos());
            System.Console.WriteLine(tim.EatDoritos());

            System.Console.WriteLine((tim as IOrderWriter).Orders);

            List <IDeveloper> developers  = new List <IDeveloper>();
            Kaleb             kaleb       = new Kaleb("Kaleb", 29);
            Music             kalebsMusic = (kaleb as IMusician).PlayMusic();

            // kaleb.
            developers.Add(tim);
            developers.Add(chris);
            developers.Add(kaleb);
            developers.ForEach(developer =>
            {
                if (developer is Person)
                {
                    // NOTE Two different ways of casting to a type
                    Person p      = developer as Person;
                    Person person = (Person)developer;
                    System.Console.WriteLine($"Hi my name is {p.Name}");
                }
                if (developer is IMusician)
                {
                    IMusician ownMusicMaker = (IMusician)developer;
                    Music selfMadeMusic     = ownMusicMaker.PlayMusic();
                    developer.WriteCode(selfMadeMusic);
                }
                developer.WriteCode(kalebsMusic);
            });
        }
        public ActionResult Index()
        {
            List <PlayerViewModel> players = new List <PlayerViewModel>();
            StockEngine            engine  = new YahooStockEngine();

            // Chris
            Player          player     = new Chris();
            Investment      investment = engine.GetCurrentInvestmentForPlayer(player.Name);
            Quote           quote      = engine.GetCurrentQuoteForPlayer(player.Name);
            PlayerViewModel model      = new PlayerViewModel(investment, quote, player);

            players.Add(model);

            // Fiona
            player     = new Fiona();
            investment = engine.GetCurrentInvestmentForPlayer(player.Name);
            quote      = engine.GetCurrentQuoteForPlayer(player.Name);
            model      = new PlayerViewModel(investment, quote, player);
            players.Add(model);

            // Wilson
            player     = new Wilson();
            investment = engine.GetCurrentInvestmentForPlayer(player.Name);
            quote      = engine.GetCurrentQuoteForPlayer(player.Name);
            model      = new PlayerViewModel(investment, quote, player);
            players.Add(model);

            // Katherine
            player     = new Katherine();
            investment = engine.GetCurrentInvestmentForPlayer(player.Name);
            quote      = engine.GetCurrentQuoteForPlayer(player.Name);
            model      = new PlayerViewModel(investment, quote, player);
            players.Add(model);

            // Jon
            player     = new Jon();
            investment = engine.GetCurrentInvestmentForPlayer(player.Name);
            quote      = engine.GetCurrentQuoteForPlayer(player.Name);
            model      = new PlayerViewModel(investment, quote, player);
            players.Add(model);

            return(View(players));
        }
Пример #5
0
        public void GetCurrentQuoteForPlayer()
        {
            // Arrange
            StockEngine          engine  = new YahooStockEngine();
            IEnumerable <string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");
            string  randomSymbol         = engine.PickRandomSymbol(symbols);
            Quote   quote      = engine.LookupPrice(randomSymbol);
            decimal walletSize = 400;             // £400

            Player player = new Chris();

            // Act
            engine.InsertQuote(quote);
            engine.InitializePlayer(player, quote, walletSize);
            Quote currentQuote = engine.GetCurrentQuoteForPlayer(player.Name);

            // Assert
            Assert.That(currentQuote.Id, Is.EqualTo(quote.Id));
            Assert.That(currentQuote.Symbol, Is.EqualTo(quote.Symbol));
            Assert.That(currentQuote.LastTradePrice, Is.EqualTo(quote.LastTradePrice));
        }
Пример #6
0
        public void InitializePlayer()
        {
            // Arrange
            StockEngine          engine  = new YahooStockEngine();
            IEnumerable <string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");
            string  randomSymbol         = engine.PickRandomSymbol(symbols);
            Quote   quote      = engine.LookupPrice(randomSymbol);
            decimal walletSize = 400;             // £400

            Player player = new Chris();

            // Act
            engine.InsertQuote(quote);
            engine.InitializePlayer(player, quote, walletSize);

            // Assert
            Investment investment = engine.GetCurrentInvestmentForPlayer(player.Name);

            Assert.That(investment.Symbol, Is.EqualTo(randomSymbol));
            Assert.That(investment.PlayerName, Is.EqualTo(player.GetType().Name));
            Assert.That(investment.PurchaseDate, Is.GreaterThan(DateTime.Today));
            Assert.That(investment.PurchasePrice, Is.EqualTo(quote.LastTradePrice.Value));
        }
Пример #7
0
        public void GetPlayerHistory()
        {
            // Arrange
            StockEngine          engine  = new YahooStockEngine();
            IEnumerable <string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");
            string  randomSymbol         = engine.PickRandomSymbol(symbols);
            decimal walletSize           = 400;

            Player player = new Chris();
            Quote  quote1 = engine.LookupPrice(randomSymbol);

            engine.InitializePlayer(player, quote1, walletSize);

            Quote quote2 = engine.LookupPrice(randomSymbol);

            engine.InitializePlayer(player, quote2, walletSize);

            // Act
            IEnumerable <Investment> investments = engine.GetInvestmentHistoryForPlayer(player.Name);

            // Assert
            Assert.That(investments.Count(), Is.EqualTo(2));
        }
Пример #8
0
        public void ShouldSellInvestment_Boundaries()
        {
            // Arrange
            Investment investment1 = new Investment()
            {
                Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today
            };
            Investment investment2 = new Investment()
            {
                Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today
            };
            Investment investment3 = new Investment()
            {
                Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today
            };

            Investment investment4 = new Investment()
            {
                Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today
            };
            Investment investment5 = new Investment()
            {
                Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today
            };
            Investment investment6 = new Investment()
            {
                Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today
            };

            Investment investment7 = new Investment()
            {
                Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today
            };
            Investment investment8 = new Investment()
            {
                Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today
            };
            Investment investment9 = new Investment()
            {
                Symbol = "", PurchasePrice = 1.0m, PurchaseDate = DateTime.Today
            };

            Quote highQuote1 = new Quote()
            {
                Symbol = "BLAH", LastTradePrice = 1.05m
            };
            Quote highQuote2 = new Quote()
            {
                Symbol = "BLAH", LastTradePrice = 1.06m
            };
            Quote highQuote3 = new Quote()
            {
                Symbol = "BLAH", LastTradePrice = 3.99m
            };

            Quote lowQuote1 = new Quote()
            {
                Symbol = "BLAH", LastTradePrice = 0.95m
            };
            Quote lowQuote2 = new Quote()
            {
                Symbol = "BLAH", LastTradePrice = 0.49m
            };
            Quote lowQuote3 = new Quote()
            {
                Symbol = "BLAH", LastTradePrice = 0
            };

            Quote noChangeQuote1 = new Quote()
            {
                Symbol = "BLAH", LastTradePrice = 0.96m
            };
            Quote noChangeQuote2 = new Quote()
            {
                Symbol = "BLAH", LastTradePrice = 1.04m
            };
            Quote noChangeQuote3 = new Quote()
            {
                Symbol = "BLAH", LastTradePrice = null
            };

            // Act
            Chris chris           = new Chris();   // 5% change
            bool  shouldSellHigh1 = chris.ShouldSellInvestment(highQuote1, investment1);
            bool  shouldSellHigh2 = chris.ShouldSellInvestment(highQuote2, investment2);
            bool  shouldSellHigh3 = chris.ShouldSellInvestment(highQuote3, investment3);

            bool shouldSellLow1 = chris.ShouldSellInvestment(lowQuote1, investment4);
            bool shouldSellLow2 = chris.ShouldSellInvestment(lowQuote2, investment5);
            bool shouldSellLow3 = chris.ShouldSellInvestment(lowQuote3, investment6);

            bool shouldSellNoChange1 = chris.ShouldSellInvestment(noChangeQuote1, investment7);
            bool shouldSellNoChange2 = chris.ShouldSellInvestment(noChangeQuote2, investment8);
            bool shouldSellNoChange3 = chris.ShouldSellInvestment(noChangeQuote3, investment9);

            // Assert
            Assert.True(shouldSellHigh1, "High price 1 to 1.05"); Assert.That(investment1.SellReason, Is.EqualTo(SellReason.HighPrice));
            Assert.True(shouldSellHigh2, "High price 1 to 1.06"); Assert.That(investment2.SellReason, Is.EqualTo(SellReason.HighPrice));
            Assert.True(shouldSellHigh3, "High price 1 to 3.99"); Assert.That(investment3.SellReason, Is.EqualTo(SellReason.HighPrice));

            Assert.True(shouldSellLow1, "Low price 1 to 0.95"); Assert.That(investment4.SellReason, Is.EqualTo(SellReason.LowPrice));
            Assert.True(shouldSellLow2, "Low price 1 to 0.49"); Assert.That(investment5.SellReason, Is.EqualTo(SellReason.LowPrice));
            Assert.True(shouldSellLow3, "Low price 1 to 0"); Assert.That(investment6.SellReason, Is.EqualTo(SellReason.LowPrice));

            Assert.False(shouldSellNoChange1, "No change 1 to 0.96");
            Assert.False(shouldSellNoChange2, "No change 1 to 1.04");
            Assert.False(shouldSellNoChange3, "No change 1 to (null)");
        }