public void ViewEditForm_NonExistingItem_Returns404NotFound()
        {
            // Arrange
            var fruitRepositoryMock = new Mock <IFruitRepository>();
            var controller          = new FruitsController(fruitRepositoryMock.Object);

            // Act
            var result = controller.Edit(1).Result;

            // Assert
            Assert.IsType <NotFoundResult>(result);
        }
        public void ViewEditForm_ExistingItem_ReturnsView()
        {
            // Arrange
            var fruitRepositoryMock = new Mock <IFruitRepository>();
            var controller          = new FruitsController(fruitRepositoryMock.Object);

            fruitRepositoryMock.Setup(x => x.GetById(1)).ReturnsAsync(new Fruit {
                Id = 1, Color = Color.Red, Name = "Apple", Price = 2.99m, Rating = 5, Description = "An apple", Image = "apple.jpeg"
            });

            // Act
            var result = controller.Edit(1).Result;

            // Assert
            Assert.IsType <ViewResult>(result);
        }
        public void SubmitEdit_IncorrectInput_ReturnsViewAgain()
        {
            // Arrange
            var fruitRepositoryMock = new Mock <IFruitRepository>();
            var controller          = new FruitsController(fruitRepositoryMock.Object);

            var originalItem = new Fruit
            {
                Id          = 1,
                Color       = Color.Red,
                Name        = "Apple",
                Price       = 2.99m,
                Rating      = 5,
                Description = "An apple",
                Image       = "apple.jpeg"
            };

            fruitRepositoryMock.Setup(x => x.GetById(1)).ReturnsAsync(originalItem);

            var updatedItem = new Fruit
            {
                Id          = 1,
                Color       = Color.Red,
                Name        = null, // Missing name!
                Price       = 2.99m,
                Rating      = 5,
                Description = "An apple",
                Image       = "apple.jpeg"
            };

            // Act
            var result = controller.Edit(1, updatedItem).Result;

            // Assert
            Assert.IsType <ViewResult>(result);
        }