public Auction StartAuction(string title, IEnumerable<Item> items, decimal openingPrice)
        {
            // Construct auction before creating command so that Auction validations will fire
            var auction = new Auction(title, items);

            var startAuctionCommand = _startAuctionCommandFactory.Create();
            startAuctionCommand.Auction = auction;
            startAuctionCommand.Execute();

            return startAuctionCommand.Auction;
        }
Beispiel #2
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();
            }
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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));
        }
Beispiel #6
0
        public void Creating_Auction_without_openingPrice_defaults_OpeningPrice_to_0()
        {
            // Act
            var auction = new Auction(
                "Test Title",
                new List<Item> { new Item("Test Description") });

            // Assert
            auction.OpeningPrice.Should().Be(0);
        }
Beispiel #7
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);
        }