public void RegisterUser_InvalidUserData_ShouldReturn400_BadRequest() { // Arrange TestingEngine.CleanDatabase(); // Act -> empty username var responseEmptyUsername = TestingEngine.RegisterUserHttpPost("", "#paSSw@rd12345"); // Assert -> 400 (Bad Request) Assert.AreEqual(HttpStatusCode.BadRequest, responseEmptyUsername.StatusCode); // Act -> empty password var responseEmptyPassword = TestingEngine.RegisterUserHttpPost("maria", ""); // Assert -> 400 (Bad Request) Assert.AreEqual(HttpStatusCode.BadRequest, responseEmptyPassword.StatusCode); // Act -> null username var responseNullUsername = TestingEngine.RegisterUserHttpPost(null, "#paSSw@rd12345"); // Assert -> 400 (Bad Request) Assert.AreEqual(HttpStatusCode.BadRequest, responseNullUsername.StatusCode); // Act -> null password var responseNullPassword = TestingEngine.RegisterUserHttpPost("maria", null); // Assert -> 400 (Bad Request) Assert.AreEqual(HttpStatusCode.BadRequest, responseNullPassword.StatusCode); // Act -> no data (empty HTTP body) var httpResponse = TestingEngine.HttpClient.PostAsync("/api/user/register", null).Result; // Assert -> 400 (Bad Request) Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode); }
public void CreateOffer_ShouldReturnCreatedOfferCorrectly() { // Arrange -> clean the database and register new user TestingEngine.CleanDatabase(); var userSession = TestingEngine.RegisterUser("peter", "pAssW@rd#123456"); // Act -> create a few offers var offersToAdds = new OfferModel[] { new OfferModel() { Title = "First Offer (Expired)", Description = "Description", InitialPrice = 200, ExpirationDateTime = DateTime.Now.AddDays(-5) }, new OfferModel() { Title = "Third Offer (Active 6 months)", InitialPrice = 120, ExpirationDateTime = DateTime.Now.AddMonths(6) }, }; foreach (var offer in offersToAdds) { var httpResult = TestingEngine.CreateOfferHttpPost(userSession.Access_Token, offer.Title, offer.Description, offer.InitialPrice, offer.ExpirationDateTime); Assert.AreEqual(HttpStatusCode.Created, httpResult.StatusCode); } }
public void CreateOffers_InvalidOffers_ShouldReturnBadRequest() { // Arrange -> clean the database TestingEngine.CleanDatabase(); var userSession = TestingEngine.RegisterUser("peter", "pAssW@rd#123456"); // Act -> try to create a few offers var offersToAdds = new OfferModel[] { new OfferModel() { Description = "Description", InitialPrice = 200, ExpirationDateTime = DateTime.Now.AddDays(-5) }, new OfferModel() { Title = "Another Offer (Expired)", ExpirationDateTime = DateTime.Now.AddDays(-1) }, new OfferModel() { Title = "Second Offer (Active 3 months)", Description = "Description", InitialPrice = 500 }, }; foreach (var offer in offersToAdds) { var httpResult = TestingEngine.CreateOfferHttpPost(userSession.Access_Token, offer.Title, offer.Description, offer.InitialPrice, offer.ExpirationDateTime); Assert.AreEqual(HttpStatusCode.BadRequest, httpResult.StatusCode); } // Assert -> offers not created var offersCount = TestingEngine.GetOffersCountFromDb(); Assert.AreEqual(0, offersCount); }
public void GetOfferDetails_Of_NonExisting_Offer_Should_Return_404NotFound() { // Arrange -> clean the database and register new user TestingEngine.CleanDatabase(); var getOfferDetailsHttpResult = TestingEngine.GetOfferDetailsHttpGet(int.MaxValue); Assert.AreEqual(HttpStatusCode.NotFound, getOfferDetailsHttpResult.StatusCode); }
public void GetDetailsNonExistingOffer_ShouldReturn404NotFound() { // Arrange -> clean the DB TestingEngine.CleanDatabase(); // Act -> delete the channel var httpDeleteResponse = TestingEngine.HttpClient.GetAsync("/api/offers/details/1").Result; // Assert -> HTTP status code is 404 (Not Found) Assert.AreEqual(HttpStatusCode.NotFound, httpDeleteResponse.StatusCode); }
public void RegisterUser_DuplicatedUsername_ShouldReturn400_BadRequest() { // Arrange TestingEngine.CleanDatabase(); // Act var responseFirstRegistration = TestingEngine.RegisterUserHttpPost("maria", "#paSSw@rd12345"); var responseSecondRegistration = TestingEngine.RegisterUserHttpPost("maria", "0th3RPassw@rd"); // Assert Assert.AreEqual(HttpStatusCode.OK, responseFirstRegistration.StatusCode); Assert.AreEqual(HttpStatusCode.BadRequest, responseSecondRegistration.StatusCode); }
public void LoginUser_InvalidUser_ShouldReturn400_BadRequest() { // Arrange TestingEngine.CleanDatabase(); var username = "******"; var password = "******"; // Act var loginResponse = TestingEngine.LoginUserHttpPost(username, password); // Assert Assert.AreEqual(HttpStatusCode.BadRequest, loginResponse.StatusCode); }
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 CreateBid_InvalidOffer_ShouldReturnNotFound() { // Arrange -> clean database, register new user TestingEngine.CleanDatabase(); var userSession = TestingEngine.RegisterUser("peter", "pAssW@rd#123456"); // Act -> try to create a bid var invalidOfferId = -999; var httpResultBid = TestingEngine.CreateBidHttpPost(userSession.Access_Token, invalidOfferId, 1000, "Some comment"); // Assert -> bid not created Assert.AreEqual(HttpStatusCode.NotFound, httpResultBid.StatusCode); var bidsCount = TestingEngine.GetBidsCountFromDb(); Assert.AreEqual(0, bidsCount); }
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 LoginUser_ValidUser_ShouldReturn200Ok_AccessToken() { // Arrange TestingEngine.CleanDatabase(); var username = "******"; var password = "******"; // Act var userSessionRegister = TestingEngine.RegisterUser(username, password); var userSessionLogin = TestingEngine.LoginUser(username, password); // Assert Assert.AreEqual(username, userSessionRegister.UserName); Assert.AreEqual(username, userSessionLogin.UserName); Assert.AreEqual(userSessionLogin.UserName, userSessionRegister.UserName); Assert.AreNotEqual(userSessionLogin.Access_Token, userSessionRegister.Access_Token); }
public void GetOfferDetails_Of_Existing_Offer_Should_Return_200Ok_And_Offer_Details() { // Arrange -> clean the database and register new user TestingEngine.CleanDatabase(); var userSession = TestingEngine.RegisterUser("peter", "pAssW@rd#123456"); // Act -> create a few offers var offersToAdds = new OfferModel[] { new OfferModel() { Title = "First Offer (Expired)", Description = "Description", InitialPrice = 200, ExpirationDateTime = DateTime.Now.AddDays(-5) }, new OfferModel() { Title = "Another Offer (Expired)", InitialPrice = 15.50m, ExpirationDateTime = DateTime.Now.AddDays(-1) }, new OfferModel() { Title = "Second Offer (Active 3 months)", Description = "Description", InitialPrice = 500, ExpirationDateTime = DateTime.Now.AddMonths(3) }, new OfferModel() { Title = "Third Offer (Active 6 months)", InitialPrice = 120, ExpirationDateTime = DateTime.Now.AddMonths(6) }, }; foreach (var offer in offersToAdds) { var httpResult = TestingEngine.CreateOfferHttpPost(userSession.Access_Token, offer.Title, offer.Description, offer.InitialPrice, offer.ExpirationDateTime); } var firstOfferId = TestingEngine.GetRandomOfferIdFromDb(); var getOfferDetailsHttpResult = TestingEngine.GetOfferDetailsHttpGet(firstOfferId); Assert.AreEqual(HttpStatusCode.OK, getOfferDetailsHttpResult.StatusCode); var offerDetails = getOfferDetailsHttpResult.Content.ReadAsAsync <GetOfferByDetailsViewModel>().Result; Assert.AreEqual(offersToAdds[0].Title, offerDetails.Title); Assert.AreEqual(offersToAdds[0].Description, offerDetails.Description); Assert.AreEqual(offersToAdds[0].InitialPrice, offerDetails.InitialPrice); //Assert.AreEqual(offersToAdds[0].ExpirationDateTime.ToString(), offerDetails.ExpirationDateTime.ToString(CultureInfo.InvariantCulture)); Assert.AreEqual(0, offerDetails.BidsCount); Assert.IsTrue(offerDetails.IsExpired); }
public void CreateOffer_Unauthorized_ShouldReturnUnauthorized() { // Arrange -> clean the database TestingEngine.CleanDatabase(); // Act -> try to create an offer var offer = new OfferModel() { Title = "Title", Description = "Description", InitialPrice = 200, ExpirationDateTime = DateTime.Now.AddDays(5) }; var httpResult = TestingEngine.CreateOfferHttpPost(null, offer.Title, offer.Description, offer.InitialPrice, offer.ExpirationDateTime); // Assert -> offer not created Assert.AreEqual(HttpStatusCode.Unauthorized, httpResult.StatusCode); var offersCount = TestingEngine.GetOffersCountFromDb(); Assert.AreEqual(0, offersCount); }
public void RegisterUser_EmptyDb_ShouldReturn200Ok_AccessToken() { // Arrange TestingEngine.CleanDatabase(); var username = "******"; // Act var postContent = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("username", username), new KeyValuePair <string, string>("password", "pAssW@rd#123456") }); var httpResponse = TestingEngine.HttpClient.PostAsync("/api/user/register", postContent).Result; Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode); var userSession = httpResponse.Content.ReadAsAsync <UserSessionModel>().Result; // Assert Assert.AreEqual(userSession.UserName, username); Assert.IsNotNull(userSession.Access_Token); }
public void CreateBid_Unauthorized_ShouldReturnUnauthorized() { // 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 bid var httpResultBid = TestingEngine.CreateBidHttpPost(null, offer.Id, 1000, "Some comment"); // Assert -> bid not created Assert.AreEqual(HttpStatusCode.Unauthorized, httpResultBid.StatusCode); var bidsCount = TestingEngine.GetBidsCountFromDb(); Assert.AreEqual(0, bidsCount); }