public async Task PostACartItem_WhenValidObjectIsPassed_ReturnsOkResult() { //Arrange var moq = new Mock <IBookAsCartItemService>(); Category category = new Category() { CategoryId = 1, CategoryName = "Novel" }; //create a new book Book book = new Book() { Id = 3, Title = "Jerry's Travel Story", Author = "Maria x", CategoryId = 1, Category = category, ISBN = 1486910263, Price = 34, DateOfPublication = "2016-10-27" }; BookAsCartItemDTO cartItem = new BookAsCartItemDTO() { Id = 2, Book = book, Price = 34, Quantity = 1 }; moq.Setup(i => i.CreateCartItem(cartItem)); //Act var controller = new BookAsCartItemController(moq.Object); var response = await controller.PostACartItem(cartItem); //Assert Assert.IsType <OkObjectResult>(response); }
public async Task PostACartItem_WhenNullIsPassed_ReturnsNotFound() { //Arrange var moq = new Mock <IBookAsCartItemService>(); moq.Setup(i => i.CreateCartItem(null)); //Act var controller = new BookAsCartItemController(moq.Object); var result = await controller.PostACartItem(null); //Assert Assert.IsType <NotFoundResult>(result); }