public void CreateBid_ValidBids_ShouldCreateBidsCorrectly() { // Arrange -> clean database, register new user, create an offer TestingEngine.CleanDatabase(); var userSession = TestingEngine.RegisterUser("peter", "pAssW@rd#123456"); var offerModel = new OfferModel() { Title = "Title", Description = "Description", InitialPrice = 200, ExpirationDateTime = DateTime.Now.AddDays(5) }; var httpResultOffer = TestingEngine.CreateOfferHttpPost(userSession.Access_Token, offerModel.Title, offerModel.Description, offerModel.InitialPrice, offerModel.ExpirationDateTime); Assert.AreEqual(HttpStatusCode.Created, httpResultOffer.StatusCode); var offer = httpResultOffer.Content.ReadAsAsync<OfferModel>().Result; // Act -> create a few bids var bidsToAdds = new BidModel[] { new BidModel() { BidPrice = 250, Comment = "My initial bid" }, new BidModel() { BidPrice = 300, Comment = "My second bid" }, new BidModel() { BidPrice = 400, Comment = "My third bid" }, new BidModel() { BidPrice = 500 } }; foreach (var bid in bidsToAdds) { var httpResultBid = TestingEngine.CreateBidHttpPost(userSession.Access_Token, offer.Id, bid.BidPrice, bid.Comment); Assert.AreEqual(HttpStatusCode.OK, httpResultBid.StatusCode); } // Assert -> bids created successfully var bidsCount = TestingEngine.GetBidsCountFromDb(); Assert.AreEqual(4, bidsCount); }
public void CreateBid_InvalidBids_ShouldCreateBidCorrectly() { // Arrange -> clean database, register new user, create an offer TestingEngine.CleanDatabase(); var userSession = TestingEngine.RegisterUser("peter", "pAssW@rd#123456"); var offerModel = new OfferModel() { Title = "Title", Description = "Description", InitialPrice = 200, ExpirationDateTime = DateTime.Now.AddDays(5) }; var httpResultOffer = TestingEngine.CreateOfferHttpPost(userSession.Access_Token, offerModel.Title, offerModel.Description, offerModel.InitialPrice, offerModel.ExpirationDateTime); Assert.AreEqual(HttpStatusCode.Created, httpResultOffer.StatusCode); var offer = httpResultOffer.Content.ReadAsAsync<OfferModel>().Result; // Act -> try to create a few bids var bids = new BidModel[] { new BidModel() { BidPrice = 150, Comment = "Invalid: less than the initioal price" }, new BidModel() { BidPrice = null, Comment = "Invalid: null price" }, new BidModel() { BidPrice = 300, Comment = "Valid" }, new BidModel() { BidPrice = 280, Comment = "Invalid: less than the max price" }, }; var httpResultBid0 = TestingEngine.CreateBidHttpPost(userSession.Access_Token, offer.Id, bids[0].BidPrice, bids[0].Comment); var httpResultBid1 = TestingEngine.CreateBidHttpPost(userSession.Access_Token, offer.Id, bids[1].BidPrice, bids[1].Comment); var httpResultBid2 = TestingEngine.CreateBidHttpPost(userSession.Access_Token, offer.Id, bids[2].BidPrice, bids[2].Comment); var httpResultBid3 = TestingEngine.CreateBidHttpPost(userSession.Access_Token, offer.Id, bids[3].BidPrice, bids[3].Comment); // Assert -> valid bids are created, invalid not created Assert.AreEqual(HttpStatusCode.BadRequest, httpResultBid0.StatusCode); Assert.AreEqual(HttpStatusCode.BadRequest, httpResultBid1.StatusCode); Assert.AreEqual(HttpStatusCode.OK, httpResultBid2.StatusCode); Assert.AreEqual(HttpStatusCode.BadRequest, httpResultBid3.StatusCode); var bidsCount = TestingEngine.GetBidsCountFromDb(); Assert.AreEqual(1, bidsCount); }
public void GetOffer_WithValidId_ShouldReturn200OKAndDataCorectly() { //Arrange TestingEngine.CleanDatabase(); var userSession = TestingEngine.RegisterUser("peter", "pAssW@rd#123456"); var offerModel = new OfferModel() { Title = "Title", Description = "Description", InitialPrice = 200, ExpirationDateTime = DateTime.Now.AddDays(5) }; var httpResultOffer = TestingEngine.CreateOfferHttpPost(userSession.Access_Token, offerModel.Title, offerModel.Description, offerModel.InitialPrice, offerModel.ExpirationDateTime); // Act var db = new BidSystemDbContext(); var offerFromDb = db.Offers.FirstOrDefault(); var bids = new BidModel[] { new BidModel() { BidPrice = 250, Comment = "Invalid: less than the initioal price" }, }; var httpResultBid0 = TestingEngine.CreateBidHttpPost(userSession.Access_Token, offerFromDb.Id, bids[0].BidPrice, bids[0].Comment); db.SaveChanges(); var offerDetailsResponse = TestingEngine.HttpClient.GetAsync("/api/offers/details/" + offerFromDb.Id).Result; var offerResponseContent = httpResultOffer.Content.ReadAsAsync<OfferDetailsViewModel>().Result; // Assert Assert.AreEqual(HttpStatusCode.OK, offerDetailsResponse.StatusCode); }