//[Authorize] public IHttpActionResult PostUserPurchasedItem(UserPurchasedItem UserPurchasedItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Post(UserPurchasedItem); return(CreatedAtRoute("DefaultApi", new { id = UserPurchasedItem.UserPurchasedItemID }, UserPurchasedItem)); }
public void GetUserPurchasedItem_WithNonExistentId_ReturnsNull() { // Arrange UserPurchasedItem purchasedItems = DummyUserPurchasedItem(DummyBrewery(), DummyUser()); _context.UserPurchasedItems.Add(purchasedItems); _context.SaveChanges(); // Act var result = _userPurchasedItemRepository.Get(5); // Assert Assert.IsNull(result); }
public void DeleteUserPurchasedItem_WithNonExistantId_ReturnsFalse() { // Arrange UserPurchasedItem purchasedItems = DummyUserPurchasedItem(DummyBrewery(), DummyUser()); _context.UserPurchasedItems.Add(purchasedItems); _context.SaveChanges(); // Act bool deleteStatus = _userPurchasedItemRepository.Delete(5); // Assert Assert.IsFalse(deleteStatus); }
public void GetUserPurchasedItem_WithNoId_ReturnsQueryable() { // Arrange UserPurchasedItem purchasedItems = DummyUserPurchasedItem(DummyBrewery(), DummyUser()); _context.UserPurchasedItems.Add(purchasedItems); _context.SaveChanges(); // Act IQueryable <UserPurchasedItem> retrievedUserPurchasedItems = _userPurchasedItemRepository.Get(); // Assert Assert.AreEqual(retrievedUserPurchasedItems.Count(), 1); }
//[Authorize] public IHttpActionResult PutUserPurchasedItem(int id, UserPurchasedItem UserPurchasedItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = _context.Put(id, UserPurchasedItem); if (result == false) { return(NotFound()); } return(StatusCode(HttpStatusCode.NoContent)); }
public void PostUserPurchasedItem_ReturnsUserPurchasedItemListCount() { // Arrange UserPurchasedItem purchasedItems = DummyUserPurchasedItem(DummyBrewery(), DummyUser()); var pre = _context.UserPurchasedItems.Any(); // Act _userPurchasedItemRepository.Post(purchasedItems); // Assert var post = _context.UserPurchasedItems.Any(); Assert.IsFalse(pre); Assert.IsTrue(post); }
public void DeleteUserPurchasedItem_WithExistantId_ReturnsTrue() { // Arrange UserPurchasedItem purchasedItems = DummyUserPurchasedItem(DummyBrewery(), DummyUser()); _context.UserPurchasedItems.Add(purchasedItems); _context.SaveChanges(); int id = _context.UserPurchasedItems.ToList().FirstOrDefault().UserPurchasedItemID; // Act bool deleteStatus = _userPurchasedItemRepository.Delete(id); // Assert Assert.IsTrue(deleteStatus); }
public void GetUserPurchasedItem_WithExistingId_ReturnsUserPurchasedItem() { // Arrange UserPurchasedItem purchasedItems = DummyUserPurchasedItem(DummyBrewery(), DummyUser()); _context.UserPurchasedItems.Add(purchasedItems); _context.SaveChanges(); int id = _context.UserPurchasedItems.ToList().FirstOrDefault().UserPurchasedItemID; bool hasPurchasedShirt = purchasedItems.PurchasedTShirt; // Act UserPurchasedItem result = _userPurchasedItemRepository.Get(id); // Assert Assert.AreEqual(hasPurchasedShirt, result.PurchasedTShirt); }
public void PutUserPurchasedItem_WithNonExistantId_ReturnsFalse() { // Arrange UserPurchasedItem purchasedItems = DummyUserPurchasedItem(DummyBrewery(), DummyUser()); _context.UserPurchasedItems.Add(purchasedItems); _context.SaveChanges(); // Act UserPurchasedItem newPurchasedItem = _context.UserPurchasedItems.ToList().FirstOrDefault(); newPurchasedItem.PurchasedMug = true; bool result = _userPurchasedItemRepository.Put(5, newPurchasedItem); // Assert Assert.IsFalse(result); }