public void Can_Edit_Dish()
        {
            // Arrange - create the mock repository
            Mock <IDishService> mock = new Mock <IDishService>();

            mock.Setup(m => m.Dish).Returns(new Dish[] {
                new Dish {
                    Id = 1, Name = "P1"
                },
                new Dish {
                    Id = 2, Name = "P2"
                },
                new Dish {
                    Id = 3, Name = "P3"
                },
            }.AsQueryable <Dish>());

            // Arrange - create a controller
            DishesController target = new DishesController(mock.Object);

            // Act
            Dish p1 = GetViewModel <Dish>(target.Edit(1));
            Dish p2 = GetViewModel <Dish>(target.Edit(2));
            Dish p3 = GetViewModel <Dish>(target.Edit(3));

            // Assert
            Assert.Equal(1, p1.Id);
            Assert.Equal(2, p2.Id);
            Assert.Equal(3, p3.Id);
        }
        public void ActionResult_Is_Of_Type_ViewResult()
        {
            // Arrange - create mock repository
            Mock <IDishService> mock = new Mock <IDishService>();

            mock.Setup(m => m.Dish).Returns(new Dish[] {
                new Dish {
                    Id = 1, Name = "P1"
                },
                new Dish {
                    Id = 2, Name = "P2"
                },
                new Dish {
                    Id = 3, Name = "P3"
                },
            }.AsQueryable <Dish>());

            // Arrange - create the controller
            DishesController target = new DishesController(mock.Object);


            // Act - try to save the Dish
            IActionResult result = target.Edit(3);

            // Assert - check that the repository was called
            // Assert - check the result type is a ViewResult
            Assert.IsType <ViewResult>(result);
        }
Example #3
0
        public void Edit_ReturnsViewResult_True()
        {
            Dish             dish       = new Dish("spaghetti and meatballs");
            DishesController controller = new DishesController();
            ViewResult       editView   = controller.Edit(dish.GetId()) as ViewResult;

            Assert.IsInstanceOfType(editView, typeof(ViewResult));
        }
Example #4
0
        public void Edit_HasCorrectModelType_Dish()
        {
            Dish             dish       = new Dish("spaghetti and meatballs");
            DishesController controller = new DishesController();
            ViewResult       editView   = controller.Edit(dish.GetId()) as ViewResult;
            var result = editView.ViewData.Model;

            Assert.IsInstanceOfType(result, typeof(Dish));
        }
Example #5
0
        public void EditDish_Success_Result()
        {
            var getDishesRequestModel = new Edit.Command();

            Mediator.Setup(x => x.Send(It.IsAny <Edit.Command>(), new CancellationToken())).
            ReturnsAsync(ResponseWrapper <Edit> .GetInstance((int)HttpStatusCode.OK, null, true, null));

            DishesController.SetMediatrForTest(Mediator.Object);

            //Action
            var result = DishesController.Edit(new ObjectId().ToString(), getDishesRequestModel);

            //Assert
            Assert.IsType <Task <ActionResult <ResponseWrapper <Edit> > > >(result);
        }
        public void Get_KeyNotFound_Exception()
        {
            // Arrange - create mock repository
            Mock <IDishService> mock = new Mock <IDishService>();

            mock.Setup(m => m.Dish).Returns(new Dish[] {
                new Dish {
                    Id = 1, Name = "P1"
                },
                new Dish {
                    Id = 2, Name = "P2"
                },
                new Dish {
                    Id = 3, Name = "P3"
                },
            }.AsQueryable <Dish>());

            // Arrange - create the controller
            DishesController target = new DishesController(mock.Object);

            Assert.Throws <KeyNotFoundException>(() => target.Edit(null));
        }
        public void Throws_Exception_When_Id_Is_Null()
        {
            // Arrange - create the mock repository
            Mock <IDishService> mock = new Mock <IDishService>();

            mock.Setup(m => m.Dish).Returns(new Dish[] {
                new Dish {
                    Id = 1, Name = "P1"
                },
                new Dish {
                    Id = 2, Name = "P2"
                },
                new Dish {
                    Id = 3, Name = "P3"
                },
            }.AsQueryable <Dish>());

            // Arrange - create the controller
            DishesController target = new DishesController(mock.Object);

            // Assert
            Assert.Throws <NullReferenceException>(() => GetViewModel <Dish>(target.Edit(4)));
        }