예제 #1
0
        public void Can_add_bids()
        {
            // Arrange
            object id;
            var items = new List<Item>
                    {
                        new Item("item 1"), new Item("item 2"), new Item("item 3")
                    };
            var auction = new Auction("test", items);
            const decimal expectedBidAmount1 = 123.45m;
            var expectedBidder1 = new Bidder("bidder1");
            var expectedBidder2 = new Bidder("bidder2");

            const decimal expectedBidAmount2 = 321.54m;

            // Act
            using (var transaction = Session.BeginTransaction())
            {
                Session.Save(expectedBidder1);
                Session.Save(expectedBidder2);

                auction.PlaceBid(expectedBidder1.Id, expectedBidAmount1);
                auction.PlaceBid(expectedBidder2.Id, expectedBidAmount2);

                id = Session.Save(auction);

                transaction.Commit();
            }

            Session.Clear();

            using (var transaction = Session.BeginTransaction())
            {
                var actual = Session.Get<Auction>(id);

                // Assert
                actual.Bids.Count.Should().Be(2);
                actual.Bids.ToList().ForEach(x =>
                    actual.Bids
                        .Any(
                            y => y.Amount == x.Amount
                            && x.Id == y.Id)
                        .Should().BeTrue());
                actual.CurrentBid.Amount.Should()
                    .Be(expectedBidAmount2,
                        "The current bid must be the last bid added");
                actual.CurrentBid.Amount.Should()
                    .Be(actual.Bids.Max(x => x.Amount));
                transaction.Commit();
            }
        }
예제 #2
0
        public void Adding_a_bid_of_a_lower_value_throws_an_exception()
        {
            // Arrange
            var target = new Auction(
                    "Test Auction",
                    new List<Item> { new Item("Test Item Description") });
            var firstBidder = new Bidder("First Bidder");
            const decimal firstAmount = 500.00m;
            var secondBidder = new Bidder("Second Bidder");
            const decimal secondLowerAmount = 400.00m;
            target.PlaceBid(firstBidder.Id, firstAmount);

            // Act
            target.PlaceBid(secondBidder.Id, secondLowerAmount);
        }
예제 #3
0
        public void Adding_2_bids_should_have_second_bid_as_current_bid()
        {
            // Arrange
            var target = new Auction(
                    "Test Auction",
                    new List<Item> { new Item("Test Item Description") });
            var firstBidder = new Bidder("First Bidder");
            const decimal firstAmount = 500.00m;
            var expectedBidder = new Bidder("Second Bidder");
            const decimal expectedAmount = 600.00m;
            target.PlaceBid(firstBidder.Id, firstAmount);

            // Act
            target.PlaceBid(expectedBidder.Id, expectedAmount);

            // Assert
            target.CurrentBid.Bidder.Id.ShouldBeEquivalentTo(expectedBidder.Id);
            target.CurrentBid.Amount.ShouldBeEquivalentTo(expectedAmount);
        }
예제 #4
0
        public void Can_place_a_bid()
        {
            // Arrange
            var target = new Auction(
                    "Test Auction",
                    new List<Item> { new Item("Test Item Description") });
            var expectedBidder = new Bidder("Test Bidder");
            const decimal expectedAmount = 500.00m;
            const int expectedNumberOfBids = 1;

            // Act
            target.PlaceBid(expectedBidder.Id, expectedAmount);

            //Assert
            target.Bids.Should().NotBeEmpty();
            target.Bids.Count().Should().Be(expectedNumberOfBids);
            Assert.IsTrue(
                target.Bids.Any(
                    x => x.Bidder.Id == expectedBidder.Id
                    && x.Amount == expectedAmount));
        }
예제 #5
0
        public void Ending_an_auction_will_set_status_to_completed()
        {
            // Arrange
            var target = new Auction(
                    "Test Auction",
                    new List<Item> { new Item("Test Item Description") });
            var expectedBidder = new Bidder("Test Bidder");
            const decimal expectedAmount = 500.00m;
            target.PlaceBid(expectedBidder.Id, expectedAmount);

            // Act
            target.EndAuction();

            // Assert
            target.Status.ShouldBeEquivalentTo(AuctionStatus.Completed);
        }