public void TestIfNewBidIsCreated_ValidInput(int userid, int productId, double price) { // ARRANGE var bid = new Bid() { UserId = userid, ProductId = productId, Price = price, CreatedAt = DateTime.Now.AddDays(1), Product = new Product() { Name = "test" } }; var bs = new BidService(_repoMock.Object); var bidList = new List <Bid>(); // ACT var newBid = bs.Add(bid); bidList.Add(bid); // ASSERT _repoMock.Setup(b => b.Add(bid)).Returns(newBid); _repoMock.Verify(repo => repo.Add(bid), Times.Once); bidList.Should().Contain(bid); }
[InlineData(2, 1, -1.00, "price")] // price is less than 0 public void CreateNewBidWithInvalidInput_ExpectArgumentException(int userid, int productId, double price, string errorField) { // ARRANGE var bid = new Bid() { UserId = userid, ProductId = productId, Price = price, CreatedAt = DateTime.Now }; var bs = new BidService(_repoMock.Object); // ACT var ex = Assert.Throws <ArgumentException>(() => bs.Add(bid)); // ASSERT Assert.Equal($"Invalid bid property: {errorField}", ex.Message); _repoMock.Verify(repo => repo.Add(It.Is <Bid>(b => b == bid)), Times.Never); }
public void AddBidThatExists_ExpectInvalidArgumentException() { // ARRANGE var bid = new Bid() { UserId = 1, ProductId = 1, Price = 2000, CreatedAt = DateTime.Now }; _repoMock.Setup(repo => repo.Get(It.Is <int>(x => x == bid.BidId))).Returns(() => bid); var bs = new BidService(_repoMock.Object); // ACT var ex = Assert.Throws <InvalidOperationException>(() => bs.Add(bid)); // ASSERT Assert.Equal("Bid already exists", ex.Message); _repoMock.Verify(repo => repo.Add(It.Is <Bid>(b => b == bid)), Times.Never); }
[InlineData(2, 1, 2000)] //Equal to higher price public void AddBidWithPriceLowerThanCurrentHighest_ExpectInvalidArgumentException(int userId, int productId, double price) { //ARRANGE var bid1 = new Bid() { BidId = 1, UserId = 1, ProductId = 1, Price = 2000, CreatedAt = DateTime.Now }; var bid2 = new Bid() { BidId = 2, UserId = userId, ProductId = productId, Price = price, CreatedAt = DateTime.Now }; _bids = new List <Bid> { bid1 }; _repoMock.Setup(repo => repo.Get(It.Is <int>(x => x == bid1.BidId))).Returns(() => bid1); var bs = new BidService(_repoMock.Object); //ACT var ex = Assert.Throws <InvalidOperationException>(() => bs.Add(bid2)); //ASSERT Assert.Equal("Bid is lower, or equal to, the current highest bid", ex.Message); _repoMock.Verify(repo => repo.Add(It.Is <Bid>(b => b == bid2)), Times.Never); }