Exemple #1
0
        private AuctionSniper CreateFailedSniper()
        {
            var sniper = new AuctionSniper("bidder", 20);

            sniper.Process(AuctionEvent.From("Some corrupted message"));
            return(sniper);
        }
Exemple #2
0
        public void Does_not_parse_events_with_incorrect_format()
        {
            string message = "Incorrectly formatted message";

            AuctionEvent auctionEvent = AuctionEvent.From(message);

            auctionEvent.Type.ShouldEqual(AuctionEventType.Unknown);
        }
Exemple #3
0
        public void Does_not_parse_events_with_incorrect_type()
        {
            string message = "SOLVersion: 1.1; Event: SOME_NONEXISTING_TYPE;";

            AuctionEvent auctionEvent = AuctionEvent.From(message);

            auctionEvent.Type.ShouldEqual(AuctionEventType.Unknown);
        }
Exemple #4
0
        public void Sniper_fails_when_auction_sends_unknown_event()
        {
            AuctionSniper sniper = CreateLosingSniper();

            AuctionCommand command = sniper.Process(AuctionEvent.From("Some corrupted message"));

            command.ShouldEqual(AuctionCommand.None());
            sniper.StateShouldBe(SniperState.Failed, 0, 0);
        }
Exemple #5
0
        public void Parses_close_events()
        {
            string message = "SOLVersion: 1.1; Event: CLOSE;";

            AuctionEvent auctionEvent    = AuctionEvent.From(message);
            string       serializedEvent = auctionEvent.ToString();

            auctionEvent.Type.ShouldEqual(AuctionEventType.Close);
            serializedEvent.ShouldEqual(message);
        }
Exemple #6
0
        public void Parses_price_events()
        {
            string message = "SOLVersion: 1.1; Event: PRICE; CurrentPrice: 12; Increment: 34; Bidder: sniper-56;";

            AuctionEvent auctionEvent    = AuctionEvent.From(message);
            string       serializedEvent = auctionEvent.ToString();

            auctionEvent.Type.ShouldEqual(AuctionEventType.Price);
            auctionEvent.CurrentPrice.ShouldEqual(12);
            auctionEvent.Increment.ShouldEqual(34);
            auctionEvent.Bidder.ShouldEqual("sniper-56");
            serializedEvent.ShouldEqual(message);
        }
Exemple #7
0
        public void ProcessMessage(Chat chat, Message message)
        {
            var @event = AuctionEvent.From(message.Body);
            var type   = @event.Type;

            if (type == "CLOSE")
            {
                _listener.AuctionClosed();
            }
            else if (type == "PRICE")
            {
                _listener.CurrentPrice(@event.CurrentPrice, @event.Increment, @event.IsFrom(_sniperId));
            }
        }
        private void ChatMessageRecieved(string message)
        {
            AuctionEvent   ev      = AuctionEvent.From(message);
            AuctionCommand command = _auctionSniper.Process(ev);

            if (command != AuctionCommand.None())
            {
                _chat.SendMessage(command.ToString());
            }

            Notify(nameof(LastPrice));
            Notify(nameof(LastBid));
            Notify(nameof(State));
        }