public async Task UpdateCartItem_WhenValidCartItemIsPassed_ReturnsOkResult()
        {
            //Arrange
            var moq = new Mock <IBookAsCartItemService>();

            Category category = new Category()
            {
                CategoryId   = 1,
                CategoryName = "Novel"
            };

            //create a new book
            Book book = new Book()
            {
                Id = 1,

                Title = "Jerry's Success Story",

                Author = "James x",

                CategoryId = 1,

                Category = category,

                ISBN = 1234567890,

                Price = 15,

                DateOfPublication = "2018-06-03"
            };

            BookAsCartItemDTO cartItem = new BookAsCartItemDTO()
            {
                Id = 1,

                Book = book,

                Price = 15,

                Quantity = 4
            };

            moq.Setup(r => r.EditCartItem(cartItem));

            //Act
            var controller = new BookAsCartItemController(moq.Object);

            var ok_Result = await controller.UpdateCartItem(cartItem);

            //Assert
            Assert.IsType <OkObjectResult>(ok_Result);
        }
        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 DeleteCartItem_WhenValidIdIsPassed_ReturnsOkResult()
        {
            //Arrange
            var moq = new Mock <IBookAsCartItemService>();

            moq.Setup(r => r.RemoveCartItem(1));

            //Act
            var controller = new BookAsCartItemController(moq.Object);

            var result = await controller.DeleteCartItem(1);

            //Assert
            Assert.IsType <OkResult>(result);
        }
        public async Task UpdateCartItem_WhenNullIsPassed_ReturnsNotFound()
        {
            //Arrange
            var moq = new Mock <IBookAsCartItemService>();

            moq.Setup(t => t.EditCartItem(null));

            //Act
            var controller = new BookAsCartItemController(moq.Object);

            var result = await controller.UpdateCartItem(null);

            //Assert
            Assert.IsType <NotFoundResult>(result);
        }
        public void GetCartItemById_WhenValidIdPassed_ReturnsCorrectCartItem()
        {
            //Arrange
            var moq = new Mock <IBookAsCartItemService>();

            moq.Setup(i => i.GetOneCartItem(1)).Returns(DummyCartItem().FirstOrDefault(x => x.Id == 1));

            //Act
            var controller = new BookAsCartItemController(moq.Object);

            var cart_Item = controller.GetCartItemById(1).Result as OkObjectResult;

            //Assert
            Assert.Equal(4, (cart_Item.Value as BookAsCartItemDTO).Quantity);
        }
        public void GetCartItemById_WhenValidIdIsPassed_ReturnsOkResult()
        {
            //Arrange
            var moq = new Mock <IBookAsCartItemService>();

            moq.Setup(x => x.GetOneCartItem(2)).Returns(DummyCartItem().FirstOrDefault(i => i.Id == 2));

            //Act
            var controller = new BookAsCartItemController(moq.Object);

            var myResult = controller.GetCartItemById(2);//Id 2 is a valid id

            //Assert
            Assert.IsType <OkObjectResult>(myResult.Result);
        }
        public async Task GetListContainingAllCartItems_WhenCalledReturnsAllCartItems()
        {
            //Arrange
            var moq = new Mock <IBookAsCartItemService>();

            moq.Setup(i => i.GetAllCartItems()).ReturnsAsync(DummyCartItem());

            //Act
            var controller = new BookAsCartItemController(moq.Object);

            var all = await controller.GetListContainingAllCartItems();

            //Assert
            Assert.NotNull(all);
        }