Exemplo n.º 1
0
        public void BidAddedWithInvalidAmountThrowsException(decimal bidAmount)
        {
            BidRepository repo    = new BidRepository();
            BidTracker    tracker = new BidTracker(repo);

            var ex = Assert.Throws <ArgumentException>(() => tracker.AddBid("item1", bidAmount, "user1"));

            Assert.Contains("The bid amount must be greater than 0.", ex.Message);
        }
Exemplo n.º 2
0
        public void BidAddedWithoutUserIdThrowsException(string userId)
        {
            BidRepository repo    = new BidRepository();
            BidTracker    tracker = new BidTracker(repo);

            var ex = Assert.Throws <ArgumentNullException>(() => tracker.AddBid("item1", 1, userId));

            Assert.Contains("A user id must be specified.", ex.Message);
        }
Exemplo n.º 3
0
        public void UserCanCreateBidSuccessfully()
        {
            BidRepository repo = new BidRepository();

            repo.Items.Add(new Item("item1", "name1"));
            repo.Bids.Add(new Bid("bid1", "item1", "user1", 2));
            repo.Bids.Add(new Bid("bid2", "item1", "user2", 3));

            BidTracker tracker = new BidTracker(repo);

            Bid bid = tracker.AddBid("item1", 5, "user3");

            Assert.Equal(3, repo.Bids.Count);

            // Retrieve the newly created bid and check its values.
            Bid newBid = repo.Bids.Single(b => b.Id == bid.Id);

            Assert.Equal(5, newBid.Amount);
            Assert.Equal("item1", newBid.ItemId);
            Assert.Equal("user3", newBid.UserId);
        }
Exemplo n.º 4
0
        public void BidLowerThanWinningBidThrowsException()
        {
            BidRepository repo = new BidRepository();

            repo.Items.Add(new Item("item1", "name1"));
            repo.Bids.Add(new Bid("bid1", "item1", "user1", 2));
            repo.Bids.Add(new Bid("bid2", "item1", "user2", 3));

            BidTracker tracker = new BidTracker(repo);

            InvalidBidException exception = Assert.Throws <InvalidBidException>(() => tracker.AddBid("item1", 1, "user3"));

            Assert.Equal("Bid too low. The current highest bid is 3.", exception.Message);
        }
Exemplo n.º 5
0
        public void BidAddedToNonExistingItemThrowsException()
        {
            BidRepository repo    = new BidRepository();
            BidTracker    tracker = new BidTracker(repo);

            InvalidBidException exception = Assert.Throws <InvalidBidException>(() => tracker.AddBid("item1", 1, "user1"));

            Assert.Equal("An item with id 'item1' does not exist.", exception.Message);
        }