public void WhenStockPriceUnderZero_ExpectBuy()
        {
            //Arrange
            #region moq
            //var mock = new Mock<IStockPriceManager>();
            //mock.Setup(foo => foo.GetCurrentPrice(stock)).Returns(-1);
            //var stockSimulator = new StockSimulator(mock.Object);
            #endregion
            #region NSubstitute
            //var mock = Substitute.For<IStockPriceManager>();
            //mock.GetCurrentPrice(stock).Returns(-1);
            //var stockSimulator = new StockSimulator(mock);
            #endregion
            #region nMock3
            //var mockFactory = new MockFactory();
            //var mock = mockFactory.CreateMock<IStockPriceManager>();
            //mock.Expects.One.Method(d => d.GetCurrentPrice(stock)).With(stock).WillReturn(-1);
            //var stockSimulator = new StockSimulator(mock.MockObject);
            #endregion
            #region RhinoMock
            var mock = Rhino.Mocks.MockRepository.GenerateMock <IStockPriceManager>();
            mock.Expect(d => d.GetCurrentPrice(stock)).Return(-1);
            var stockSimulator = new StockSimulator(mock);
            #endregion
            //Act
            var answer = stockSimulator.IsStockGood(stock);

            //Assert
            Assert.IsFalse(answer);
        }
        static void Main(string[] args)
        {
            //This is our Observable also known as publisher that notifies about change
            var stockObservable = new Observable <Stock>();

            //observer that monitors microsoft stock
            var microsoftObserver = new MicrosoftStockObserver();

            //here microsoftObserver gets register with stockObservable
            //as microsoftObserver wants to get notified when there is a
            //change made inside the subject.
            stockObservable.Register(microsoftObserver);

            //observer that monitors google stock
            var googleObserver = new GoogleStockObserver();

            //here googleObserver gets register with stockObservable
            //as googleObserver wants to get notified when there is a
            //change made inside the subject.
            stockObservable.Register(googleObserver);

            //our same old simulator
            var stockSimulator = new StockSimulator();

            //code that updates the subject
            foreach (var stock in stockSimulator)
            {
                stockObservable.Subject = stock; //this will cause for
            }
            Console.ReadLine();
        }
 public void WhenStockNotFound_ExpectException()
 {
     //Arrange
     #region moq
     //var mock = new Mock<IStockPriceManager>();
     //mock.Setup(foo => foo.GetCurrentPrice(stock)).Throws<ExceptionStockNotFound>();
     //var stockSimulator = new StockSimulator(mock.Object);
     #endregion
     #region NSubstitute
     //var mock = Substitute.For<IStockPriceManager>();
     //mock.GetCurrentPrice(stock).Returns(x => { throw new ExceptionStockNotFound(); });
     //var stockSimulator = new StockSimulator(mock);
     #endregion
     #region nMock3
     //var mockFactory = new MockFactory();
     //var mock = mockFactory.CreateMock<IStockPriceManager>();
     //mock.Expects.One.Method(d => d.GetCurrentPrice(stock)).With(stock).Will(Throw.Exception(new ExceptionStockNotFound()));
     //var stockSimulator = new StockSimulator(mock.MockObject);
     #endregion
     #region RhinoMock
     var mock = Rhino.Mocks.MockRepository.GenerateMock <IStockPriceManager>();
     mock.Expect(d => d.GetCurrentPrice(stock)).Throw(new ExceptionStockNotFound());
     var stockSimulator = new StockSimulator(mock);
     #endregion
     //Act & Assert
     try
     {
         stockSimulator.IsStockGood(stock);
         Assert.Fail("Should never go here");
     }
     catch (ExceptionStockNotFound e)
     {
         //This is what we want
     }
 }
        static void Main(string[] args)
        {
            var stockSimulator = new StockSimulator();

            foreach (var stock in stockSimulator)
            {
                if (stock.Name == "Microsoft")
                {
                    Console.WriteLine($"Microsoft new price is {stock.Price}");
                }

                if (stock.Name == "Google" && stock.Price > 50)
                {
                    Console.WriteLine($"Google has reached the target price {stock.Price}");
                }

                /* Now, if look at the program we can say that we have two differenct activity.
                 * One activity is checking for the microsoft price and the other is checking for the google price.
                 * Although, they both are independent of each other they are occuring in the same program.
                 *
                 * If for some reason we want to monitor a new stock we have to update the main program.
                 */

                if (stock.Name == "Apple")
                {
                    Console.WriteLine($"Apple new price is {stock.Price}");
                }

                /* Now, The observer pattern what allow us to do is separate out the monitoring
                 * aspect of the stock data from the action of reading the stock data from the stock simulator.
                 */
            }
            Console.ReadLine();
        }
Beispiel #5
0
        private void Simulator(SecurityInfo si, DateTime StartDate, DateTime EndDate, DataReceiver dataReceiver, int inteval)
        {
            StockSimulator ss = new StockSimulator(si, StartDate, EndDate, da, dataReceiver, inteval, true);
            Thread         th = new Thread(new ThreadStart(ss.Start));

            SimulatThread.Add(th);
            th.Start();
        }
Beispiel #6
0
    static void Main(string[] args)
    {
        var stockObservable   = new StockObservable();
        var microsoftObserver = new MicrosoftStockObserver(stockObservable);
        var googleObserver    = new GoogleStockObserver(stockObservable);

        var stockSimulator = new StockSimulator();

        foreach (var stock in stockSimulator)
        {
            stockObservable.Subject = stock;
        }
        Console.ReadLine();
    }
        static void Main(string[] args)
        {
            /* The below code is a stock simulator that contains a list of dummy stock data
             * Each stock contains a name and price that we can monitor
             */
            var stockSimulator = new StockSimulator();

            foreach (var stock in stockSimulator)
            {
                //The below code that checks for microsoft stock and display its changed price
                if (stock.Name == "Microsoft")
                {
                    Console.WriteLine($"Microsoft new price is {stock.Price}");
                }

                //The below code looks for google stock and check if its reached the target price
                // and display the price when it reaches the target price.
                if (stock.Name == "Google" && stock.Price > 50)
                {
                    Console.WriteLine($"Google has reached the target price {stock.Price}");
                }
            }
            Console.ReadLine();
        }
Beispiel #8
0
        private static void AutomaticSimulator(StockTicker stockTicker)
        {
            var simulator = new StockSimulator(stockTicker);

            simulator.Run();
        }