Esempio n. 1
0
        public void Does_not_parse_events_with_unknown_types()
        {
            string message = "Event: UNKNOWN;";

            Action action = () => StockEvent.From(message);

            action.ShouldThrow <ArgumentException>();
        }
Esempio n. 2
0
        public void Does_not_parse_events_with_incorrect_format()
        {
            string message = "incorrect message";

            Action action = () => StockEvent.From(message);

            action.ShouldThrow <ArgumentException>();
        }
Esempio n. 3
0
        public void Parses_close_event()
        {
            string message = "Event: CLOSE;";

            StockEvent stockEvent = StockEvent.From(message);
            string     serialized = stockEvent.ToString();

            stockEvent.Type.ShouldEqual(StockEventType.Close);
            serialized.ShouldEqual(message);
        }
Esempio n. 4
0
        public void Parses_purchase_event()
        {
            string message = "Event: PURCHASE; BuyerName: Buyer; NumberSold: 1;";

            StockEvent stockEvent = StockEvent.From(message);
            string     serialized = stockEvent.ToString();

            stockEvent.Type.ShouldEqual(StockEventType.Purchase);
            stockEvent.BuyerName.ShouldEqual("Buyer");
            stockEvent.NumberSold.ShouldEqual(1);
            serialized.ShouldEqual(message);
        }
Esempio n. 5
0
        public void Parses_price_event()
        {
            string message = "Event: PRICE; NumberInStock: 12; CurrentPrice: 34;";

            StockEvent stockEvent = StockEvent.From(message);
            string     serialized = stockEvent.ToString();

            stockEvent.Type.ShouldEqual(StockEventType.Price);
            stockEvent.NumberInStock.ShouldEqual(12);
            stockEvent.CurrentPrice.ShouldEqual(34);
            serialized.ShouldEqual(message);
        }
Esempio n. 6
0
        private void StockMessageRecieved(string message)
        {
            StockEvent   stockEvent   = StockEvent.From(message);
            StockCommand stockCommand = _buyer.Process(stockEvent);

            if (stockCommand != StockCommand.None())
            {
                _connection.SendMessage(stockCommand.ToString());
            }

            _repository.Save(ItemId, _buyer);

            Notify(nameof(CurrentPrice));
            Notify(nameof(NumberInStock));
            Notify(nameof(BoughtSoFar));
            Notify(nameof(State));
        }