예제 #1
0
        public void Losing_sniper_loses_when_auction_closes()
        {
            AuctionSniper sniper = CreateLosingSniper();

            AuctionCommand command = sniper.Process(AuctionEvent.Close());

            command.ShouldEqual(AuctionCommand.None());
            sniper.Snapshot.State.ShouldEqual(SniperState.Lost);
        }
예제 #2
0
        public void Bidding_sniper_is_winning_when_price_event_with_the_same_bidder_arrives()
        {
            AuctionSniper sniper = CreateBiddingSniper("bidder");

            AuctionCommand command = sniper.Process(AuctionEvent.Price(3, 2, "bidder"));

            command.ShouldEqual(AuctionCommand.None());
            sniper.StateShouldBe(SniperState.Winning, 3, 3);
        }
예제 #3
0
        public void Sniper_is_losing_when_it_cannot_beat_last_bid()
        {
            var sniper = new AuctionSniper("bidder", 20);

            AuctionCommand command = sniper.Process(AuctionEvent.Price(15, 10, "other bidder"));

            command.ShouldEqual(AuctionCommand.None());
            sniper.StateShouldBe(SniperState.Losing, 15, 0);
        }
예제 #4
0
        public void Bidding_sniper_loses_when_auction_closes()
        {
            AuctionSniper sniper = CreateBiddingSniper();

            AuctionCommand command = sniper.Process(AuctionEvent.Close());

            command.ShouldEqual(AuctionCommand.None());
            sniper.StateShouldBe(SniperState.Lost, 1, 3);
        }
예제 #5
0
        public void Sniper_bids_when_price_event_with_a_different_bidder_arrives()
        {
            var sniper = new AuctionSniper("", 200);

            AuctionCommand command = sniper.Process(AuctionEvent.Price(1, 2, "some bidder"));

            command.ShouldEqual(AuctionCommand.Bid(3));
            sniper.StateShouldBe(SniperState.Bidding, 1, 3);
        }
예제 #6
0
        public void Joining_sniper_loses_when_auction_closes()
        {
            var sniper = new AuctionSniper("", 200);

            AuctionCommand command = sniper.Process(AuctionEvent.Close());

            command.ShouldEqual(AuctionCommand.None());
            sniper.StateShouldBe(SniperState.Lost, 0, 0);
        }
예제 #7
0
        public void Failed_sniper_does_not_react_on_further_messages()
        {
            AuctionSniper sniper = CreateFailedSniper();

            AuctionCommand command = sniper.Process(AuctionEvent.Price(10, 5, "some bidder"));

            command.ShouldEqual(AuctionCommand.None());
            sniper.StateShouldBe(SniperState.Failed, 0, 0);
        }
        public async Task CreateAuctionAsync(AuctionCommand auctionCommand, Guid userId)
        {
            var auction = await _repository.GetAsync(auctionCommand.Url);

            if (auction != null)
            {
                throw new Exception("Auction already existing in database.");
            }

            Auction auctionNew = Auction.Create(auctionCommand.AuctionName, auctionCommand.Url, auctionCommand.IsActive, userId);
            await _repository.AddAsync(auctionNew);
        }
예제 #9
0
        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));
        }
예제 #10
0
        public void Bid_command_is_of_appropriate_content()
        {
            AuctionCommand command = AuctionCommand.Bid(123);

            command.ToString().ShouldEqual("SOLVersion: 1.1; Command: BID; Price: 123;");
        }
예제 #11
0
        public void Join_command_is_of_appropriate_content()
        {
            AuctionCommand command = AuctionCommand.Join();

            command.ToString().ShouldEqual("SOLVersion: 1.1; Command: JOIN;");
        }
        public async Task <IActionResult> Post([FromBody] AuctionCommand command)
        {
            await ExecuteAsync(command);

            return(Created($"", null));
        }