コード例 #1
0
        public void a_stock_has_a_purchase_price()
        {
            var purchasePrice = new Pennies(1845);

            var stock = new Stock(purchasePrice, this);

            Assert.That(stock.LatestPrice, Is.EqualTo(purchasePrice));
        }
コード例 #2
0
        public void a_stock_whose_price_goes_down_does_not_sell_when_price_change_is_under_threshold()
        {
            _stockToSell = null;
            var purchasePrice = new Pennies(1298);
            var stock         = new Stock(purchasePrice, this);

            stock.PriceChanged(new Pennies(1297));

            Assert.That(_stockToSell, Is.Null);
        }
コード例 #3
0
        public void a_stock_whose_price_goes_down_sells_when_price_change_exceeds_threshold()
        {
            _stockToSell = null;
            var purchasePrice = new Pennies(1298);
            var stock         = new Stock(purchasePrice, this);

            stock.PriceChanged(new Pennies(1100));

            Assert.That(_stockToSell, Is.EqualTo(new Sell(stock, new Pennies(1100))));
        }
コード例 #4
0
 public void PriceChanged(Pennies newPrice)
 {
     if (newPrice.IsOneDollarLessThan(LatestPrice))
     {
         _saleHandler.Handle(new Sell(stock: this, atPrice: newPrice));
     }
     else
     {
         LatestPrice = newPrice;
     }
 }
コード例 #5
0
        public void a_stock_whose_price_goes_up_does_not_sell()
        {
            _stockToSell = null;

            var purchasePrice = new Pennies(5000);
            var stock         = new Stock(purchasePrice, this);

            stock.PriceChanged(new Pennies(7000));

            Assert.That(_stockToSell, Is.Null);
        }
コード例 #6
0
        public void a_stock_whose_price_goes_up_sells_at_a_new_price()
        {
            _stockToSell = null;

            var purchasePrice = new Pennies(5000);
            var stock         = new Stock(purchasePrice, this);

            stock.PriceChanged(new Pennies(7000));

            Assert.That(_stockToSell, Is.Null);

            stock.PriceChanged(new Pennies(6800));

            Assert.That(_stockToSell, Is.EqualTo(new Sell(stock, new Pennies(6800))));
        }
コード例 #7
0
 public Sell(Stock stock, Pennies atPrice)
 {
     Stock   = stock;
     AtPrice = atPrice;
 }
コード例 #8
0
 internal Stock(Pennies purchasePrice, IHandle <Sell> saleHandler)
 {
     LatestPrice  = purchasePrice;
     _saleHandler = saleHandler;
 }